Skip to content

Commit 7ff11bb

Browse files
committed
Merge branch 'master' into module-nodejs
2 parents 3b33df0 + a79610a commit 7ff11bb

File tree

311 files changed

+5579
-3717
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

311 files changed

+5579
-3717
lines changed

Gulpfile.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
4646
boolean: ["debug", "inspect", "light", "colors", "lint", "soft"],
4747
string: ["browser", "tests", "host", "reporter", "stackTraceLimit", "timeout"],
4848
alias: {
49-
b: "browser",
50-
d: "debug", "debug-brk": "debug",
51-
i: "inspect", "inspect-brk": "inspect",
52-
t: "tests", test: "tests",
53-
ru: "runners", runner: "runners",
54-
r: "reporter",
55-
c: "colors", color: "colors",
56-
f: "files", file: "files",
57-
w: "workers",
49+
"b": "browser",
50+
"d": "debug", "debug-brk": "debug",
51+
"i": "inspect", "inspect-brk": "inspect",
52+
"t": "tests", "test": "tests",
53+
"ru": "runners", "runner": "runners",
54+
"r": "reporter",
55+
"c": "colors", "color": "colors",
56+
"f": "files", "file": "files",
57+
"w": "workers",
5858
},
5959
default: {
6060
soft: false,
@@ -74,7 +74,8 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
7474
}
7575
});
7676

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

