Skip to content

Commit

Permalink
Merge branch 'master' into module-nodejs
Browse files Browse the repository at this point in the history
  • Loading branch information
weswigham committed Nov 10, 2017
2 parents 3b33df0 + a79610a commit 7ff11bb
Show file tree
Hide file tree
Showing 311 changed files with 5,579 additions and 3,717 deletions.
23 changes: 12 additions & 11 deletions Gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
boolean: ["debug", "inspect", "light", "colors", "lint", "soft"],
string: ["browser", "tests", "host", "reporter", "stackTraceLimit", "timeout"],
alias: {
b: "browser",
d: "debug", "debug-brk": "debug",
i: "inspect", "inspect-brk": "inspect",
t: "tests", test: "tests",
ru: "runners", runner: "runners",
r: "reporter",
c: "colors", color: "colors",
f: "files", file: "files",
w: "workers",
"b": "browser",
"d": "debug", "debug-brk": "debug",
"i": "inspect", "inspect-brk": "inspect",
"t": "tests", "test": "tests",
"ru": "runners", "runner": "runners",
"r": "reporter",
"c": "colors", "color": "colors",
"f": "files", "file": "files",
"w": "workers",
},
default: {
soft: false,
Expand All @@ -74,7 +74,8 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
}
});

function exec(cmd: string, args: string[], complete: () => void = (() => { }), error: (e: any, status: number) => void = (() => { })) {
const noop = () => {}; // tslint:disable-line no-empty
function exec(cmd: string, args: string[], complete: () => void = noop, error: (e: any, status: number) => void = noop) {
console.log(`${cmd} ${args.join(" ")}`);
// TODO (weswig): Update child_process types to add windowsVerbatimArguments to the type definition
const subshellFlag = isWin ? "/c" : "-c";
Expand Down Expand Up @@ -1034,7 +1035,7 @@ gulp.task("update-sublime", "Updates the sublime plugin's tsserver", ["local", s
});

gulp.task("build-rules", "Compiles tslint rules to js", () => {
const settings: tsc.Settings = getCompilerSettings({ module: "commonjs", "lib": ["es6"] }, /*useBuiltCompiler*/ false);
const settings: tsc.Settings = getCompilerSettings({ module: "commonjs", lib: ["es6"] }, /*useBuiltCompiler*/ false);
const dest = path.join(builtLocalDirectory, "tslint");
return gulp.src("scripts/tslint/**/*.ts")
.pipe(newer({
Expand Down
2 changes: 1 addition & 1 deletion Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ var harnessCoreSources = [
"projectsRunner.ts",
"loggedIO.ts",
"rwcRunner.ts",
"userRunner.ts",
"externalCompileRunner.ts",
"test262Runner.ts",
"./parallel/shared.ts",
"./parallel/host.ts",
Expand Down
67 changes: 33 additions & 34 deletions scripts/processDiagnosticMessages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// <reference path="../src/compiler/sys.ts" />
/// <reference path="../src/compiler/core.ts" />

interface DiagnosticDetails {
category: string;
Expand All @@ -9,57 +10,55 @@ interface DiagnosticDetails {
type InputDiagnosticMessageTable = ts.Map<DiagnosticDetails>;

function main(): void {
var sys = ts.sys;
const sys = ts.sys;
if (sys.args.length < 1) {
sys.write("Usage:" + sys.newLine)
sys.write("Usage:" + sys.newLine);
sys.write("\tnode processDiagnosticMessages.js <diagnostic-json-input-file>" + sys.newLine);
return;
}

function writeFile(fileName: string, contents: string) {
// TODO: Fix path joining
var inputDirectory = inputFilePath.substr(0,inputFilePath.lastIndexOf("/"));
var fileOutputPath = inputDirectory + "/" + fileName;
const inputDirectory = ts.getDirectoryPath(inputFilePath);
const fileOutputPath = ts.combinePaths(inputDirectory, fileName);
sys.writeFile(fileOutputPath, contents);
}

var inputFilePath = sys.args[0].replace(/\\/g, "/");
var inputStr = sys.readFile(inputFilePath);
const inputFilePath = sys.args[0].replace(/\\/g, "/");
const inputStr = sys.readFile(inputFilePath);

var diagnosticMessagesJson: { [key: string]: DiagnosticDetails } = JSON.parse(inputStr);
// Check that there are no duplicates.
const seenNames = ts.createMap<true>();
for (const name of Object.keys(diagnosticMessagesJson)) {
if (seenNames.has(name))
throw new Error(`Name ${name} appears twice`);
seenNames.set(name, true);
}
const diagnosticMessagesJson: { [key: string]: DiagnosticDetails } = JSON.parse(inputStr);

const diagnosticMessages: InputDiagnosticMessageTable = ts.createMapFromTemplate(diagnosticMessagesJson);

var infoFileOutput = buildInfoFileOutput(diagnosticMessages);
const outputFilesDir = ts.getDirectoryPath(inputFilePath);
const thisFilePathRel = ts.getRelativePathToDirectoryOrUrl(outputFilesDir, sys.getExecutingFilePath(),
sys.getCurrentDirectory(), ts.createGetCanonicalFileName(sys.useCaseSensitiveFileNames), /* isAbsolutePathAnUrl */ false);

const infoFileOutput = buildInfoFileOutput(diagnosticMessages, "./diagnosticInformationMap.generated.ts", thisFilePathRel);
checkForUniqueCodes(diagnosticMessages);
writeFile("diagnosticInformationMap.generated.ts", infoFileOutput);

var messageOutput = buildDiagnosticMessageOutput(diagnosticMessages);
const messageOutput = buildDiagnosticMessageOutput(diagnosticMessages);
writeFile("diagnosticMessages.generated.json", messageOutput);
}

function checkForUniqueCodes(diagnosticTable: InputDiagnosticMessageTable) {
const allCodes: { [key: number]: true | undefined } = [];
diagnosticTable.forEach(({ code }) => {
if (allCodes[code])
if (allCodes[code]) {
throw new Error(`Diagnostic code ${code} appears more than once.`);
}
allCodes[code] = true;
});
}

function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable): string {
var result =
'// <auto-generated />\r\n' +
'/// <reference path="types.ts" />\r\n' +
'/* @internal */\r\n' +
'namespace ts {\r\n' +
function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, inputFilePathRel: string, thisFilePathRel: string): string {
let result =
"// <auto-generated />\r\n" +
"// generated from '" + inputFilePathRel + "' by '" + thisFilePathRel + "'\r\n" +
"/// <reference path=\"types.ts\" />\r\n" +
"/* @internal */\r\n" +
"namespace ts {\r\n" +
" function diag(code: number, category: DiagnosticCategory, key: string, message: string): DiagnosticMessage {\r\n" +
" return { code, category, key, message };\r\n" +
" }\r\n" +
Expand All @@ -70,44 +69,44 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable): string
result += ` ${propName}: diag(${code}, DiagnosticCategory.${category}, "${createKey(propName, code)}", ${JSON.stringify(name)}),\r\n`;
});

result += ' };\r\n}';
result += " };\r\n}";

return result;
}

function buildDiagnosticMessageOutput(messageTable: InputDiagnosticMessageTable): string {
let result = '{';
let result = "{";
messageTable.forEach(({ code }, name) => {
const propName = convertPropertyName(name);
result += `\r\n "${createKey(propName, code)}" : "${name.replace(/[\"]/g, '\\"')}",`;
});

// Shave trailing comma, then add newline and ending brace
result = result.slice(0, result.length - 1) + '\r\n}';
result = result.slice(0, result.length - 1) + "\r\n}";

// Assert that we generated valid JSON
JSON.parse(result);

return result;
}

function createKey(name: string, code: number) : string {
return name.slice(0, 100) + '_' + code;
function createKey(name: string, code: number): string {
return name.slice(0, 100) + "_" + code;
}

function convertPropertyName(origName: string): string {
var result = origName.split("").map(char => {
if (char === '*') { return "_Asterisk"; }
if (char === '/') { return "_Slash"; }
if (char === ':') { return "_Colon"; }
let result = origName.split("").map(char => {
if (char === "*") { return "_Asterisk"; }
if (char === "/") { return "_Slash"; }
if (char === ":") { return "_Colon"; }
return /\w/.test(char) ? char : "_";
}).join("");

// get rid of all multi-underscores
result = result.replace(/_+/g, "_");

// remove any leading underscore, unless it is followed by a number.
result = result.replace(/^_([^\d])/, "$1")
result = result.replace(/^_([^\d])/, "$1");

// get rid of all trailing underscores.
result = result.replace(/_$/, "");
Expand Down
34 changes: 12 additions & 22 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,7 @@ namespace ts {
else {
let pattern: Pattern | undefined;
if (node.name.kind === SyntaxKind.StringLiteral) {
const text = (<StringLiteral>node.name).text;
const { text } = node.name;
if (hasZeroOrOneAsteriskCharacter(text)) {
pattern = tryParsePattern(text);
}
Expand All @@ -1589,22 +1589,13 @@ namespace ts {
else {
const state = declareModuleSymbol(node);
if (state !== ModuleInstanceState.NonInstantiated) {
if (node.symbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.RegularEnum)) {
// if module was already merged with some function, class or non-const enum
// treat is a non-const-enum-only
node.symbol.constEnumOnlyModule = false;
}
else {
const currentModuleIsConstEnumOnly = state === ModuleInstanceState.ConstEnumOnly;
if (node.symbol.constEnumOnlyModule === undefined) {
// non-merged case - use the current state
node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly;
}
else {
// merged case: module is const enum only if all its pieces are non-instantiated or const enum
node.symbol.constEnumOnlyModule = node.symbol.constEnumOnlyModule && currentModuleIsConstEnumOnly;
}
}
const { symbol } = node;
// if module was already merged with some function, class or non-const enum, treat it as non-const-enum-only
symbol.constEnumOnlyModule = (!(symbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.RegularEnum)))
// Current must be `const enum` only
&& state === ModuleInstanceState.ConstEnumOnly
// Can't have been set to 'false' in a previous merged symbol. ('undefined' OK)
&& symbol.constEnumOnlyModule !== false;
}
}
}
Expand Down Expand Up @@ -2205,15 +2196,14 @@ namespace ts {
bindAnonymousDeclaration(node, SymbolFlags.Alias, getDeclarationName(node));
}
else {
// An export default clause with an expression exports a value
// We want to exclude both class and function here, this is necessary to issue an error when there are both
// default export-assignment and default export function and class declaration.
const flags = node.kind === SyntaxKind.ExportAssignment && exportAssignmentIsAlias(<ExportAssignment>node)
const flags = node.kind === SyntaxKind.ExportAssignment && exportAssignmentIsAlias(node)
// An export default clause with an EntityNameExpression exports all meanings of that identifier
? SymbolFlags.Alias
// An export default clause with any other expression exports a value
: SymbolFlags.Property;
declareSymbol(container.symbol.exports, container.symbol, node, flags, SymbolFlags.Property | SymbolFlags.AliasExcludes | SymbolFlags.Class | SymbolFlags.Function);
// If there is an `export default x;` alias declaration, can't `export default` anything else.
// (In contrast, you can still have `export default function f() {}` and `export default interface I {}`.)
declareSymbol(container.symbol.exports, container.symbol, node, flags, SymbolFlags.All);
}
}

Expand Down
Loading

0 comments on commit 7ff11bb

Please sign in to comment.