10361037
gulp.task("build-rules", "Compiles tslint rules to js", () => {
1037-
const settings: tsc.Settings = getCompilerSettings({ module: "commonjs", "lib": ["es6"] }, /*useBuiltCompiler*/ false);
1038+
const settings: tsc.Settings = getCompilerSettings({ module: "commonjs", lib: ["es6"] }, /*useBuiltCompiler*/ false);
10381039
const dest = path.join(builtLocalDirectory, "tslint");
10391040
return gulp.src("scripts/tslint/**/*.ts")
10401041
.pipe(newer({

Jakefile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ var harnessCoreSources = [
105105
"projectsRunner.ts",
106106
"loggedIO.ts",
107107
"rwcRunner.ts",
108-
"userRunner.ts",
108+
"externalCompileRunner.ts",
109109
"test262Runner.ts",
110110
"./parallel/shared.ts",
111111
"./parallel/host.ts",

scripts/processDiagnosticMessages.ts

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/// <reference path="../src/compiler/sys.ts" />
2+
/// <reference path="../src/compiler/core.ts" />
23

34
interface DiagnosticDetails {
45
category: string;
@@ -9,57 +10,55 @@ interface DiagnosticDetails {
910
type InputDiagnosticMessageTable = ts.Map<DiagnosticDetails>;
1011

1112
function main(): void {
12-
var sys = ts.sys;
13+
const sys = ts.sys;
1314
if (sys.args.length < 1) {
14-
sys.write("Usage:" + sys.newLine)
15+
sys.write("Usage:" + sys.newLine);
1516
sys.write("\tnode processDiagnosticMessages.js <diagnostic-json-input-file>" + sys.newLine);
1617
return;
1718
}
1819

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

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

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

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

40-
var infoFileOutput = buildInfoFileOutput(diagnosticMessages);
33+
const outputFilesDir = ts.getDirectoryPath(inputFilePath);
34+
const thisFilePathRel = ts.getRelativePathToDirectoryOrUrl(outputFilesDir, sys.getExecutingFilePath(),
35+
sys.getCurrentDirectory(), ts.createGetCanonicalFileName(sys.useCaseSensitiveFileNames), /* isAbsolutePathAnUrl */ false);
36+
37+
const infoFileOutput = buildInfoFileOutput(diagnosticMessages, "./diagnosticInformationMap.generated.ts", thisFilePathRel);
4138
checkForUniqueCodes(diagnosticMessages);
4239
writeFile("diagnosticInformationMap.generated.ts", infoFileOutput);
4340

44-
var messageOutput = buildDiagnosticMessageOutput(diagnosticMessages);
41+
const messageOutput = buildDiagnosticMessageOutput(diagnosticMessages);
4542
writeFile("diagnosticMessages.generated.json", messageOutput);
4643
}
4744

4845
function checkForUniqueCodes(diagnosticTable: InputDiagnosticMessageTable) {
4946
const allCodes: { [key: number]: true | undefined } = [];
5047
diagnosticTable.forEach(({ code }) => {
51-
if (allCodes[code])
48+
if (allCodes[code]) {
5249
throw new Error(`Diagnostic code ${code} appears more than once.`);
50+
}
5351
allCodes[code] = true;
5452
});
5553
}
5654

57-
function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable): string {
58-
var result =
59-
'// <auto-generated />\r\n' +
60-
'/// <reference path="types.ts" />\r\n' +
61-
'/* @internal */\r\n' +
62-
'namespace ts {\r\n' +
55+
function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, inputFilePathRel: string, thisFilePathRel: string): string {
56+
let result =
57+
"// <auto-generated />\r\n" +
58+
"// generated from '" + inputFilePathRel + "' by '" + thisFilePathRel + "'\r\n" +
59+
"/// <reference path=\"types.ts\" />\r\n" +
60+
"/* @internal */\r\n" +
61+
"namespace ts {\r\n" +
6362
" function diag(code: number, category: DiagnosticCategory, key: string, message: string): DiagnosticMessage {\r\n" +
6463
" return { code, category, key, message };\r\n" +
6564
" }\r\n" +
@@ -70,44 +69,44 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable): string
7069
result += ` ${propName}: diag(${code}, DiagnosticCategory.${category}, "${createKey(propName, code)}", ${JSON.stringify(name)}),\r\n`;
7170
});
7271

73-
result += ' };\r\n}';
72+
result += " };\r\n}";
7473

7574
return result;
7675
}
7776

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

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

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

9190
return result;
9291
}
9392

94-
function createKey(name: string, code: number) : string {
95-
return name.slice(0, 100) + '_' + code;
93+
function createKey(name: string, code: number): string {
94+
return name.slice(0, 100) + "_" + code;
9695
}
9796

9897
function convertPropertyName(origName: string): string {
99-
var result = origName.split("").map(char => {
100-
if (char === '*') { return "_Asterisk"; }
101-
if (char === '/') { return "_Slash"; }
102-
if (char === ':') { return "_Colon"; }
98+
let result = origName.split("").map(char => {
99+
if (char === "*") { return "_Asterisk"; }
100+
if (char === "/") { return "_Slash"; }
101+
if (char === ":") { return "_Colon"; }
103102
return /\w/.test(char) ? char : "_";
104103
}).join("");
105104

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

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

112111
// get rid of all trailing underscores.
113112
result = result.replace(/_$/, "");

src/compiler/binder.ts

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ namespace ts {
15701570
else {
15711571
let pattern: Pattern | undefined;
15721572
if (node.name.kind === SyntaxKind.StringLiteral) {
1573-
const text = (<StringLiteral>node.name).text;
1573+
const { text } = node.name;
15741574
if (hasZeroOrOneAsteriskCharacter(text)) {
15751575
pattern = tryParsePattern(text);
15761576
}
@@ -1589,22 +1589,13 @@ namespace ts {
15891589
else {
15901590
const state = declareModuleSymbol(node);
15911591
if (state !== ModuleInstanceState.NonInstantiated) {
1592-
if (node.symbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.RegularEnum)) {
1593-
// if module was already merged with some function, class or non-const enum
1594-
// treat is a non-const-enum-only
1595-
node.symbol.constEnumOnlyModule = false;
1596-
}
1597-
else {
1598-
const currentModuleIsConstEnumOnly = state === ModuleInstanceState.ConstEnumOnly;
1599-
if (node.symbol.constEnumOnlyModule === undefined) {
1600-
// non-merged case - use the current state
1601-
node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly;
1602-
}
1603-
else {
1604-
// merged case: module is const enum only if all its pieces are non-instantiated or const enum
1605-
node.symbol.constEnumOnlyModule = node.symbol.constEnumOnlyModule && currentModuleIsConstEnumOnly;
1606-
}
1607-
}
1592+
const { symbol } = node;
1593+
// if module was already merged with some function, class or non-const enum, treat it as non-const-enum-only
1594+
symbol.constEnumOnlyModule = (!(symbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.RegularEnum)))
1595+
// Current must be `const enum` only
1596+
&& state === ModuleInstanceState.ConstEnumOnly
1597+
// Can't have been set to 'false' in a previous merged symbol. ('undefined' OK)
1598+
&& symbol.constEnumOnlyModule !== false;
16081599
}
16091600
}
16101601
}
@@ -2205,15 +2196,14 @@ namespace ts {
22052196
bindAnonymousDeclaration(node, SymbolFlags.Alias, getDeclarationName(node));
22062197
}
22072198
else {
2208-
// An export default clause with an expression exports a value
2209-
// We want to exclude both class and function here, this is necessary to issue an error when there are both
2210-
// default export-assignment and default export function and class declaration.
2211-
const flags = node.kind === SyntaxKind.ExportAssignment && exportAssignmentIsAlias(<ExportAssignment>node)
2199+
const flags = node.kind === SyntaxKind.ExportAssignment && exportAssignmentIsAlias(node)
22122200
// An export default clause with an EntityNameExpression exports all meanings of that identifier
22132201
? SymbolFlags.Alias
22142202
// An export default clause with any other expression exports a value
22152203
: SymbolFlags.Property;
2216-
declareSymbol(container.symbol.exports, container.symbol, node, flags, SymbolFlags.Property | SymbolFlags.AliasExcludes | SymbolFlags.Class | SymbolFlags.Function);
2204+
// If there is an `export default x;` alias declaration, can't `export default` anything else.
2205+
// (In contrast, you can still have `export default function f() {}` and `export default interface I {}`.)
2206+
declareSymbol(container.symbol.exports, container.symbol, node, flags, SymbolFlags.All);
22172207
}
22182208
}
22192209

0 commit comments

Comments
 (0)