From e7eef830e13509baa479eabe0e75aaa4992927c1 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 26 May 2015 20:18:13 -0700 Subject: [PATCH 01/26] Fix #3245: ensure transpile diagnostics only include syntactic and compiler options diagnostics --- Jakefile.js | 3 +- src/compiler/program.ts | 15 ++++---- src/compiler/types.ts | 1 + src/compiler/utilities.ts | 15 ++++++++ src/services/services.ts | 17 +++++++-- tests/cases/unittests/transpile.ts | 59 ++++++++++++++++++++++++++++++ 6 files changed, 98 insertions(+), 12 deletions(-) create mode 100644 tests/cases/unittests/transpile.ts diff --git a/Jakefile.js b/Jakefile.js index cb53b479502..f27e61062f0 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -128,7 +128,8 @@ var harnessSources = [ "services/preProcessFile.ts", "services/patternMatcher.ts", "versionCache.ts", - "convertToBase64.ts" + "convertToBase64.ts", + "transpile.ts" ].map(function (f) { return path.join(unittestsDirectory, f); })).concat([ diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 32503de2566..4cccc881d40 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -10,9 +10,6 @@ module ts { /** The version of the TypeScript compiler release */ export const version = "1.5.3"; - const carriageReturnLineFeed = "\r\n"; - const lineFeed = "\n"; - export function findConfigFile(searchPath: string): string { var fileName = "tsconfig.json"; while (true) { @@ -94,10 +91,7 @@ module ts { } } - let newLine = - options.newLine === NewLineKind.CarriageReturnLineFeed ? carriageReturnLineFeed : - options.newLine === NewLineKind.LineFeed ? lineFeed : - sys.newLine; + const newLine = getNewLineCharacter(options); return { getSourceFile, @@ -175,6 +169,7 @@ module ts { getGlobalDiagnostics, getSemanticDiagnostics, getDeclarationDiagnostics, + getCompilerOptionsDiagnostics, getTypeChecker, getDiagnosticsProducingTypeChecker, getCommonSourceDirectory: () => commonSourceDirectory, @@ -291,6 +286,12 @@ module ts { } } + function getCompilerOptionsDiagnostics(): Diagnostic[]{ + let allDiagnostics: Diagnostic[] = []; + addRange(allDiagnostics, diagnostics.getGlobalDiagnostics()); + return sortAndDeduplicateDiagnostics(allDiagnostics); + } + function getGlobalDiagnostics(): Diagnostic[] { let typeChecker = getDiagnosticsProducingTypeChecker(); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index a6fa89846bb..7eec44eb2f2 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1064,6 +1064,7 @@ module ts { getGlobalDiagnostics(): Diagnostic[]; getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + /* @internal */ getCompilerOptionsDiagnostics(): Diagnostic[]; /** * Gets a type checker that can be used to semantically analyze source fils in the program. diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 3ded0a7cfd9..3bb459ff99e 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1774,6 +1774,21 @@ module ts { return result; } + + const carriageReturnLineFeed = "\r\n"; + const lineFeed = "\n"; + export function getNewLineCharacter(options: CompilerOptions): string { + if (options.newLine === NewLineKind.CarriageReturnLineFeed) { + return carriageReturnLineFeed; + } + else if (options.newLine === NewLineKind.LineFeed) { + return lineFeed; + } + else if (sys) { + return sys.newLine + } + return carriageReturnLineFeed; + } } module ts { diff --git a/src/services/services.ts b/src/services/services.ts index d5ba024cee5..ff1e627a241 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1772,15 +1772,24 @@ module ts { // Filename can be non-ts file. options.allowNonTsExtensions = true; + // We are not returning a lib file when asked, so pass this flag to + // avoid reporting a file not found error + options.noLib = true; + + // Similar to the library, we are not returning any refrenced files + options.noResolve = true; + // Parse - var inputFileName = fileName || "module.ts"; - var sourceFile = createSourceFile(inputFileName, input, options.target); + let inputFileName = fileName || "module.ts"; + let sourceFile = createSourceFile(inputFileName, input, options.target); // Store syntactic diagnostics if (diagnostics && sourceFile.parseDiagnostics) { diagnostics.push(...sourceFile.parseDiagnostics); } + let newLine = getNewLineCharacter(options); + // Output let outputText: string; @@ -1795,13 +1804,13 @@ module ts { useCaseSensitiveFileNames: () => false, getCanonicalFileName: fileName => fileName, getCurrentDirectory: () => "", - getNewLine: () => (sys && sys.newLine) || "\r\n" + getNewLine: () => newLine }; var program = createProgram([inputFileName], options, compilerHost); if (diagnostics) { - diagnostics.push(...program.getGlobalDiagnostics()); + diagnostics.push(...program.getCompilerOptionsDiagnostics()); } // Emit diff --git a/tests/cases/unittests/transpile.ts b/tests/cases/unittests/transpile.ts new file mode 100644 index 00000000000..32caad8d05c --- /dev/null +++ b/tests/cases/unittests/transpile.ts @@ -0,0 +1,59 @@ +/// + +module ts { + describe("Transpile", () => { + + function runTest(input: string, compilerOptions: ts.CompilerOptions = {}, expectedOutput?: string, expectedDiagnosticCodes: number[] = []): void { + let diagnostics: Diagnostic[] = []; + let result = transpile(input, compilerOptions, "file.ts", diagnostics); + + assert.equal(diagnostics.length, expectedDiagnosticCodes.length); + for (let diagnostic of diagnostics) { + assert.isTrue(expectedDiagnosticCodes.indexOf(diagnostic.code) >= 0, `Found an unexpected diagnostic: ${ diagnostic.code }`); + } + + if (expectedOutput !== undefined) { + assert.equal(result, expectedOutput); + } + } + + it("Generates correct compilerOptions diagnostics", () => { + // Expecting 5047: "Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher." + runTest(`var x = 0;`, {}, /*expectedOutput*/ undefined, [5047]); + }); + + it("Generates no diagnostics with valid inputs", () => { + // No errors + runTest(`var x = 0;`, { module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, []); + }); + + it("Generates no diagnostics for missing file references", () => { + runTest(`/// +var x = 0;`, + { module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, []); + }); + + it("Generates no diagnostics for missing module imports", () => { + runTest(`import {a} from "module2";`, + { module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, []); + }); + + it("Generates expected syntactic diagnostics", () => { + runTest(`a b`, + { module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, [1005]); /// 1005: ';' Expected + }); + + it("Does not generate semantic diagnostics", () => { + runTest(`var x: string = 0;`, + { module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, []); + }); + + it("Generates module output", () => { + runTest(`var x = 0;`, { module: ModuleKind.AMD }, `define(["require", "exports"], function (require, exports) {\r\n var x = 0;\r\n});\r\n`); + }); + + it("Uses correct newLine character", () => { + runTest(`var x = 0;`, { module: ModuleKind.CommonJS, newLine: NewLineKind.LineFeed }, `var x = 0;\n`); + }); + }); +} From 2cbe14e1312296cdb1c8abfa0b81c6fb6932701e Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 27 May 2015 10:20:01 -0700 Subject: [PATCH 02/26] Respond to code review comments --- src/compiler/program.ts | 2 +- src/services/services.ts | 9 ++++++--- tests/cases/unittests/transpile.ts | 6 +++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 4cccc881d40..1db32b95954 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -286,7 +286,7 @@ module ts { } } - function getCompilerOptionsDiagnostics(): Diagnostic[]{ + function getCompilerOptionsDiagnostics(): Diagnostic[] { let allDiagnostics: Diagnostic[] = []; addRange(allDiagnostics, diagnostics.getGlobalDiagnostics()); return sortAndDeduplicateDiagnostics(allDiagnostics); diff --git a/src/services/services.ts b/src/services/services.ts index ff1e627a241..58155f2a691 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1763,6 +1763,8 @@ module ts { * Extra compiler options that will unconditionally be used bu this function are: * - isolatedModules = true * - allowNonTsExtensions = true + * - noLib = true + * - noResolve = true */ export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string { let options = compilerOptions ? clone(compilerOptions) : getDefaultCompilerOptions(); @@ -1772,11 +1774,12 @@ module ts { // Filename can be non-ts file. options.allowNonTsExtensions = true; - // We are not returning a lib file when asked, so pass this flag to - // avoid reporting a file not found error + // We are not returning a sourceFile for lib file when asked by the program, + // so pass --noLib to avoid reporting a file not found error. options.noLib = true; - // Similar to the library, we are not returning any refrenced files + // We are not doing a full typecheck, we are not resolving the whole context, + // so pass --noResolve to avoid reporting missing file errors. options.noResolve = true; // Parse diff --git a/tests/cases/unittests/transpile.ts b/tests/cases/unittests/transpile.ts index 32caad8d05c..eca136649f2 100644 --- a/tests/cases/unittests/transpile.ts +++ b/tests/cases/unittests/transpile.ts @@ -7,10 +7,10 @@ module ts { let diagnostics: Diagnostic[] = []; let result = transpile(input, compilerOptions, "file.ts", diagnostics); - assert.equal(diagnostics.length, expectedDiagnosticCodes.length); - for (let diagnostic of diagnostics) { - assert.isTrue(expectedDiagnosticCodes.indexOf(diagnostic.code) >= 0, `Found an unexpected diagnostic: ${ diagnostic.code }`); + for (let i = 0; i < expectedDiagnosticCodes.length; i++) { + assert.equal(expectedDiagnosticCodes[i], diagnostics[i] && diagnostics[i].code, `Could not find expeced diagnostic.`); } + assert.equal(diagnostics.length, expectedDiagnosticCodes.length, "Resuting diagnostics count does not match expected"); if (expectedOutput !== undefined) { assert.equal(result, expectedOutput); From 456eedf43295e90bcb5cedeb4e84c66efc96aceb Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 27 May 2015 14:56:30 -0700 Subject: [PATCH 03/26] Added tests. --- ...lassExpressionWithResolutionOfNamespaceOfSameName01.ts | 8 ++++++++ ...tionDeclarationWithResolutionOfTypeNamedArguments01.ts | 6 ++++++ ...functionDeclarationWithResolutionOfTypeOfSameName01.ts | 6 ++++++ ...ctionExpressionWithResolutionOfTypeNamedArguments01.ts | 6 ++++++ .../functionExpressionWithResolutionOfTypeOfSameName01.ts | 6 ++++++ 5 files changed, 32 insertions(+) create mode 100644 tests/cases/compiler/classExpressionWithResolutionOfNamespaceOfSameName01.ts create mode 100644 tests/cases/compiler/functionDeclarationWithResolutionOfTypeNamedArguments01.ts create mode 100644 tests/cases/compiler/functionDeclarationWithResolutionOfTypeOfSameName01.ts create mode 100644 tests/cases/compiler/functionExpressionWithResolutionOfTypeNamedArguments01.ts create mode 100644 tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName01.ts diff --git a/tests/cases/compiler/classExpressionWithResolutionOfNamespaceOfSameName01.ts b/tests/cases/compiler/classExpressionWithResolutionOfNamespaceOfSameName01.ts new file mode 100644 index 00000000000..ce44c2bca43 --- /dev/null +++ b/tests/cases/compiler/classExpressionWithResolutionOfNamespaceOfSameName01.ts @@ -0,0 +1,8 @@ +namespace C { + export interface type { + } +} + +var x = class C { + prop: C.type; +} \ No newline at end of file diff --git a/tests/cases/compiler/functionDeclarationWithResolutionOfTypeNamedArguments01.ts b/tests/cases/compiler/functionDeclarationWithResolutionOfTypeNamedArguments01.ts new file mode 100644 index 00000000000..b9ceeb4740b --- /dev/null +++ b/tests/cases/compiler/functionDeclarationWithResolutionOfTypeNamedArguments01.ts @@ -0,0 +1,6 @@ +interface arguments { +} + +function f() { + arguments; +} \ No newline at end of file diff --git a/tests/cases/compiler/functionDeclarationWithResolutionOfTypeOfSameName01.ts b/tests/cases/compiler/functionDeclarationWithResolutionOfTypeOfSameName01.ts new file mode 100644 index 00000000000..9dc0bf86943 --- /dev/null +++ b/tests/cases/compiler/functionDeclarationWithResolutionOfTypeOfSameName01.ts @@ -0,0 +1,6 @@ +interface f { +} + +function f() { + f; +} \ No newline at end of file diff --git a/tests/cases/compiler/functionExpressionWithResolutionOfTypeNamedArguments01.ts b/tests/cases/compiler/functionExpressionWithResolutionOfTypeNamedArguments01.ts new file mode 100644 index 00000000000..c1b99ee8f0e --- /dev/null +++ b/tests/cases/compiler/functionExpressionWithResolutionOfTypeNamedArguments01.ts @@ -0,0 +1,6 @@ +interface arguments { +} + +var x = function f() { + arguments; +} \ No newline at end of file diff --git a/tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName01.ts b/tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName01.ts new file mode 100644 index 00000000000..de4d0e3bb90 --- /dev/null +++ b/tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName01.ts @@ -0,0 +1,6 @@ +interface f { +} + +var x = function f() { + f; +} \ No newline at end of file From ac152ed19d548dd418ddd15e563671e13f3f8504 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 27 May 2015 15:03:54 -0700 Subject: [PATCH 04/26] Accepted baselines for the only test that was expected to pass. --- ...onDeclarationWithResolutionOfTypeOfSameName01.js | 12 ++++++++++++ ...larationWithResolutionOfTypeOfSameName01.symbols | 12 ++++++++++++ ...eclarationWithResolutionOfTypeOfSameName01.types | 13 +++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 tests/baselines/reference/functionDeclarationWithResolutionOfTypeOfSameName01.js create mode 100644 tests/baselines/reference/functionDeclarationWithResolutionOfTypeOfSameName01.symbols create mode 100644 tests/baselines/reference/functionDeclarationWithResolutionOfTypeOfSameName01.types diff --git a/tests/baselines/reference/functionDeclarationWithResolutionOfTypeOfSameName01.js b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeOfSameName01.js new file mode 100644 index 00000000000..6f5bb2cacf9 --- /dev/null +++ b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeOfSameName01.js @@ -0,0 +1,12 @@ +//// [functionDeclarationWithResolutionOfTypeOfSameName01.ts] +interface f { +} + +function f() { + f; +} + +//// [functionDeclarationWithResolutionOfTypeOfSameName01.js] +function f() { + f; +} diff --git a/tests/baselines/reference/functionDeclarationWithResolutionOfTypeOfSameName01.symbols b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeOfSameName01.symbols new file mode 100644 index 00000000000..aa51fad0538 --- /dev/null +++ b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeOfSameName01.symbols @@ -0,0 +1,12 @@ +=== tests/cases/compiler/functionDeclarationWithResolutionOfTypeOfSameName01.ts === +interface f { +>f : Symbol(f, Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 0, 0), Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 1, 1)) +} + +function f() { +>f : Symbol(f, Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 0, 0), Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 1, 1)) + + f; +>f : Symbol(f, Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 0, 0), Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 1, 1)) +>f : Symbol(f, Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 0, 0), Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 1, 1)) +} diff --git a/tests/baselines/reference/functionDeclarationWithResolutionOfTypeOfSameName01.types b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeOfSameName01.types new file mode 100644 index 00000000000..1067b8989c8 --- /dev/null +++ b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeOfSameName01.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/functionDeclarationWithResolutionOfTypeOfSameName01.ts === +interface f { +>f : f +} + +function f() { +>f : () => void + + f; +>f : f +>f : f +>f : () => void +} From 4088bc099c797ada14b0b2606d1e8d758324a413 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 27 May 2015 15:04:34 -0700 Subject: [PATCH 05/26] Only resolve 'arguments' and function/class expression names if the meaning permits it. --- src/compiler/checker.ts | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d409d1ea2fa..8a833123dcb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -422,27 +422,33 @@ module ts { case SyntaxKind.SetAccessor: case SyntaxKind.FunctionDeclaration: case SyntaxKind.ArrowFunction: - if (name === "arguments") { - result = argumentsSymbol; - break loop; + if (meaning & SymbolFlags.Value) { + if (name === "arguments") { + result = argumentsSymbol; + break loop; + } } break; case SyntaxKind.FunctionExpression: - if (name === "arguments") { - result = argumentsSymbol; - break loop; - } - let functionName = (location).name; - if (functionName && name === functionName.text) { - result = location.symbol; - break loop; + if (meaning & SymbolFlags.Value) { + if (name === "arguments") { + result = argumentsSymbol; + break loop; + } + let functionName = (location).name; + if (functionName && name === functionName.text) { + result = location.symbol; + break loop; + } } break; case SyntaxKind.ClassExpression: - let className = (location).name; - if (className && name === className.text) { - result = location.symbol; - break loop; + if (meaning & (SymbolFlags.Value | SymbolFlags.Type)) { + let className = (location).name; + if (className && name === className.text) { + result = location.symbol; + break loop; + } } break; case SyntaxKind.Decorator: From 644dbf230fabd7bb85c5bd0bc359083b88bd8600 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 27 May 2015 16:03:04 -0700 Subject: [PATCH 06/26] Don't use 'Value' or 'Type' as they have overlap. Instead test for the precice meaning. --- src/compiler/checker.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8a833123dcb..991e83150a3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -422,19 +422,18 @@ module ts { case SyntaxKind.SetAccessor: case SyntaxKind.FunctionDeclaration: case SyntaxKind.ArrowFunction: - if (meaning & SymbolFlags.Value) { - if (name === "arguments") { - result = argumentsSymbol; - break loop; - } + if (meaning & SymbolFlags.Variable && name === "arguments") { + result = argumentsSymbol; + break loop; } break; case SyntaxKind.FunctionExpression: - if (meaning & SymbolFlags.Value) { - if (name === "arguments") { - result = argumentsSymbol; - break loop; - } + if (meaning & SymbolFlags.Variable && name === "arguments") { + result = argumentsSymbol; + break loop; + } + + if (meaning & SymbolFlags.Function) { let functionName = (location).name; if (functionName && name === functionName.text) { result = location.symbol; @@ -443,7 +442,7 @@ module ts { } break; case SyntaxKind.ClassExpression: - if (meaning & (SymbolFlags.Value | SymbolFlags.Type)) { + if (meaning & SymbolFlags.Class) { let className = (location).name; if (className && name === className.text) { result = location.symbol; From 636347d86b7537c708b0478545dde85b2bd7eb6e Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 27 May 2015 16:03:27 -0700 Subject: [PATCH 07/26] Accepted baselines. --- ...hResolutionOfNamespaceOfSameName01.errors.txt | 14 ++++++++++++++ ...ssionWithResolutionOfNamespaceOfSameName01.js | 16 ++++++++++++++++ ...rationWithResolutionOfTypeNamedArguments01.js | 12 ++++++++++++ ...nWithResolutionOfTypeNamedArguments01.symbols | 12 ++++++++++++ ...ionWithResolutionOfTypeNamedArguments01.types | 13 +++++++++++++ ...essionWithResolutionOfTypeNamedArguments01.js | 12 ++++++++++++ ...nWithResolutionOfTypeNamedArguments01.symbols | 13 +++++++++++++ ...ionWithResolutionOfTypeNamedArguments01.types | 15 +++++++++++++++ ...ExpressionWithResolutionOfTypeOfSameName01.js | 12 ++++++++++++ ...ssionWithResolutionOfTypeOfSameName01.symbols | 13 +++++++++++++ ...ressionWithResolutionOfTypeOfSameName01.types | 15 +++++++++++++++ 11 files changed, 147 insertions(+) create mode 100644 tests/baselines/reference/classExpressionWithResolutionOfNamespaceOfSameName01.errors.txt create mode 100644 tests/baselines/reference/classExpressionWithResolutionOfNamespaceOfSameName01.js create mode 100644 tests/baselines/reference/functionDeclarationWithResolutionOfTypeNamedArguments01.js create mode 100644 tests/baselines/reference/functionDeclarationWithResolutionOfTypeNamedArguments01.symbols create mode 100644 tests/baselines/reference/functionDeclarationWithResolutionOfTypeNamedArguments01.types create mode 100644 tests/baselines/reference/functionExpressionWithResolutionOfTypeNamedArguments01.js create mode 100644 tests/baselines/reference/functionExpressionWithResolutionOfTypeNamedArguments01.symbols create mode 100644 tests/baselines/reference/functionExpressionWithResolutionOfTypeNamedArguments01.types create mode 100644 tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName01.js create mode 100644 tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName01.symbols create mode 100644 tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName01.types diff --git a/tests/baselines/reference/classExpressionWithResolutionOfNamespaceOfSameName01.errors.txt b/tests/baselines/reference/classExpressionWithResolutionOfNamespaceOfSameName01.errors.txt new file mode 100644 index 00000000000..8edc1d8f74b --- /dev/null +++ b/tests/baselines/reference/classExpressionWithResolutionOfNamespaceOfSameName01.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/classExpressionWithResolutionOfNamespaceOfSameName01.ts(6,15): error TS9003: 'class' expressions are not currently supported. + + +==== tests/cases/compiler/classExpressionWithResolutionOfNamespaceOfSameName01.ts (1 errors) ==== + namespace C { + export interface type { + } + } + + var x = class C { + ~ +!!! error TS9003: 'class' expressions are not currently supported. + prop: C.type; + } \ No newline at end of file diff --git a/tests/baselines/reference/classExpressionWithResolutionOfNamespaceOfSameName01.js b/tests/baselines/reference/classExpressionWithResolutionOfNamespaceOfSameName01.js new file mode 100644 index 00000000000..7c9f25cdfe6 --- /dev/null +++ b/tests/baselines/reference/classExpressionWithResolutionOfNamespaceOfSameName01.js @@ -0,0 +1,16 @@ +//// [classExpressionWithResolutionOfNamespaceOfSameName01.ts] +namespace C { + export interface type { + } +} + +var x = class C { + prop: C.type; +} + +//// [classExpressionWithResolutionOfNamespaceOfSameName01.js] +var x = (function () { + function C() { + } + return C; +})(); diff --git a/tests/baselines/reference/functionDeclarationWithResolutionOfTypeNamedArguments01.js b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeNamedArguments01.js new file mode 100644 index 00000000000..3659f3fd9f9 --- /dev/null +++ b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeNamedArguments01.js @@ -0,0 +1,12 @@ +//// [functionDeclarationWithResolutionOfTypeNamedArguments01.ts] +interface arguments { +} + +function f() { + arguments; +} + +//// [functionDeclarationWithResolutionOfTypeNamedArguments01.js] +function f() { + arguments; +} diff --git a/tests/baselines/reference/functionDeclarationWithResolutionOfTypeNamedArguments01.symbols b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeNamedArguments01.symbols new file mode 100644 index 00000000000..8a36f146001 --- /dev/null +++ b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeNamedArguments01.symbols @@ -0,0 +1,12 @@ +=== tests/cases/compiler/functionDeclarationWithResolutionOfTypeNamedArguments01.ts === +interface arguments { +>arguments : Symbol(arguments, Decl(functionDeclarationWithResolutionOfTypeNamedArguments01.ts, 0, 0)) +} + +function f() { +>f : Symbol(f, Decl(functionDeclarationWithResolutionOfTypeNamedArguments01.ts, 1, 1)) + + arguments; +>arguments : Symbol(arguments, Decl(functionDeclarationWithResolutionOfTypeNamedArguments01.ts, 0, 0)) +>arguments : Symbol(arguments) +} diff --git a/tests/baselines/reference/functionDeclarationWithResolutionOfTypeNamedArguments01.types b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeNamedArguments01.types new file mode 100644 index 00000000000..72dbbf8ec69 --- /dev/null +++ b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeNamedArguments01.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/functionDeclarationWithResolutionOfTypeNamedArguments01.ts === +interface arguments { +>arguments : arguments +} + +function f() { +>f : () => void + + arguments; +>arguments : arguments +>arguments : arguments +>arguments : IArguments +} diff --git a/tests/baselines/reference/functionExpressionWithResolutionOfTypeNamedArguments01.js b/tests/baselines/reference/functionExpressionWithResolutionOfTypeNamedArguments01.js new file mode 100644 index 00000000000..43b38f2dd39 --- /dev/null +++ b/tests/baselines/reference/functionExpressionWithResolutionOfTypeNamedArguments01.js @@ -0,0 +1,12 @@ +//// [functionExpressionWithResolutionOfTypeNamedArguments01.ts] +interface arguments { +} + +var x = function f() { + arguments; +} + +//// [functionExpressionWithResolutionOfTypeNamedArguments01.js] +var x = function f() { + arguments; +}; diff --git a/tests/baselines/reference/functionExpressionWithResolutionOfTypeNamedArguments01.symbols b/tests/baselines/reference/functionExpressionWithResolutionOfTypeNamedArguments01.symbols new file mode 100644 index 00000000000..d2455fd0106 --- /dev/null +++ b/tests/baselines/reference/functionExpressionWithResolutionOfTypeNamedArguments01.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/functionExpressionWithResolutionOfTypeNamedArguments01.ts === +interface arguments { +>arguments : Symbol(arguments, Decl(functionExpressionWithResolutionOfTypeNamedArguments01.ts, 0, 0)) +} + +var x = function f() { +>x : Symbol(x, Decl(functionExpressionWithResolutionOfTypeNamedArguments01.ts, 3, 3)) +>f : Symbol(f, Decl(functionExpressionWithResolutionOfTypeNamedArguments01.ts, 3, 7)) + + arguments; +>arguments : Symbol(arguments, Decl(functionExpressionWithResolutionOfTypeNamedArguments01.ts, 0, 0)) +>arguments : Symbol(arguments) +} diff --git a/tests/baselines/reference/functionExpressionWithResolutionOfTypeNamedArguments01.types b/tests/baselines/reference/functionExpressionWithResolutionOfTypeNamedArguments01.types new file mode 100644 index 00000000000..1a65010a4f6 --- /dev/null +++ b/tests/baselines/reference/functionExpressionWithResolutionOfTypeNamedArguments01.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/functionExpressionWithResolutionOfTypeNamedArguments01.ts === +interface arguments { +>arguments : arguments +} + +var x = function f() { +>x : () => void +>function f() { arguments;} : () => void +>f : () => void + + arguments; +>arguments : arguments +>arguments : arguments +>arguments : IArguments +} diff --git a/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName01.js b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName01.js new file mode 100644 index 00000000000..c9af7ab3297 --- /dev/null +++ b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName01.js @@ -0,0 +1,12 @@ +//// [functionExpressionWithResolutionOfTypeOfSameName01.ts] +interface f { +} + +var x = function f() { + f; +} + +//// [functionExpressionWithResolutionOfTypeOfSameName01.js] +var x = function f() { + f; +}; diff --git a/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName01.symbols b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName01.symbols new file mode 100644 index 00000000000..cd2248c6018 --- /dev/null +++ b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName01.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName01.ts === +interface f { +>f : Symbol(f, Decl(functionExpressionWithResolutionOfTypeOfSameName01.ts, 0, 0)) +} + +var x = function f() { +>x : Symbol(x, Decl(functionExpressionWithResolutionOfTypeOfSameName01.ts, 3, 3)) +>f : Symbol(f, Decl(functionExpressionWithResolutionOfTypeOfSameName01.ts, 3, 7)) + + f; +>f : Symbol(f, Decl(functionExpressionWithResolutionOfTypeOfSameName01.ts, 0, 0)) +>f : Symbol(f, Decl(functionExpressionWithResolutionOfTypeOfSameName01.ts, 3, 7)) +} diff --git a/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName01.types b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName01.types new file mode 100644 index 00000000000..08b51f35226 --- /dev/null +++ b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName01.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName01.ts === +interface f { +>f : f +} + +var x = function f() { +>x : () => void +>function f() { f;} : () => void +>f : () => void + + f; +>f : f +>f : f +>f : () => void +} From db313061ee1ba80fc263829f14f65dc26f8dc766 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 27 May 2015 16:30:44 -0700 Subject: [PATCH 08/26] Added another test. --- .../functionExpressionWithResolutionOfTypeOfSameName02.ts | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName02.ts diff --git a/tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName02.ts b/tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName02.ts new file mode 100644 index 00000000000..041195271fb --- /dev/null +++ b/tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName02.ts @@ -0,0 +1,6 @@ +interface Foo { +} + +var x = function Foo() { + var x: Foo; +} \ No newline at end of file From acbff901da2b80b346ea1dcaae057ca854294265 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 27 May 2015 16:34:39 -0700 Subject: [PATCH 09/26] Accepted baselines. --- ...onExpressionWithResolutionOfTypeOfSameName02.js | 12 ++++++++++++ ...ressionWithResolutionOfTypeOfSameName02.symbols | 13 +++++++++++++ ...xpressionWithResolutionOfTypeOfSameName02.types | 14 ++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName02.js create mode 100644 tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName02.symbols create mode 100644 tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName02.types diff --git a/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName02.js b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName02.js new file mode 100644 index 00000000000..ada96c63a56 --- /dev/null +++ b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName02.js @@ -0,0 +1,12 @@ +//// [functionExpressionWithResolutionOfTypeOfSameName02.ts] +interface Foo { +} + +var x = function Foo() { + var x: Foo; +} + +//// [functionExpressionWithResolutionOfTypeOfSameName02.js] +var x = function Foo() { + var x; +}; diff --git a/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName02.symbols b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName02.symbols new file mode 100644 index 00000000000..89b46c99b4e --- /dev/null +++ b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName02.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName02.ts === +interface Foo { +>Foo : Symbol(Foo, Decl(functionExpressionWithResolutionOfTypeOfSameName02.ts, 0, 0)) +} + +var x = function Foo() { +>x : Symbol(x, Decl(functionExpressionWithResolutionOfTypeOfSameName02.ts, 3, 3)) +>Foo : Symbol(Foo, Decl(functionExpressionWithResolutionOfTypeOfSameName02.ts, 3, 7)) + + var x: Foo; +>x : Symbol(x, Decl(functionExpressionWithResolutionOfTypeOfSameName02.ts, 4, 7)) +>Foo : Symbol(Foo, Decl(functionExpressionWithResolutionOfTypeOfSameName02.ts, 0, 0)) +} diff --git a/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName02.types b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName02.types new file mode 100644 index 00000000000..218276a95ea --- /dev/null +++ b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName02.types @@ -0,0 +1,14 @@ +=== tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName02.ts === +interface Foo { +>Foo : Foo +} + +var x = function Foo() { +>x : () => void +>function Foo() { var x: Foo;} : () => void +>Foo : () => void + + var x: Foo; +>x : Foo +>Foo : Foo +} From a10cd1e8226d97c904b35dffcd5d7890f4cbb062 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 2 Jun 2015 15:48:59 -0700 Subject: [PATCH 10/26] Update LKG --- bin/tsc.js | 24 ++++++++++++++---------- bin/tsserver.js | 24 ++++++++++++++---------- bin/typescript.js | 24 ++++++++++++++---------- bin/typescriptServices.js | 24 ++++++++++++++---------- 4 files changed, 56 insertions(+), 40 deletions(-) diff --git a/bin/tsc.js b/bin/tsc.js index 8c1542d6c7b..01d312f2083 100644 --- a/bin/tsc.js +++ b/bin/tsc.js @@ -8892,27 +8892,31 @@ var ts; case 138: case 201: case 164: - if (name === "arguments") { + if (meaning & 3 && name === "arguments") { result = argumentsSymbol; break loop; } break; case 163: - if (name === "arguments") { + if (meaning & 3 && name === "arguments") { result = argumentsSymbol; break loop; } - var functionName = location.name; - if (functionName && name === functionName.text) { - result = location.symbol; - break loop; + if (meaning & 16) { + var functionName = location.name; + if (functionName && name === functionName.text) { + result = location.symbol; + break loop; + } } break; case 175: - var className = location.name; - if (className && name === className.text) { - result = location.symbol; - break loop; + if (meaning & 32) { + var className = location.name; + if (className && name === className.text) { + result = location.symbol; + break loop; + } } break; case 131: diff --git a/bin/tsserver.js b/bin/tsserver.js index 4f175eee95b..6cdb8f9560c 100644 --- a/bin/tsserver.js +++ b/bin/tsserver.js @@ -9282,27 +9282,31 @@ var ts; case 138: case 201: case 164: - if (name === "arguments") { + if (meaning & 3 && name === "arguments") { result = argumentsSymbol; break loop; } break; case 163: - if (name === "arguments") { + if (meaning & 3 && name === "arguments") { result = argumentsSymbol; break loop; } - var functionName = location.name; - if (functionName && name === functionName.text) { - result = location.symbol; - break loop; + if (meaning & 16) { + var functionName = location.name; + if (functionName && name === functionName.text) { + result = location.symbol; + break loop; + } } break; case 175: - var className = location.name; - if (className && name === className.text) { - result = location.symbol; - break loop; + if (meaning & 32) { + var className = location.name; + if (className && name === className.text) { + result = location.symbol; + break loop; + } } break; case 131: diff --git a/bin/typescript.js b/bin/typescript.js index a60814cc7fd..dbede84a76e 100644 --- a/bin/typescript.js +++ b/bin/typescript.js @@ -11147,27 +11147,31 @@ var ts; case 138 /* SetAccessor */: case 201 /* FunctionDeclaration */: case 164 /* ArrowFunction */: - if (name === "arguments") { + if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; } break; case 163 /* FunctionExpression */: - if (name === "arguments") { + if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; } - var functionName = location.name; - if (functionName && name === functionName.text) { - result = location.symbol; - break loop; + if (meaning & 16 /* Function */) { + var functionName = location.name; + if (functionName && name === functionName.text) { + result = location.symbol; + break loop; + } } break; case 175 /* ClassExpression */: - var className = location.name; - if (className && name === className.text) { - result = location.symbol; - break loop; + if (meaning & 32 /* Class */) { + var className = location.name; + if (className && name === className.text) { + result = location.symbol; + break loop; + } } break; case 131 /* Decorator */: diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js index a60814cc7fd..dbede84a76e 100644 --- a/bin/typescriptServices.js +++ b/bin/typescriptServices.js @@ -11147,27 +11147,31 @@ var ts; case 138 /* SetAccessor */: case 201 /* FunctionDeclaration */: case 164 /* ArrowFunction */: - if (name === "arguments") { + if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; } break; case 163 /* FunctionExpression */: - if (name === "arguments") { + if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; } - var functionName = location.name; - if (functionName && name === functionName.text) { - result = location.symbol; - break loop; + if (meaning & 16 /* Function */) { + var functionName = location.name; + if (functionName && name === functionName.text) { + result = location.symbol; + break loop; + } } break; case 175 /* ClassExpression */: - var className = location.name; - if (className && name === className.text) { - result = location.symbol; - break loop; + if (meaning & 32 /* Class */) { + var className = location.name; + if (className && name === className.text) { + result = location.symbol; + break loop; + } } break; case 131 /* Decorator */: From 6902b050ca9cb94ba494d0900ad48a0780850ef4 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 2 Jun 2015 18:04:05 -0700 Subject: [PATCH 11/26] Respond to code review comments --- tests/cases/unittests/transpile.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/cases/unittests/transpile.ts b/tests/cases/unittests/transpile.ts index eca136649f2..c906c03a9e0 100644 --- a/tests/cases/unittests/transpile.ts +++ b/tests/cases/unittests/transpile.ts @@ -19,33 +19,33 @@ module ts { it("Generates correct compilerOptions diagnostics", () => { // Expecting 5047: "Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher." - runTest(`var x = 0;`, {}, /*expectedOutput*/ undefined, [5047]); + runTest(`var x = 0;`, {}, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ [5047]); }); it("Generates no diagnostics with valid inputs", () => { // No errors - runTest(`var x = 0;`, { module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, []); + runTest(`var x = 0;`, { module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []); }); it("Generates no diagnostics for missing file references", () => { runTest(`/// var x = 0;`, - { module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, []); + { module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []); }); it("Generates no diagnostics for missing module imports", () => { runTest(`import {a} from "module2";`, - { module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, []); + { module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []); }); it("Generates expected syntactic diagnostics", () => { runTest(`a b`, - { module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, [1005]); /// 1005: ';' Expected + { module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ [1005]); /// 1005: ';' Expected }); it("Does not generate semantic diagnostics", () => { runTest(`var x: string = 0;`, - { module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, []); + { module: ModuleKind.CommonJS }, /*expectedOutput*/ undefined, /*expectedDiagnosticCodes*/ []); }); it("Generates module output", () => { @@ -53,7 +53,7 @@ var x = 0;`, }); it("Uses correct newLine character", () => { - runTest(`var x = 0;`, { module: ModuleKind.CommonJS, newLine: NewLineKind.LineFeed }, `var x = 0;\n`); + runTest(`var x = 0;`, { module: ModuleKind.CommonJS, newLine: NewLineKind.LineFeed }, `var x = 0;\n`, /*expectedDiagnosticCodes*/ []); }); }); } From 86d9398a929de9c5816e664a271ff392687107d2 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 1 Jun 2015 16:08:58 -0700 Subject: [PATCH 12/26] clean hostCache to avoid extending lifetime of script snapshots --- src/services/services.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/services/services.ts b/src/services/services.ts index 58155f2a691..6a497c87307 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2487,6 +2487,10 @@ module ts { } } + // hostCache is captured in the closure for 'getOrCreateSourceFile' but it should not be used past this point. + // It needs to be cleared to allow all collected snapshots to be released + hostCache = undefined; + program = newProgram; // Make sure all the nodes in the program are both bound, and have their parent @@ -2495,6 +2499,7 @@ module ts { return; function getOrCreateSourceFile(fileName: string): SourceFile { + Debug.assert(hostCache !== undefined); // The program is asking for this file, check first if the host can locate it. // If the host can not locate the file, then it does not exist. return undefined // to the program to allow reporting of errors for missing files. From 46da6678ad082b53de4698740fa751bba7c8c29a Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Tue, 2 Jun 2015 17:33:57 -0700 Subject: [PATCH 13/26] Return expressions always need to be type checked --- src/compiler/checker.ts | 4 ++++ ...ltiLinePropertyAccessAndArrowFunctionIndent1.errors.txt | 5 ++++- .../reference/typeCheckReturnExpression.errors.txt | 7 +++++++ tests/baselines/reference/typeCheckReturnExpression.js | 5 +++++ tests/cases/compiler/typeCheckReturnExpression.ts | 2 ++ 5 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/typeCheckReturnExpression.errors.txt create mode 100644 tests/baselines/reference/typeCheckReturnExpression.js create mode 100644 tests/cases/compiler/typeCheckReturnExpression.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ab5d8e4207f..aa3b69d9b34 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7454,6 +7454,10 @@ module ts { } if (node.body) { + if (!node.type) { + getReturnTypeOfSignature(getSignatureFromDeclaration(node)); + } + if (node.body.kind === SyntaxKind.Block) { checkSourceElement(node.body); } diff --git a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt index 14b7769d22f..abf11dc9dba 100644 --- a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt +++ b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt @@ -1,12 +1,15 @@ tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(1,1): error TS1108: A 'return' statement can only be used within a function body. +tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(1,18): error TS2304: Cannot find name 'role'. tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(2,18): error TS2304: Cannot find name 'Role'. tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(4,26): error TS2503: Cannot find namespace 'ng'. -==== tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts (3 errors) ==== +==== tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts (4 errors) ==== return this.edit(role) ~~~~~~ !!! error TS1108: A 'return' statement can only be used within a function body. + ~~~~ +!!! error TS2304: Cannot find name 'role'. .then((role: Role) => ~~~~ !!! error TS2304: Cannot find name 'Role'. diff --git a/tests/baselines/reference/typeCheckReturnExpression.errors.txt b/tests/baselines/reference/typeCheckReturnExpression.errors.txt new file mode 100644 index 00000000000..c648c57799d --- /dev/null +++ b/tests/baselines/reference/typeCheckReturnExpression.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/typeCheckReturnExpression.ts(1,11): error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type. + + +==== tests/cases/compiler/typeCheckReturnExpression.ts (1 errors) ==== + var foo = () => undefined; + ~~~~~~~~~~~~~~~ +!!! error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type. \ No newline at end of file diff --git a/tests/baselines/reference/typeCheckReturnExpression.js b/tests/baselines/reference/typeCheckReturnExpression.js new file mode 100644 index 00000000000..ba71780b48d --- /dev/null +++ b/tests/baselines/reference/typeCheckReturnExpression.js @@ -0,0 +1,5 @@ +//// [typeCheckReturnExpression.ts] +var foo = () => undefined; + +//// [typeCheckReturnExpression.js] +var foo = function () { return undefined; }; diff --git a/tests/cases/compiler/typeCheckReturnExpression.ts b/tests/cases/compiler/typeCheckReturnExpression.ts new file mode 100644 index 00000000000..00f75912bd1 --- /dev/null +++ b/tests/cases/compiler/typeCheckReturnExpression.ts @@ -0,0 +1,2 @@ +//@noImplicitAny: true +var foo = () => undefined; \ No newline at end of file From 22cc3a7d848fa3adfbbeb58ec359dc5a201221c8 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Tue, 2 Jun 2015 17:54:08 -0700 Subject: [PATCH 14/26] Add hopefully helpful comment --- src/compiler/checker.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index aa3b69d9b34..8ee39ab18f3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7455,6 +7455,11 @@ module ts { if (node.body) { if (!node.type) { + // There are some checks that are only performed in getReturnTypeFromBody, that may produce errors + // we need. An example is the noImplicitAny errors resulting from widening the return expression + // of a function. Because checking of function expression bodies is deferred, there was never an + // appropriate time to do this during the main walk of the file (see the comment at the top of + // checkFunctionExpressionBodies). So it must be done now. getReturnTypeOfSignature(getSignatureFromDeclaration(node)); } From 9394c5ca04231ec17626ea4867042dcfd61b0443 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Tue, 2 Jun 2015 18:06:05 -0700 Subject: [PATCH 15/26] Add test for object literal methods --- .../typeCheckReturnExpressionMethodBody.errors.txt | 7 +++++++ .../reference/typeCheckReturnExpressionMethodBody.js | 5 +++++ .../cases/compiler/typeCheckReturnExpressionMethodBody.ts | 2 ++ 3 files changed, 14 insertions(+) create mode 100644 tests/baselines/reference/typeCheckReturnExpressionMethodBody.errors.txt create mode 100644 tests/baselines/reference/typeCheckReturnExpressionMethodBody.js create mode 100644 tests/cases/compiler/typeCheckReturnExpressionMethodBody.ts diff --git a/tests/baselines/reference/typeCheckReturnExpressionMethodBody.errors.txt b/tests/baselines/reference/typeCheckReturnExpressionMethodBody.errors.txt new file mode 100644 index 00000000000..a32f6548c9f --- /dev/null +++ b/tests/baselines/reference/typeCheckReturnExpressionMethodBody.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/typeCheckReturnExpressionMethodBody.ts(1,13): error TS7010: 'bar', which lacks return-type annotation, implicitly has an 'any' return type. + + +==== tests/cases/compiler/typeCheckReturnExpressionMethodBody.ts (1 errors) ==== + var foo = { bar() { return undefined } }; + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS7010: 'bar', which lacks return-type annotation, implicitly has an 'any' return type. \ No newline at end of file diff --git a/tests/baselines/reference/typeCheckReturnExpressionMethodBody.js b/tests/baselines/reference/typeCheckReturnExpressionMethodBody.js new file mode 100644 index 00000000000..3050b05268f --- /dev/null +++ b/tests/baselines/reference/typeCheckReturnExpressionMethodBody.js @@ -0,0 +1,5 @@ +//// [typeCheckReturnExpressionMethodBody.ts] +var foo = { bar() { return undefined } }; + +//// [typeCheckReturnExpressionMethodBody.js] +var foo = { bar: function () { return undefined; } }; diff --git a/tests/cases/compiler/typeCheckReturnExpressionMethodBody.ts b/tests/cases/compiler/typeCheckReturnExpressionMethodBody.ts new file mode 100644 index 00000000000..316572466df --- /dev/null +++ b/tests/cases/compiler/typeCheckReturnExpressionMethodBody.ts @@ -0,0 +1,2 @@ +//@noImplicitAny: true +var foo = { bar() { return undefined } }; \ No newline at end of file From 34a5514fef25125b56dfff49fb0357aee2d1bb90 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Tue, 2 Jun 2015 18:21:39 -0700 Subject: [PATCH 16/26] Rename new test --- .../reference/typeCheckObjectLiteralMethodBody.errors.txt | 7 +++++++ ...onMethodBody.js => typeCheckObjectLiteralMethodBody.js} | 4 ++-- .../typeCheckReturnExpressionMethodBody.errors.txt | 7 ------- ...onMethodBody.ts => typeCheckObjectLiteralMethodBody.ts} | 0 4 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 tests/baselines/reference/typeCheckObjectLiteralMethodBody.errors.txt rename tests/baselines/reference/{typeCheckReturnExpressionMethodBody.js => typeCheckObjectLiteralMethodBody.js} (50%) delete mode 100644 tests/baselines/reference/typeCheckReturnExpressionMethodBody.errors.txt rename tests/cases/compiler/{typeCheckReturnExpressionMethodBody.ts => typeCheckObjectLiteralMethodBody.ts} (100%) diff --git a/tests/baselines/reference/typeCheckObjectLiteralMethodBody.errors.txt b/tests/baselines/reference/typeCheckObjectLiteralMethodBody.errors.txt new file mode 100644 index 00000000000..7db4c2506cc --- /dev/null +++ b/tests/baselines/reference/typeCheckObjectLiteralMethodBody.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/typeCheckObjectLiteralMethodBody.ts(1,13): error TS7010: 'bar', which lacks return-type annotation, implicitly has an 'any' return type. + + +==== tests/cases/compiler/typeCheckObjectLiteralMethodBody.ts (1 errors) ==== + var foo = { bar() { return undefined } }; + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS7010: 'bar', which lacks return-type annotation, implicitly has an 'any' return type. \ No newline at end of file diff --git a/tests/baselines/reference/typeCheckReturnExpressionMethodBody.js b/tests/baselines/reference/typeCheckObjectLiteralMethodBody.js similarity index 50% rename from tests/baselines/reference/typeCheckReturnExpressionMethodBody.js rename to tests/baselines/reference/typeCheckObjectLiteralMethodBody.js index 3050b05268f..1339315e93c 100644 --- a/tests/baselines/reference/typeCheckReturnExpressionMethodBody.js +++ b/tests/baselines/reference/typeCheckObjectLiteralMethodBody.js @@ -1,5 +1,5 @@ -//// [typeCheckReturnExpressionMethodBody.ts] +//// [typeCheckObjectLiteralMethodBody.ts] var foo = { bar() { return undefined } }; -//// [typeCheckReturnExpressionMethodBody.js] +//// [typeCheckObjectLiteralMethodBody.js] var foo = { bar: function () { return undefined; } }; diff --git a/tests/baselines/reference/typeCheckReturnExpressionMethodBody.errors.txt b/tests/baselines/reference/typeCheckReturnExpressionMethodBody.errors.txt deleted file mode 100644 index a32f6548c9f..00000000000 --- a/tests/baselines/reference/typeCheckReturnExpressionMethodBody.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/compiler/typeCheckReturnExpressionMethodBody.ts(1,13): error TS7010: 'bar', which lacks return-type annotation, implicitly has an 'any' return type. - - -==== tests/cases/compiler/typeCheckReturnExpressionMethodBody.ts (1 errors) ==== - var foo = { bar() { return undefined } }; - ~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS7010: 'bar', which lacks return-type annotation, implicitly has an 'any' return type. \ No newline at end of file diff --git a/tests/cases/compiler/typeCheckReturnExpressionMethodBody.ts b/tests/cases/compiler/typeCheckObjectLiteralMethodBody.ts similarity index 100% rename from tests/cases/compiler/typeCheckReturnExpressionMethodBody.ts rename to tests/cases/compiler/typeCheckObjectLiteralMethodBody.ts From 1bb46e3f332c41612b166fc12608b34f02809c92 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 3 Jun 2015 13:39:25 -0700 Subject: [PATCH 17/26] Update LKG after commit 34a5514fef25125b56dfff49fb0357aee2d1bb90 --- bin/tsc.js | 30 ++++++++++++++++++---- bin/tsserver.js | 39 +++++++++++++++++++++++------ bin/typescript.js | 52 +++++++++++++++++++++++++++++++++------ bin/typescriptServices.js | 52 +++++++++++++++++++++++++++++++++------ 4 files changed, 147 insertions(+), 26 deletions(-) diff --git a/bin/tsc.js b/bin/tsc.js index 01d312f2083..a6d28976046 100644 --- a/bin/tsc.js +++ b/bin/tsc.js @@ -4688,6 +4688,21 @@ var ts; return result; } ts.convertToBase64 = convertToBase64; + var carriageReturnLineFeed = "\r\n"; + var lineFeed = "\n"; + function getNewLineCharacter(options) { + if (options.newLine === 0) { + return carriageReturnLineFeed; + } + else if (options.newLine === 1) { + return lineFeed; + } + else if (ts.sys) { + return ts.sys.newLine; + } + return carriageReturnLineFeed; + } + ts.getNewLineCharacter = getNewLineCharacter; })(ts || (ts = {})); var ts; (function (ts) { @@ -14454,6 +14469,9 @@ var ts; checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } if (node.body) { + if (!node.type) { + getReturnTypeOfSignature(getSignatureFromDeclaration(node)); + } if (node.body.kind === 180) { checkSourceElement(node.body); } @@ -25062,8 +25080,6 @@ var ts; ts.ioReadTime = 0; ts.ioWriteTime = 0; ts.version = "1.5.3"; - var carriageReturnLineFeed = "\r\n"; - var lineFeed = "\n"; function findConfigFile(searchPath) { var fileName = "tsconfig.json"; while (true) { @@ -25134,9 +25150,7 @@ var ts; } } } - var newLine = options.newLine === 0 ? carriageReturnLineFeed : - options.newLine === 1 ? lineFeed : - ts.sys.newLine; + var newLine = ts.getNewLineCharacter(options); return { getSourceFile: getSourceFile, getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), ts.getDefaultLibFileName(options)); }, @@ -25204,6 +25218,7 @@ var ts; getGlobalDiagnostics: getGlobalDiagnostics, getSemanticDiagnostics: getSemanticDiagnostics, getDeclarationDiagnostics: getDeclarationDiagnostics, + getCompilerOptionsDiagnostics: getCompilerOptionsDiagnostics, getTypeChecker: getTypeChecker, getDiagnosticsProducingTypeChecker: getDiagnosticsProducingTypeChecker, getCommonSourceDirectory: function () { return commonSourceDirectory; }, @@ -25284,6 +25299,11 @@ var ts; return ts.getDeclarationDiagnostics(getEmitHost(writeFile), resolver, sourceFile); } } + function getCompilerOptionsDiagnostics() { + var allDiagnostics = []; + ts.addRange(allDiagnostics, diagnostics.getGlobalDiagnostics()); + return ts.sortAndDeduplicateDiagnostics(allDiagnostics); + } function getGlobalDiagnostics() { var typeChecker = getDiagnosticsProducingTypeChecker(); var allDiagnostics = []; diff --git a/bin/tsserver.js b/bin/tsserver.js index 6cdb8f9560c..194f0768196 100644 --- a/bin/tsserver.js +++ b/bin/tsserver.js @@ -4565,6 +4565,21 @@ var ts; return result; } ts.convertToBase64 = convertToBase64; + var carriageReturnLineFeed = "\r\n"; + var lineFeed = "\n"; + function getNewLineCharacter(options) { + if (options.newLine === 0) { + return carriageReturnLineFeed; + } + else if (options.newLine === 1) { + return lineFeed; + } + else if (ts.sys) { + return ts.sys.newLine; + } + return carriageReturnLineFeed; + } + ts.getNewLineCharacter = getNewLineCharacter; })(ts || (ts = {})); var ts; (function (ts) { @@ -14844,6 +14859,9 @@ var ts; checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } if (node.body) { + if (!node.type) { + getReturnTypeOfSignature(getSignatureFromDeclaration(node)); + } if (node.body.kind === 180) { checkSourceElement(node.body); } @@ -25452,8 +25470,6 @@ var ts; ts.ioReadTime = 0; ts.ioWriteTime = 0; ts.version = "1.5.3"; - var carriageReturnLineFeed = "\r\n"; - var lineFeed = "\n"; function findConfigFile(searchPath) { var fileName = "tsconfig.json"; while (true) { @@ -25524,9 +25540,7 @@ var ts; } } } - var newLine = options.newLine === 0 ? carriageReturnLineFeed : - options.newLine === 1 ? lineFeed : - ts.sys.newLine; + var newLine = ts.getNewLineCharacter(options); return { getSourceFile: getSourceFile, getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), ts.getDefaultLibFileName(options)); }, @@ -25594,6 +25608,7 @@ var ts; getGlobalDiagnostics: getGlobalDiagnostics, getSemanticDiagnostics: getSemanticDiagnostics, getDeclarationDiagnostics: getDeclarationDiagnostics, + getCompilerOptionsDiagnostics: getCompilerOptionsDiagnostics, getTypeChecker: getTypeChecker, getDiagnosticsProducingTypeChecker: getDiagnosticsProducingTypeChecker, getCommonSourceDirectory: function () { return commonSourceDirectory; }, @@ -25674,6 +25689,11 @@ var ts; return ts.getDeclarationDiagnostics(getEmitHost(writeFile), resolver, sourceFile); } } + function getCompilerOptionsDiagnostics() { + var allDiagnostics = []; + ts.addRange(allDiagnostics, diagnostics.getGlobalDiagnostics()); + return ts.sortAndDeduplicateDiagnostics(allDiagnostics); + } function getGlobalDiagnostics() { var typeChecker = getDiagnosticsProducingTypeChecker(); var allDiagnostics = []; @@ -31379,11 +31399,14 @@ var ts; var options = compilerOptions ? ts.clone(compilerOptions) : getDefaultCompilerOptions(); options.isolatedModules = true; options.allowNonTsExtensions = true; + options.noLib = true; + options.noResolve = true; var inputFileName = fileName || "module.ts"; var sourceFile = ts.createSourceFile(inputFileName, input, options.target); if (diagnostics && sourceFile.parseDiagnostics) { diagnostics.push.apply(diagnostics, sourceFile.parseDiagnostics); } + var newLine = ts.getNewLineCharacter(options); var outputText; var compilerHost = { getSourceFile: function (fileName, target) { return fileName === inputFileName ? sourceFile : undefined; }, @@ -31395,11 +31418,11 @@ var ts; useCaseSensitiveFileNames: function () { return false; }, getCanonicalFileName: function (fileName) { return fileName; }, getCurrentDirectory: function () { return ""; }, - getNewLine: function () { return (ts.sys && ts.sys.newLine) || "\r\n"; } + getNewLine: function () { return newLine; } }; var program = ts.createProgram([inputFileName], options, compilerHost); if (diagnostics) { - diagnostics.push.apply(diagnostics, program.getGlobalDiagnostics()); + diagnostics.push.apply(diagnostics, program.getCompilerOptionsDiagnostics()); } program.emit(); ts.Debug.assert(outputText !== undefined, "Output generation failed"); @@ -31914,10 +31937,12 @@ var ts; } } } + hostCache = undefined; program = newProgram; program.getTypeChecker(); return; function getOrCreateSourceFile(fileName) { + ts.Debug.assert(hostCache !== undefined); var hostFileInformation = hostCache.getOrCreateEntry(fileName); if (!hostFileInformation) { return undefined; diff --git a/bin/typescript.js b/bin/typescript.js index dbede84a76e..dac610e2504 100644 --- a/bin/typescript.js +++ b/bin/typescript.js @@ -5793,6 +5793,21 @@ var ts; return result; } ts.convertToBase64 = convertToBase64; + var carriageReturnLineFeed = "\r\n"; + var lineFeed = "\n"; + function getNewLineCharacter(options) { + if (options.newLine === 0 /* CarriageReturnLineFeed */) { + return carriageReturnLineFeed; + } + else if (options.newLine === 1 /* LineFeed */) { + return lineFeed; + } + else if (ts.sys) { + return ts.sys.newLine; + } + return carriageReturnLineFeed; + } + ts.getNewLineCharacter = getNewLineCharacter; })(ts || (ts = {})); var ts; (function (ts) { @@ -17596,6 +17611,14 @@ var ts; checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } if (node.body) { + if (!node.type) { + // There are some checks that are only performed in getReturnTypeFromBody, that may produce errors + // we need. An example is the noImplicitAny errors resulting from widening the return expression + // of a function. Because checking of function expression bodies is deferred, there was never an + // appropriate time to do this during the main walk of the file (see the comment at the top of + // checkFunctionExpressionBodies). So it must be done now. + getReturnTypeOfSignature(getSignatureFromDeclaration(node)); + } if (node.body.kind === 180 /* Block */) { checkSourceElement(node.body); } @@ -29658,8 +29681,6 @@ var ts; /* @internal */ ts.ioWriteTime = 0; /** The version of the TypeScript compiler release */ ts.version = "1.5.3"; - var carriageReturnLineFeed = "\r\n"; - var lineFeed = "\n"; function findConfigFile(searchPath) { var fileName = "tsconfig.json"; while (true) { @@ -29733,9 +29754,7 @@ var ts; } } } - var newLine = options.newLine === 0 /* CarriageReturnLineFeed */ ? carriageReturnLineFeed : - options.newLine === 1 /* LineFeed */ ? lineFeed : - ts.sys.newLine; + var newLine = ts.getNewLineCharacter(options); return { getSourceFile: getSourceFile, getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), ts.getDefaultLibFileName(options)); }, @@ -29803,6 +29822,7 @@ var ts; getGlobalDiagnostics: getGlobalDiagnostics, getSemanticDiagnostics: getSemanticDiagnostics, getDeclarationDiagnostics: getDeclarationDiagnostics, + getCompilerOptionsDiagnostics: getCompilerOptionsDiagnostics, getTypeChecker: getTypeChecker, getDiagnosticsProducingTypeChecker: getDiagnosticsProducingTypeChecker, getCommonSourceDirectory: function () { return commonSourceDirectory; }, @@ -29894,6 +29914,11 @@ var ts; return ts.getDeclarationDiagnostics(getEmitHost(writeFile), resolver, sourceFile); } } + function getCompilerOptionsDiagnostics() { + var allDiagnostics = []; + ts.addRange(allDiagnostics, diagnostics.getGlobalDiagnostics()); + return ts.sortAndDeduplicateDiagnostics(allDiagnostics); + } function getGlobalDiagnostics() { var typeChecker = getDiagnosticsProducingTypeChecker(); var allDiagnostics = []; @@ -36695,12 +36720,20 @@ var ts; * Extra compiler options that will unconditionally be used bu this function are: * - isolatedModules = true * - allowNonTsExtensions = true + * - noLib = true + * - noResolve = true */ function transpile(input, compilerOptions, fileName, diagnostics) { var options = compilerOptions ? ts.clone(compilerOptions) : getDefaultCompilerOptions(); options.isolatedModules = true; // Filename can be non-ts file. options.allowNonTsExtensions = true; + // We are not returning a sourceFile for lib file when asked by the program, + // so pass --noLib to avoid reporting a file not found error. + options.noLib = true; + // We are not doing a full typecheck, we are not resolving the whole context, + // so pass --noResolve to avoid reporting missing file errors. + options.noResolve = true; // Parse var inputFileName = fileName || "module.ts"; var sourceFile = ts.createSourceFile(inputFileName, input, options.target); @@ -36708,6 +36741,7 @@ var ts; if (diagnostics && sourceFile.parseDiagnostics) { diagnostics.push.apply(diagnostics, sourceFile.parseDiagnostics); } + var newLine = ts.getNewLineCharacter(options); // Output var outputText; // Create a compilerHost object to allow the compiler to read and write files @@ -36721,11 +36755,11 @@ var ts; useCaseSensitiveFileNames: function () { return false; }, getCanonicalFileName: function (fileName) { return fileName; }, getCurrentDirectory: function () { return ""; }, - getNewLine: function () { return (ts.sys && ts.sys.newLine) || "\r\n"; } + getNewLine: function () { return newLine; } }; var program = ts.createProgram([inputFileName], options, compilerHost); if (diagnostics) { - diagnostics.push.apply(diagnostics, program.getGlobalDiagnostics()); + diagnostics.push.apply(diagnostics, program.getCompilerOptionsDiagnostics()); } // Emit program.emit(); @@ -37328,12 +37362,16 @@ var ts; } } } + // hostCache is captured in the closure for 'getOrCreateSourceFile' but it should not be used past this point. + // It needs to be cleared to allow all collected snapshots to be released + hostCache = undefined; program = newProgram; // Make sure all the nodes in the program are both bound, and have their parent // pointers set property. program.getTypeChecker(); return; function getOrCreateSourceFile(fileName) { + ts.Debug.assert(hostCache !== undefined); // The program is asking for this file, check first if the host can locate it. // If the host can not locate the file, then it does not exist. return undefined // to the program to allow reporting of errors for missing files. diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js index dbede84a76e..dac610e2504 100644 --- a/bin/typescriptServices.js +++ b/bin/typescriptServices.js @@ -5793,6 +5793,21 @@ var ts; return result; } ts.convertToBase64 = convertToBase64; + var carriageReturnLineFeed = "\r\n"; + var lineFeed = "\n"; + function getNewLineCharacter(options) { + if (options.newLine === 0 /* CarriageReturnLineFeed */) { + return carriageReturnLineFeed; + } + else if (options.newLine === 1 /* LineFeed */) { + return lineFeed; + } + else if (ts.sys) { + return ts.sys.newLine; + } + return carriageReturnLineFeed; + } + ts.getNewLineCharacter = getNewLineCharacter; })(ts || (ts = {})); var ts; (function (ts) { @@ -17596,6 +17611,14 @@ var ts; checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } if (node.body) { + if (!node.type) { + // There are some checks that are only performed in getReturnTypeFromBody, that may produce errors + // we need. An example is the noImplicitAny errors resulting from widening the return expression + // of a function. Because checking of function expression bodies is deferred, there was never an + // appropriate time to do this during the main walk of the file (see the comment at the top of + // checkFunctionExpressionBodies). So it must be done now. + getReturnTypeOfSignature(getSignatureFromDeclaration(node)); + } if (node.body.kind === 180 /* Block */) { checkSourceElement(node.body); } @@ -29658,8 +29681,6 @@ var ts; /* @internal */ ts.ioWriteTime = 0; /** The version of the TypeScript compiler release */ ts.version = "1.5.3"; - var carriageReturnLineFeed = "\r\n"; - var lineFeed = "\n"; function findConfigFile(searchPath) { var fileName = "tsconfig.json"; while (true) { @@ -29733,9 +29754,7 @@ var ts; } } } - var newLine = options.newLine === 0 /* CarriageReturnLineFeed */ ? carriageReturnLineFeed : - options.newLine === 1 /* LineFeed */ ? lineFeed : - ts.sys.newLine; + var newLine = ts.getNewLineCharacter(options); return { getSourceFile: getSourceFile, getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), ts.getDefaultLibFileName(options)); }, @@ -29803,6 +29822,7 @@ var ts; getGlobalDiagnostics: getGlobalDiagnostics, getSemanticDiagnostics: getSemanticDiagnostics, getDeclarationDiagnostics: getDeclarationDiagnostics, + getCompilerOptionsDiagnostics: getCompilerOptionsDiagnostics, getTypeChecker: getTypeChecker, getDiagnosticsProducingTypeChecker: getDiagnosticsProducingTypeChecker, getCommonSourceDirectory: function () { return commonSourceDirectory; }, @@ -29894,6 +29914,11 @@ var ts; return ts.getDeclarationDiagnostics(getEmitHost(writeFile), resolver, sourceFile); } } + function getCompilerOptionsDiagnostics() { + var allDiagnostics = []; + ts.addRange(allDiagnostics, diagnostics.getGlobalDiagnostics()); + return ts.sortAndDeduplicateDiagnostics(allDiagnostics); + } function getGlobalDiagnostics() { var typeChecker = getDiagnosticsProducingTypeChecker(); var allDiagnostics = []; @@ -36695,12 +36720,20 @@ var ts; * Extra compiler options that will unconditionally be used bu this function are: * - isolatedModules = true * - allowNonTsExtensions = true + * - noLib = true + * - noResolve = true */ function transpile(input, compilerOptions, fileName, diagnostics) { var options = compilerOptions ? ts.clone(compilerOptions) : getDefaultCompilerOptions(); options.isolatedModules = true; // Filename can be non-ts file. options.allowNonTsExtensions = true; + // We are not returning a sourceFile for lib file when asked by the program, + // so pass --noLib to avoid reporting a file not found error. + options.noLib = true; + // We are not doing a full typecheck, we are not resolving the whole context, + // so pass --noResolve to avoid reporting missing file errors. + options.noResolve = true; // Parse var inputFileName = fileName || "module.ts"; var sourceFile = ts.createSourceFile(inputFileName, input, options.target); @@ -36708,6 +36741,7 @@ var ts; if (diagnostics && sourceFile.parseDiagnostics) { diagnostics.push.apply(diagnostics, sourceFile.parseDiagnostics); } + var newLine = ts.getNewLineCharacter(options); // Output var outputText; // Create a compilerHost object to allow the compiler to read and write files @@ -36721,11 +36755,11 @@ var ts; useCaseSensitiveFileNames: function () { return false; }, getCanonicalFileName: function (fileName) { return fileName; }, getCurrentDirectory: function () { return ""; }, - getNewLine: function () { return (ts.sys && ts.sys.newLine) || "\r\n"; } + getNewLine: function () { return newLine; } }; var program = ts.createProgram([inputFileName], options, compilerHost); if (diagnostics) { - diagnostics.push.apply(diagnostics, program.getGlobalDiagnostics()); + diagnostics.push.apply(diagnostics, program.getCompilerOptionsDiagnostics()); } // Emit program.emit(); @@ -37328,12 +37362,16 @@ var ts; } } } + // hostCache is captured in the closure for 'getOrCreateSourceFile' but it should not be used past this point. + // It needs to be cleared to allow all collected snapshots to be released + hostCache = undefined; program = newProgram; // Make sure all the nodes in the program are both bound, and have their parent // pointers set property. program.getTypeChecker(); return; function getOrCreateSourceFile(fileName) { + ts.Debug.assert(hostCache !== undefined); // The program is asking for this file, check first if the host can locate it. // If the host can not locate the file, then it does not exist. return undefined // to the program to allow reporting of errors for missing files. From 269ae3ab995847d0e0db00d546486cfbfbf24ff7 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 3 Jun 2015 13:48:34 -0700 Subject: [PATCH 18/26] introduce FileMap to store mappings with filenames as keys --- src/compiler/core.ts | 32 +++++++++++++++++++++++ src/compiler/program.ts | 17 ++++++------ src/services/services.ts | 56 +++++++++++++++++++++------------------- src/services/shims.ts | 10 ++++++- 4 files changed, 80 insertions(+), 35 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 281bfa36ece..b798bd8771d 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -15,6 +15,38 @@ module ts { True = -1 } + export class FileMap { + private files: Map = {}; + + constructor(private getCanonicalFileName: (fileName: string) => string) { + } + + public set(fileName: string, value: T) { + this.files[this.normalizeKey(fileName)] = value; + } + + public get(fileName: string) { + return this.files[this.normalizeKey(fileName)]; + } + + public contains(fileName: string) { + return hasProperty(this.files, this.normalizeKey(fileName)); + } + + public delete(fileName: string) { + let key = this.normalizeKey(fileName); + delete this.files[key]; + } + + public forEachValue(f: (value: T) => void) { + forEachValue(this.files, f); + } + + private normalizeKey(key: string) { + return this.getCanonicalFileName(normalizeSlashes(key)); + } + } + export const enum Comparison { LessThan = -1, EqualTo = 0, diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 955e24fd1de..dd693b55907 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -149,7 +149,6 @@ module ts { export function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program { let program: Program; let files: SourceFile[] = []; - let filesByName: Map = {}; let diagnostics = createDiagnosticCollection(); let seenNoDefaultLib = options.noLib; let commonSourceDirectory: string; @@ -159,6 +158,8 @@ module ts { let start = new Date().getTime(); host = host || createCompilerHost(options); + let filesByName: FileMap = new FileMap(host.getCanonicalFileName); + forEach(rootNames, name => processRootFile(name, false)); if (!seenNoDefaultLib) { processRootFile(host.getDefaultLibFileName(options), true); @@ -238,8 +239,7 @@ module ts { } function getSourceFile(fileName: string) { - fileName = host.getCanonicalFileName(normalizeSlashes(fileName)); - return hasProperty(filesByName, fileName) ? filesByName[fileName] : undefined; + return filesByName.get(fileName); } function getDiagnosticsHelper(sourceFile: SourceFile, getDiagnostics: (sourceFile: SourceFile) => Diagnostic[]): Diagnostic[] { @@ -358,19 +358,19 @@ module ts { // Get source file from normalized fileName function findSourceFile(fileName: string, isDefaultLib: boolean, refFile?: SourceFile, refStart?: number, refLength?: number): SourceFile { let canonicalName = host.getCanonicalFileName(normalizeSlashes(fileName)); - if (hasProperty(filesByName, canonicalName)) { + if (filesByName.contains(canonicalName)) { // We've already looked for this file, use cached result return getSourceFileFromCache(fileName, canonicalName, /*useAbsolutePath*/ false); } else { let normalizedAbsolutePath = getNormalizedAbsolutePath(fileName, host.getCurrentDirectory()); let canonicalAbsolutePath = host.getCanonicalFileName(normalizedAbsolutePath); - if (hasProperty(filesByName, canonicalAbsolutePath)) { + if (filesByName.contains(canonicalAbsolutePath)) { return getSourceFileFromCache(normalizedAbsolutePath, canonicalAbsolutePath, /*useAbsolutePath*/ true); } // We haven't looked for this file, do so now and cache result - let file = filesByName[canonicalName] = host.getSourceFile(fileName, options.target, hostErrorMessage => { + let file = host.getSourceFile(fileName, options.target, hostErrorMessage => { if (refFile) { diagnostics.add(createFileDiagnostic(refFile, refStart, refLength, Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); @@ -379,11 +379,12 @@ module ts { diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } }); + filesByName.set(canonicalName, file); if (file) { seenNoDefaultLib = seenNoDefaultLib || file.hasNoDefaultLib; // Set the source file for normalized absolute path - filesByName[canonicalAbsolutePath] = file; + filesByName.set(canonicalAbsolutePath, file); if (!options.noResolve) { let basePath = getDirectoryPath(fileName); @@ -402,7 +403,7 @@ module ts { } function getSourceFileFromCache(fileName: string, canonicalName: string, useAbsolutePath: boolean): SourceFile { - let file = filesByName[canonicalName]; + let file = filesByName.get(canonicalName); if (file && host.useCaseSensitiveFileNames()) { let sourceFileName = useAbsolutePath ? getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName; if (canonicalName !== sourceFileName) { diff --git a/src/services/services.ts b/src/services/services.ts index 400bf754a00..908d9efbaca 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -960,6 +960,7 @@ module ts { log? (s: string): void; trace? (s: string): void; error? (s: string): void; + useCaseSensitiveFileNames? (): boolean; } // @@ -1632,12 +1633,12 @@ module ts { // at each language service public entry point, since we don't know when // set of scripts handled by the host changes. class HostCache { - private fileNameToEntry: Map; + private fileNameToEntry: FileMap; private _compilationSettings: CompilerOptions; - constructor(private host: LanguageServiceHost, private getCanonicalFileName: (fileName: string) => string) { + constructor(private host: LanguageServiceHost, getCanonicalFileName: (fileName: string) => string) { // script id => script index - this.fileNameToEntry = {}; + this.fileNameToEntry = new FileMap(getCanonicalFileName); // Initialize the list with the root file names let rootFileNames = host.getScriptFileNames(); @@ -1653,10 +1654,6 @@ module ts { return this._compilationSettings; } - private normalizeFileName(fileName: string): string { - return this.getCanonicalFileName(normalizeSlashes(fileName)); - } - private createEntry(fileName: string) { let entry: HostFileInformation; let scriptSnapshot = this.host.getScriptSnapshot(fileName); @@ -1668,15 +1665,16 @@ module ts { }; } - return this.fileNameToEntry[this.normalizeFileName(fileName)] = entry; + this.fileNameToEntry.set(fileName, entry); + return entry; } private getEntry(fileName: string): HostFileInformation { - return lookUp(this.fileNameToEntry, this.normalizeFileName(fileName)); + return this.fileNameToEntry.get(fileName); } private contains(fileName: string): boolean { - return hasProperty(this.fileNameToEntry, this.normalizeFileName(fileName)); + return this.fileNameToEntry.contains(fileName); } public getOrCreateEntry(fileName: string): HostFileInformation { @@ -1690,10 +1688,9 @@ module ts { public getRootFileNames(): string[] { let fileNames: string[] = []; - forEachKey(this.fileNameToEntry, key => { - let entry = this.getEntry(key); - if (entry) { - fileNames.push(entry.hostFileName); + this.fileNameToEntry.forEachValue(value => { + if (value) { + fileNames.push(value.hostFileName); } }); @@ -1873,20 +1870,28 @@ module ts { return createLanguageServiceSourceFile(sourceFile.fileName, scriptSnapshot, sourceFile.languageVersion, version, /*setNodeParents:*/ true); } - export function createDocumentRegistry(): DocumentRegistry { + function createGetCanonicalFileName(useCaseSensitivefileNames: boolean): (fileName: string) => string { + return useCaseSensitivefileNames + ? ((fileName) => fileName) + : ((fileName) => fileName.toLowerCase()); + } + + + export function createDocumentRegistry(useCaseSensitiveFileNames?: boolean): DocumentRegistry { // Maps from compiler setting target (ES3, ES5, etc.) to all the cached documents we have // for those settings. - let buckets: Map> = {}; + let buckets: Map> = {}; + let getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames || false); function getKeyFromCompilationSettings(settings: CompilerOptions): string { return "_" + settings.target; // + "|" + settings.propagateEnumConstantoString() } - function getBucketForCompilationSettings(settings: CompilerOptions, createIfMissing: boolean): Map { + function getBucketForCompilationSettings(settings: CompilerOptions, createIfMissing: boolean): FileMap { let key = getKeyFromCompilationSettings(settings); let bucket = lookUp(buckets, key); if (!bucket && createIfMissing) { - buckets[key] = bucket = {}; + buckets[key] = bucket = new FileMap(getCanonicalFileName); } return bucket; } @@ -1896,7 +1901,7 @@ module ts { let entries = lookUp(buckets, name); let sourceFiles: { name: string; refCount: number; references: string[]; }[] = []; for (let i in entries) { - let entry = entries[i]; + let entry = entries.get(i); sourceFiles.push({ name: i, refCount: entry.languageServiceRefCount, @@ -1928,18 +1933,19 @@ module ts { acquiring: boolean): SourceFile { let bucket = getBucketForCompilationSettings(compilationSettings, /*createIfMissing*/ true); - let entry = lookUp(bucket, fileName); + let entry = bucket.get(fileName); if (!entry) { Debug.assert(acquiring, "How could we be trying to update a document that the registry doesn't have?"); // Have never seen this file with these settings. Create a new source file for it. let sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, compilationSettings.target, version, /*setNodeParents:*/ false); - bucket[fileName] = entry = { + entry = { sourceFile: sourceFile, languageServiceRefCount: 0, owners: [] }; + bucket.set(fileName, entry); } else { // We have an entry for this file. However, it may be for a different version of @@ -1967,12 +1973,12 @@ module ts { let bucket = getBucketForCompilationSettings(compilationSettings, false); Debug.assert(bucket !== undefined); - let entry = lookUp(bucket, fileName); + let entry = bucket.get(fileName); entry.languageServiceRefCount--; Debug.assert(entry.languageServiceRefCount >= 0); if (entry.languageServiceRefCount === 0) { - delete bucket[fileName]; + bucket.delete(fileName); } } @@ -2400,9 +2406,7 @@ module ts { } } - function getCanonicalFileName(fileName: string) { - return useCaseSensitivefileNames ? fileName : fileName.toLowerCase(); - } + let getCanonicalFileName = createGetCanonicalFileName(useCaseSensitivefileNames); function getValidSourceFile(fileName: string): SourceFile { fileName = normalizeSlashes(fileName); diff --git a/src/services/shims.ts b/src/services/shims.ts index d3f59737538..4dfab444cde 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -56,6 +56,7 @@ module ts { getDefaultLibFileName(options: string): string; getNewLine?(): string; getProjectVersion?(): string; + useCaseSensitiveFileNames?(): boolean; } /** Public interface of the the of a config service shim instance.*/ @@ -270,6 +271,10 @@ module ts { return this.shimHost.getProjectVersion(); } + public useCaseSensitiveFileNames(): boolean { + return this.shimHost.useCaseSensitiveFileNames && this.useCaseSensitiveFileNames(); + } + public getCompilationSettings(): CompilerOptions { var settingsJson = this.shimHost.getCompilationSettings(); if (settingsJson == null || settingsJson == "") { @@ -909,7 +914,7 @@ module ts { export class TypeScriptServicesFactory implements ShimFactory { private _shims: Shim[] = []; - private documentRegistry: DocumentRegistry = createDocumentRegistry(); + private documentRegistry: DocumentRegistry; /* * Returns script API version. @@ -920,6 +925,9 @@ module ts { public createLanguageServiceShim(host: LanguageServiceShimHost): LanguageServiceShim { try { + if (this.documentRegistry === undefined) { + this.documentRegistry = createDocumentRegistry(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames()); + } var hostAdapter = new LanguageServiceShimHostAdapter(host); var languageService = createLanguageService(hostAdapter, this.documentRegistry); return new LanguageServiceShimObject(this, host, languageService); From ef54047a65c963201d972bccec5d5e08d53f6091 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 3 Jun 2015 15:22:17 -0700 Subject: [PATCH 19/26] address PR feedback --- src/compiler/core.ts | 38 +++++++++++++++++++++----------------- src/compiler/program.ts | 2 +- src/compiler/types.ts | 8 ++++++++ src/services/services.ts | 6 +++--- src/services/shims.ts | 2 +- 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index b798bd8771d..ed9647970c0 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -15,35 +15,39 @@ module ts { True = -1 } - export class FileMap { - private files: Map = {}; - - constructor(private getCanonicalFileName: (fileName: string) => string) { + export function createFileMap(getCanonicalFileName: (fileName: string) => string): FileMap { + let files: Map = {}; + return { + get, + set, + contains, + delete: deleteItem, + forEachValue: forEachValueInMap } - public set(fileName: string, value: T) { - this.files[this.normalizeKey(fileName)] = value; + function set(fileName: string, value: T) { + files[normalizeKey(fileName)] = value; } - public get(fileName: string) { - return this.files[this.normalizeKey(fileName)]; + function get(fileName: string) { + return files[normalizeKey(fileName)]; } - public contains(fileName: string) { - return hasProperty(this.files, this.normalizeKey(fileName)); + function contains(fileName: string) { + return hasProperty(files, normalizeKey(fileName)); } - public delete(fileName: string) { - let key = this.normalizeKey(fileName); - delete this.files[key]; + function deleteItem (fileName: string) { + let key = normalizeKey(fileName); + delete files[key]; } - public forEachValue(f: (value: T) => void) { - forEachValue(this.files, f); + function forEachValueInMap(f: (value: T) => void) { + forEachValue(files, f); } - private normalizeKey(key: string) { - return this.getCanonicalFileName(normalizeSlashes(key)); + function normalizeKey(key: string) { + return getCanonicalFileName(normalizeSlashes(key)); } } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index dd693b55907..74c0ac7fefb 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -158,7 +158,7 @@ module ts { let start = new Date().getTime(); host = host || createCompilerHost(options); - let filesByName: FileMap = new FileMap(host.getCanonicalFileName); + let filesByName = createFileMap(host.getCanonicalFileName); forEach(rootNames, name => processRootFile(name, false)); if (!seenNoDefaultLib) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 0fcf0e1f67a..638dd0b79ec 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3,6 +3,14 @@ module ts { [index: string]: T; } + export interface FileMap { + get(fileName: string): T; + set(fileName: string, value: T): void; + contains(fileName: string): boolean; + delete(fileName: string): void; + forEachValue(f: (v: T) => void): void; + } + export interface TextRange { pos: number; end: number; diff --git a/src/services/services.ts b/src/services/services.ts index 908d9efbaca..f2aa6dfee7f 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1638,7 +1638,7 @@ module ts { constructor(private host: LanguageServiceHost, getCanonicalFileName: (fileName: string) => string) { // script id => script index - this.fileNameToEntry = new FileMap(getCanonicalFileName); + this.fileNameToEntry = createFileMap(getCanonicalFileName); // Initialize the list with the root file names let rootFileNames = host.getScriptFileNames(); @@ -1881,7 +1881,7 @@ module ts { // Maps from compiler setting target (ES3, ES5, etc.) to all the cached documents we have // for those settings. let buckets: Map> = {}; - let getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames || false); + let getCanonicalFileName = createGetCanonicalFileName(!!useCaseSensitiveFileNames); function getKeyFromCompilationSettings(settings: CompilerOptions): string { return "_" + settings.target; // + "|" + settings.propagateEnumConstantoString() @@ -1891,7 +1891,7 @@ module ts { let key = getKeyFromCompilationSettings(settings); let bucket = lookUp(buckets, key); if (!bucket && createIfMissing) { - buckets[key] = bucket = new FileMap(getCanonicalFileName); + buckets[key] = bucket = createFileMap(getCanonicalFileName); } return bucket; } diff --git a/src/services/shims.ts b/src/services/shims.ts index 4dfab444cde..004393fb3b5 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -272,7 +272,7 @@ module ts { } public useCaseSensitiveFileNames(): boolean { - return this.shimHost.useCaseSensitiveFileNames && this.useCaseSensitiveFileNames(); + return this.shimHost.useCaseSensitiveFileNames ? this.shimHost.useCaseSensitiveFileNames() : false; } public getCompilationSettings(): CompilerOptions { From 4ccf088734ad929f347a29ad0962830116ca575f Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 3 Jun 2015 17:22:11 -0700 Subject: [PATCH 20/26] Don't try to strip parentheses when emitting synthesized parenthesized expressions --- src/compiler/emitter.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 028a65ddfa1..5a0db87d409 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1644,6 +1644,13 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { } function parenthesizeForAccess(expr: Expression): LeftHandSideExpression { + // When diagnosing whether the expression needs parentheses, the decision should be based + // on the innermost expression in a chain of nested type assertions. + let innerExpression = expr; + while (innerExpression.kind === SyntaxKind.TypeAssertionExpression) { + innerExpression = (innerExpression).expression; + } + // isLeftHandSideExpression is almost the correct criterion for when it is not necessary // to parenthesize the expression before a dot. The known exceptions are: // @@ -1652,7 +1659,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { // NumberLiteral // 1.x -> not the same as (1).x // - if (isLeftHandSideExpression(expr) && expr.kind !== SyntaxKind.NewExpression && expr.kind !== SyntaxKind.NumericLiteral) { + if (isLeftHandSideExpression(innerExpression) && + innerExpression.kind !== SyntaxKind.NewExpression && + innerExpression.kind !== SyntaxKind.NumericLiteral) { + return expr; } let node = createSynthesizedNode(SyntaxKind.ParenthesizedExpression); @@ -1906,7 +1916,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { } function emitParenExpression(node: ParenthesizedExpression) { - if (!node.parent || node.parent.kind !== SyntaxKind.ArrowFunction) { + // If the node is synthesized, it means the emitter put the parentheses there, + // not the user. If we didn't want them, the emitter would not have put them + // there. + if (!nodeIsSynthesized(node) && node.parent.kind !== SyntaxKind.ArrowFunction) { if (node.expression.kind === SyntaxKind.TypeAssertionExpression) { let operand = (node.expression).expression; From 7a74d9f8d021f50201765d2170af8d249af90320 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 3 Jun 2015 17:22:38 -0700 Subject: [PATCH 21/26] Add tests for parenthesized type assertions --- .../es6/destructuring/destructuringTypeAssertionsES5_1.ts | 2 ++ .../es6/destructuring/destructuringTypeAssertionsES5_2.ts | 2 ++ .../es6/destructuring/destructuringTypeAssertionsES5_3.ts | 2 ++ .../es6/destructuring/destructuringTypeAssertionsES5_4.ts | 2 ++ .../es6/destructuring/destructuringTypeAssertionsES5_5.ts | 2 ++ .../es6/destructuring/destructuringTypeAssertionsES5_6.ts | 2 ++ .../es6/destructuring/destructuringTypeAssertionsES5_7.ts | 2 ++ 7 files changed, 14 insertions(+) create mode 100644 tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_1.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_2.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_3.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_4.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_5.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_6.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_7.ts diff --git a/tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_1.ts b/tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_1.ts new file mode 100644 index 00000000000..7be8ce1dc12 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_1.ts @@ -0,0 +1,2 @@ +//@target: ES5 +var { x } = foo(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_2.ts b/tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_2.ts new file mode 100644 index 00000000000..7c4e084796a --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_2.ts @@ -0,0 +1,2 @@ +//@target: ES5 +var { x } = (foo()); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_3.ts b/tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_3.ts new file mode 100644 index 00000000000..30386fe9f86 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_3.ts @@ -0,0 +1,2 @@ +//@target: ES5 +var { x } = (foo()); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_4.ts b/tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_4.ts new file mode 100644 index 00000000000..84f251c205b --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_4.ts @@ -0,0 +1,2 @@ +//@target: ES5 +var { x } = foo(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_5.ts b/tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_5.ts new file mode 100644 index 00000000000..927a53883d3 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_5.ts @@ -0,0 +1,2 @@ +//@target: ES5 +var { x } = 0; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_6.ts b/tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_6.ts new file mode 100644 index 00000000000..2097a8ec760 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_6.ts @@ -0,0 +1,2 @@ +//@target: ES5 +var { x } = new Foo; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_7.ts b/tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_7.ts new file mode 100644 index 00000000000..d11381dc088 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_7.ts @@ -0,0 +1,2 @@ +//@target: ES5 +var { x } = new Foo; \ No newline at end of file From 26cf97430e6f2cec2141155f61edfafe8ed49b42 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 3 Jun 2015 17:22:51 -0700 Subject: [PATCH 22/26] Accept baselines for parenthesized type assertions --- .../reference/destructuringTypeAssertionsES5_1.errors.txt | 7 +++++++ .../reference/destructuringTypeAssertionsES5_1.js | 5 +++++ .../reference/destructuringTypeAssertionsES5_2.errors.txt | 7 +++++++ .../reference/destructuringTypeAssertionsES5_2.js | 5 +++++ .../reference/destructuringTypeAssertionsES5_3.errors.txt | 7 +++++++ .../reference/destructuringTypeAssertionsES5_3.js | 5 +++++ .../reference/destructuringTypeAssertionsES5_4.errors.txt | 7 +++++++ .../reference/destructuringTypeAssertionsES5_4.js | 5 +++++ .../reference/destructuringTypeAssertionsES5_5.js | 5 +++++ .../reference/destructuringTypeAssertionsES5_5.symbols | 4 ++++ .../reference/destructuringTypeAssertionsES5_5.types | 6 ++++++ .../reference/destructuringTypeAssertionsES5_6.errors.txt | 7 +++++++ .../reference/destructuringTypeAssertionsES5_6.js | 5 +++++ .../reference/destructuringTypeAssertionsES5_7.errors.txt | 7 +++++++ .../reference/destructuringTypeAssertionsES5_7.js | 5 +++++ 15 files changed, 87 insertions(+) create mode 100644 tests/baselines/reference/destructuringTypeAssertionsES5_1.errors.txt create mode 100644 tests/baselines/reference/destructuringTypeAssertionsES5_1.js create mode 100644 tests/baselines/reference/destructuringTypeAssertionsES5_2.errors.txt create mode 100644 tests/baselines/reference/destructuringTypeAssertionsES5_2.js create mode 100644 tests/baselines/reference/destructuringTypeAssertionsES5_3.errors.txt create mode 100644 tests/baselines/reference/destructuringTypeAssertionsES5_3.js create mode 100644 tests/baselines/reference/destructuringTypeAssertionsES5_4.errors.txt create mode 100644 tests/baselines/reference/destructuringTypeAssertionsES5_4.js create mode 100644 tests/baselines/reference/destructuringTypeAssertionsES5_5.js create mode 100644 tests/baselines/reference/destructuringTypeAssertionsES5_5.symbols create mode 100644 tests/baselines/reference/destructuringTypeAssertionsES5_5.types create mode 100644 tests/baselines/reference/destructuringTypeAssertionsES5_6.errors.txt create mode 100644 tests/baselines/reference/destructuringTypeAssertionsES5_6.js create mode 100644 tests/baselines/reference/destructuringTypeAssertionsES5_7.errors.txt create mode 100644 tests/baselines/reference/destructuringTypeAssertionsES5_7.js diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_1.errors.txt b/tests/baselines/reference/destructuringTypeAssertionsES5_1.errors.txt new file mode 100644 index 00000000000..187c1d33f3d --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_1.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_1.ts(1,18): error TS2304: Cannot find name 'foo'. + + +==== tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_1.ts (1 errors) ==== + var { x } = foo(); + ~~~ +!!! error TS2304: Cannot find name 'foo'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_1.js b/tests/baselines/reference/destructuringTypeAssertionsES5_1.js new file mode 100644 index 00000000000..296cad051b1 --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_1.js @@ -0,0 +1,5 @@ +//// [destructuringTypeAssertionsES5_1.ts] +var { x } = foo(); + +//// [destructuringTypeAssertionsES5_1.js] +var x = foo().x; diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_2.errors.txt b/tests/baselines/reference/destructuringTypeAssertionsES5_2.errors.txt new file mode 100644 index 00000000000..2036653820b --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_2.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_2.ts(1,19): error TS2304: Cannot find name 'foo'. + + +==== tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_2.ts (1 errors) ==== + var { x } = (foo()); + ~~~ +!!! error TS2304: Cannot find name 'foo'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_2.js b/tests/baselines/reference/destructuringTypeAssertionsES5_2.js new file mode 100644 index 00000000000..1725b7042ec --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_2.js @@ -0,0 +1,5 @@ +//// [destructuringTypeAssertionsES5_2.ts] +var { x } = (foo()); + +//// [destructuringTypeAssertionsES5_2.js] +var x = foo().x; diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_3.errors.txt b/tests/baselines/reference/destructuringTypeAssertionsES5_3.errors.txt new file mode 100644 index 00000000000..a3aef8b91ea --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_3.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_3.ts(1,19): error TS2304: Cannot find name 'foo'. + + +==== tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_3.ts (1 errors) ==== + var { x } = (foo()); + ~~~ +!!! error TS2304: Cannot find name 'foo'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_3.js b/tests/baselines/reference/destructuringTypeAssertionsES5_3.js new file mode 100644 index 00000000000..1c8b8b1e5d8 --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_3.js @@ -0,0 +1,5 @@ +//// [destructuringTypeAssertionsES5_3.ts] +var { x } = (foo()); + +//// [destructuringTypeAssertionsES5_3.js] +var x = (foo()).x; diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_4.errors.txt b/tests/baselines/reference/destructuringTypeAssertionsES5_4.errors.txt new file mode 100644 index 00000000000..a27afe42f3c --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_4.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_4.ts(1,23): error TS2304: Cannot find name 'foo'. + + +==== tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_4.ts (1 errors) ==== + var { x } = foo(); + ~~~ +!!! error TS2304: Cannot find name 'foo'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_4.js b/tests/baselines/reference/destructuringTypeAssertionsES5_4.js new file mode 100644 index 00000000000..66a3e89c9b0 --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_4.js @@ -0,0 +1,5 @@ +//// [destructuringTypeAssertionsES5_4.ts] +var { x } = foo(); + +//// [destructuringTypeAssertionsES5_4.js] +var x = foo().x; diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_5.js b/tests/baselines/reference/destructuringTypeAssertionsES5_5.js new file mode 100644 index 00000000000..a51ac02af77 --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_5.js @@ -0,0 +1,5 @@ +//// [destructuringTypeAssertionsES5_5.ts] +var { x } = 0; + +//// [destructuringTypeAssertionsES5_5.js] +var x = (0).x; diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_5.symbols b/tests/baselines/reference/destructuringTypeAssertionsES5_5.symbols new file mode 100644 index 00000000000..d8e335f3e73 --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_5.symbols @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_5.ts === +var { x } = 0; +>x : Symbol(x, Decl(destructuringTypeAssertionsES5_5.ts, 0, 5)) + diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_5.types b/tests/baselines/reference/destructuringTypeAssertionsES5_5.types new file mode 100644 index 00000000000..a7111cc4361 --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_5.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_5.ts === +var { x } = 0; +>x : any +>0 : any +>0 : number + diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_6.errors.txt b/tests/baselines/reference/destructuringTypeAssertionsES5_6.errors.txt new file mode 100644 index 00000000000..9a27c4f47ab --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_6.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_6.ts(1,22): error TS2304: Cannot find name 'Foo'. + + +==== tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_6.ts (1 errors) ==== + var { x } = new Foo; + ~~~ +!!! error TS2304: Cannot find name 'Foo'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_6.js b/tests/baselines/reference/destructuringTypeAssertionsES5_6.js new file mode 100644 index 00000000000..01fd78f44e9 --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_6.js @@ -0,0 +1,5 @@ +//// [destructuringTypeAssertionsES5_6.ts] +var { x } = new Foo; + +//// [destructuringTypeAssertionsES5_6.js] +var x = (new Foo).x; diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_7.errors.txt b/tests/baselines/reference/destructuringTypeAssertionsES5_7.errors.txt new file mode 100644 index 00000000000..984f6a1dbb4 --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_7.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_7.ts(1,27): error TS2304: Cannot find name 'Foo'. + + +==== tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_7.ts (1 errors) ==== + var { x } = new Foo; + ~~~ +!!! error TS2304: Cannot find name 'Foo'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_7.js b/tests/baselines/reference/destructuringTypeAssertionsES5_7.js new file mode 100644 index 00000000000..78492eefc28 --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_7.js @@ -0,0 +1,5 @@ +//// [destructuringTypeAssertionsES5_7.ts] +var { x } = new Foo; + +//// [destructuringTypeAssertionsES5_7.js] +var x = (new Foo).x; From e940fdc534f0c8de8794274a84264efe67299c57 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 3 Jun 2015 17:34:56 -0700 Subject: [PATCH 23/26] Don't use innerExpression in parenthesizeForAccess --- src/compiler/emitter.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 5a0db87d409..bf0aef74455 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1646,9 +1646,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { function parenthesizeForAccess(expr: Expression): LeftHandSideExpression { // When diagnosing whether the expression needs parentheses, the decision should be based // on the innermost expression in a chain of nested type assertions. - let innerExpression = expr; - while (innerExpression.kind === SyntaxKind.TypeAssertionExpression) { - innerExpression = (innerExpression).expression; + while (expr.kind === SyntaxKind.TypeAssertionExpression) { + expr = (expr).expression; } // isLeftHandSideExpression is almost the correct criterion for when it is not necessary @@ -1659,9 +1658,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { // NumberLiteral // 1.x -> not the same as (1).x // - if (isLeftHandSideExpression(innerExpression) && - innerExpression.kind !== SyntaxKind.NewExpression && - innerExpression.kind !== SyntaxKind.NumericLiteral) { + if (isLeftHandSideExpression(expr) && + expr.kind !== SyntaxKind.NewExpression && + expr.kind !== SyntaxKind.NumericLiteral) { return expr; } From 76076794c55ff0446ca379996ae4684a97377843 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 3 Jun 2015 18:01:54 -0700 Subject: [PATCH 24/26] Update LKG after merging release-1.5 --- bin/lib.d.ts | 20 +- bin/lib.dom.d.ts | 21 +- bin/lib.es6.d.ts | 20 +- bin/tsc.js | 629 +++++++++++++++--------------- bin/tsserver.js | 673 ++++++++++++++++---------------- bin/typescript.d.ts | 9 +- bin/typescript.js | 749 +++++++++++++++++++----------------- bin/typescriptServices.d.ts | 9 +- bin/typescriptServices.js | 749 +++++++++++++++++++----------------- 9 files changed, 1508 insertions(+), 1371 deletions(-) diff --git a/bin/lib.d.ts b/bin/lib.d.ts index 7497c306161..0e1176377b5 100644 --- a/bin/lib.d.ts +++ b/bin/lib.d.ts @@ -11335,10 +11335,10 @@ declare var MediaQueryList: { interface MediaSource extends EventTarget { activeSourceBuffers: SourceBufferList; duration: number; - readyState: string; + readyState: number; sourceBuffers: SourceBufferList; addSourceBuffer(type: string): SourceBuffer; - endOfStream(error?: string): void; + endOfStream(error?: number): void; removeSourceBuffer(sourceBuffer: SourceBuffer): void; } @@ -12067,7 +12067,7 @@ declare var PopStateEvent: { interface Position { coords: Coordinates; - timestamp: Date; + timestamp: number; } declare var Position: { @@ -14748,9 +14748,17 @@ interface WebGLRenderingContext { stencilMaskSeparate(face: number, mask: number): void; stencilOp(fail: number, zfail: number, zpass: number): void; stencilOpSeparate(face: number, fail: number, zfail: number, zpass: number): void; + texImage2D(target: number, level: number, internalformat: number, width: number, height: number, border: number, format: number, type: number, pixels: ArrayBufferView): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, image: HTMLImageElement): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, canvas: HTMLCanvasElement): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, video: HTMLVideoElement): void; texImage2D(target: number, level: number, internalformat: number, format: number, type: number, pixels: ImageData): void; texParameterf(target: number, pname: number, param: number): void; texParameteri(target: number, pname: number, param: number): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, width: number, height: number, format: number, type: number, pixels: ArrayBufferView): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, image: HTMLImageElement): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, canvas: HTMLCanvasElement): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, video: HTMLVideoElement): void; texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, pixels: ImageData): void; uniform1f(location: WebGLUniformLocation, x: number): void; uniform1fv(location: WebGLUniformLocation, v: any): void; @@ -15990,10 +15998,11 @@ interface DocumentEvent { createEvent(eventInterface:"AriaRequestEvent"): AriaRequestEvent; createEvent(eventInterface:"AudioProcessingEvent"): AudioProcessingEvent; createEvent(eventInterface:"BeforeUnloadEvent"): BeforeUnloadEvent; + createEvent(eventInterface:"ClipboardEvent"): ClipboardEvent; createEvent(eventInterface:"CloseEvent"): CloseEvent; createEvent(eventInterface:"CommandEvent"): CommandEvent; createEvent(eventInterface:"CompositionEvent"): CompositionEvent; - createEvent(eventInterface: "CustomEvent"): CustomEvent; + createEvent(eventInterface:"CustomEvent"): CustomEvent; createEvent(eventInterface:"DeviceMotionEvent"): DeviceMotionEvent; createEvent(eventInterface:"DeviceOrientationEvent"): DeviceOrientationEvent; createEvent(eventInterface:"DragEvent"): DragEvent; @@ -16016,8 +16025,6 @@ interface DocumentEvent { createEvent(eventInterface:"MouseEvent"): MouseEvent; createEvent(eventInterface:"MouseEvents"): MouseEvent; createEvent(eventInterface:"MouseWheelEvent"): MouseWheelEvent; - createEvent(eventInterface:"MSGestureEvent"): MSGestureEvent; - createEvent(eventInterface:"MSPointerEvent"): MSPointerEvent; createEvent(eventInterface:"MutationEvent"): MutationEvent; createEvent(eventInterface:"MutationEvents"): MutationEvent; createEvent(eventInterface:"NavigationCompletedEvent"): NavigationCompletedEvent; @@ -16630,6 +16637,7 @@ declare function addEventListener(type: "volumechange", listener: (ev: Event) => declare function addEventListener(type: "waiting", listener: (ev: Event) => any, useCapture?: boolean): void; declare function addEventListener(type: "wheel", listener: (ev: WheelEvent) => any, useCapture?: boolean): void; declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; + ///////////////////////////// /// WorkerGlobalScope APIs ///////////////////////////// diff --git a/bin/lib.dom.d.ts b/bin/lib.dom.d.ts index 1df0e2f736c..7638f0fba4c 100644 --- a/bin/lib.dom.d.ts +++ b/bin/lib.dom.d.ts @@ -10165,10 +10165,10 @@ declare var MediaQueryList: { interface MediaSource extends EventTarget { activeSourceBuffers: SourceBufferList; duration: number; - readyState: string; + readyState: number; sourceBuffers: SourceBufferList; addSourceBuffer(type: string): SourceBuffer; - endOfStream(error?: string): void; + endOfStream(error?: number): void; removeSourceBuffer(sourceBuffer: SourceBuffer): void; } @@ -10897,7 +10897,7 @@ declare var PopStateEvent: { interface Position { coords: Coordinates; - timestamp: Date; + timestamp: number; } declare var Position: { @@ -13578,9 +13578,17 @@ interface WebGLRenderingContext { stencilMaskSeparate(face: number, mask: number): void; stencilOp(fail: number, zfail: number, zpass: number): void; stencilOpSeparate(face: number, fail: number, zfail: number, zpass: number): void; + texImage2D(target: number, level: number, internalformat: number, width: number, height: number, border: number, format: number, type: number, pixels: ArrayBufferView): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, image: HTMLImageElement): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, canvas: HTMLCanvasElement): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, video: HTMLVideoElement): void; texImage2D(target: number, level: number, internalformat: number, format: number, type: number, pixels: ImageData): void; texParameterf(target: number, pname: number, param: number): void; texParameteri(target: number, pname: number, param: number): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, width: number, height: number, format: number, type: number, pixels: ArrayBufferView): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, image: HTMLImageElement): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, canvas: HTMLCanvasElement): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, video: HTMLVideoElement): void; texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, pixels: ImageData): void; uniform1f(location: WebGLUniformLocation, x: number): void; uniform1fv(location: WebGLUniformLocation, v: any): void; @@ -14820,10 +14828,11 @@ interface DocumentEvent { createEvent(eventInterface:"AriaRequestEvent"): AriaRequestEvent; createEvent(eventInterface:"AudioProcessingEvent"): AudioProcessingEvent; createEvent(eventInterface:"BeforeUnloadEvent"): BeforeUnloadEvent; + createEvent(eventInterface:"ClipboardEvent"): ClipboardEvent; createEvent(eventInterface:"CloseEvent"): CloseEvent; createEvent(eventInterface:"CommandEvent"): CommandEvent; createEvent(eventInterface:"CompositionEvent"): CompositionEvent; - createEvent(eventInterface: "CustomEvent"): CustomEvent; + createEvent(eventInterface:"CustomEvent"): CustomEvent; createEvent(eventInterface:"DeviceMotionEvent"): DeviceMotionEvent; createEvent(eventInterface:"DeviceOrientationEvent"): DeviceOrientationEvent; createEvent(eventInterface:"DragEvent"): DragEvent; @@ -14846,8 +14855,6 @@ interface DocumentEvent { createEvent(eventInterface:"MouseEvent"): MouseEvent; createEvent(eventInterface:"MouseEvents"): MouseEvent; createEvent(eventInterface:"MouseWheelEvent"): MouseWheelEvent; - createEvent(eventInterface:"MSGestureEvent"): MSGestureEvent; - createEvent(eventInterface:"MSPointerEvent"): MSPointerEvent; createEvent(eventInterface:"MutationEvent"): MutationEvent; createEvent(eventInterface:"MutationEvents"): MutationEvent; createEvent(eventInterface:"NavigationCompletedEvent"): NavigationCompletedEvent; @@ -15459,4 +15466,4 @@ declare function addEventListener(type: "unload", listener: (ev: Event) => any, declare function addEventListener(type: "volumechange", listener: (ev: Event) => any, useCapture?: boolean): void; declare function addEventListener(type: "waiting", listener: (ev: Event) => any, useCapture?: boolean): void; declare function addEventListener(type: "wheel", listener: (ev: WheelEvent) => any, useCapture?: boolean): void; -declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; \ No newline at end of file +declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; diff --git a/bin/lib.es6.d.ts b/bin/lib.es6.d.ts index b91bd34cf5d..2326b43207d 100644 --- a/bin/lib.es6.d.ts +++ b/bin/lib.es6.d.ts @@ -12713,10 +12713,10 @@ declare var MediaQueryList: { interface MediaSource extends EventTarget { activeSourceBuffers: SourceBufferList; duration: number; - readyState: string; + readyState: number; sourceBuffers: SourceBufferList; addSourceBuffer(type: string): SourceBuffer; - endOfStream(error?: string): void; + endOfStream(error?: number): void; removeSourceBuffer(sourceBuffer: SourceBuffer): void; } @@ -13445,7 +13445,7 @@ declare var PopStateEvent: { interface Position { coords: Coordinates; - timestamp: Date; + timestamp: number; } declare var Position: { @@ -16126,9 +16126,17 @@ interface WebGLRenderingContext { stencilMaskSeparate(face: number, mask: number): void; stencilOp(fail: number, zfail: number, zpass: number): void; stencilOpSeparate(face: number, fail: number, zfail: number, zpass: number): void; + texImage2D(target: number, level: number, internalformat: number, width: number, height: number, border: number, format: number, type: number, pixels: ArrayBufferView): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, image: HTMLImageElement): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, canvas: HTMLCanvasElement): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, video: HTMLVideoElement): void; texImage2D(target: number, level: number, internalformat: number, format: number, type: number, pixels: ImageData): void; texParameterf(target: number, pname: number, param: number): void; texParameteri(target: number, pname: number, param: number): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, width: number, height: number, format: number, type: number, pixels: ArrayBufferView): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, image: HTMLImageElement): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, canvas: HTMLCanvasElement): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, video: HTMLVideoElement): void; texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, pixels: ImageData): void; uniform1f(location: WebGLUniformLocation, x: number): void; uniform1fv(location: WebGLUniformLocation, v: any): void; @@ -17368,10 +17376,11 @@ interface DocumentEvent { createEvent(eventInterface:"AriaRequestEvent"): AriaRequestEvent; createEvent(eventInterface:"AudioProcessingEvent"): AudioProcessingEvent; createEvent(eventInterface:"BeforeUnloadEvent"): BeforeUnloadEvent; + createEvent(eventInterface:"ClipboardEvent"): ClipboardEvent; createEvent(eventInterface:"CloseEvent"): CloseEvent; createEvent(eventInterface:"CommandEvent"): CommandEvent; createEvent(eventInterface:"CompositionEvent"): CompositionEvent; - createEvent(eventInterface: "CustomEvent"): CustomEvent; + createEvent(eventInterface:"CustomEvent"): CustomEvent; createEvent(eventInterface:"DeviceMotionEvent"): DeviceMotionEvent; createEvent(eventInterface:"DeviceOrientationEvent"): DeviceOrientationEvent; createEvent(eventInterface:"DragEvent"): DragEvent; @@ -17394,8 +17403,6 @@ interface DocumentEvent { createEvent(eventInterface:"MouseEvent"): MouseEvent; createEvent(eventInterface:"MouseEvents"): MouseEvent; createEvent(eventInterface:"MouseWheelEvent"): MouseWheelEvent; - createEvent(eventInterface:"MSGestureEvent"): MSGestureEvent; - createEvent(eventInterface:"MSPointerEvent"): MSPointerEvent; createEvent(eventInterface:"MutationEvent"): MutationEvent; createEvent(eventInterface:"MutationEvents"): MutationEvent; createEvent(eventInterface:"NavigationCompletedEvent"): NavigationCompletedEvent; @@ -18008,6 +18015,7 @@ declare function addEventListener(type: "volumechange", listener: (ev: Event) => declare function addEventListener(type: "waiting", listener: (ev: Event) => any, useCapture?: boolean): void; declare function addEventListener(type: "wheel", listener: (ev: WheelEvent) => any, useCapture?: boolean): void; declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; + ///////////////////////////// /// WorkerGlobalScope APIs ///////////////////////////// diff --git a/bin/tsc.js b/bin/tsc.js index 2c0b0b8865e..c55b3be37ba 100644 --- a/bin/tsc.js +++ b/bin/tsc.js @@ -738,6 +738,9 @@ var ts; fileStream.Close(); } } + function getCanonicalPath(path) { + return path.toLowerCase(); + } function getNames(collection) { var result = []; for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) { @@ -745,23 +748,28 @@ var ts; } return result.sort(); } - function readDirectory(path, extension) { + function readDirectory(path, extension, exclude) { var result = []; + exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); visitDirectory(path); return result; function visitDirectory(path) { var folder = fso.GetFolder(path || "."); var files = getNames(folder.files); for (var _i = 0; _i < files.length; _i++) { - var name_1 = files[_i]; - if (!extension || ts.fileExtensionIs(name_1, extension)) { - result.push(ts.combinePaths(path, name_1)); + var current = files[_i]; + var name_1 = ts.combinePaths(path, current); + if ((!extension || ts.fileExtensionIs(name_1, extension)) && !ts.contains(exclude, getCanonicalPath(name_1))) { + result.push(name_1); } } var subfolders = getNames(folder.subfolders); for (var _a = 0; _a < subfolders.length; _a++) { var current = subfolders[_a]; - visitDirectory(ts.combinePaths(path, current)); + var name_2 = ts.combinePaths(path, current); + if (!ts.contains(exclude, getCanonicalPath(name_2))) { + visitDirectory(name_2); + } } } } @@ -839,8 +847,12 @@ var ts; } _fs.writeFileSync(fileName, data, "utf8"); } - function readDirectory(path, extension) { + function getCanonicalPath(path) { + return useCaseSensitiveFileNames ? path.toLowerCase() : path; + } + function readDirectory(path, extension, exclude) { var result = []; + exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); visitDirectory(path); return result; function visitDirectory(path) { @@ -849,14 +861,16 @@ var ts; for (var _i = 0; _i < files.length; _i++) { var current = files[_i]; var name = ts.combinePaths(path, current); - var stat = _fs.statSync(name); - if (stat.isFile()) { - if (!extension || ts.fileExtensionIs(name, extension)) { - result.push(name); + if (!ts.contains(exclude, getCanonicalPath(name))) { + var stat = _fs.statSync(name); + if (stat.isFile()) { + if (!extension || ts.fileExtensionIs(name, extension)) { + result.push(name); + } + } + else if (stat.isDirectory()) { + directories.push(name); } - } - else if (stat.isDirectory()) { - directories.push(name); } } for (var _a = 0; _a < directories.length; _a++) { @@ -1460,7 +1474,7 @@ var ts; Object_literal_s_property_0_implicitly_has_an_1_type: { code: 7018, category: ts.DiagnosticCategory.Error, key: "Object literal's property '{0}' implicitly has an '{1}' type." }, Rest_parameter_0_implicitly_has_an_any_type: { code: 7019, category: ts.DiagnosticCategory.Error, key: "Rest parameter '{0}' implicitly has an 'any[]' type." }, Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: { code: 7020, category: ts.DiagnosticCategory.Error, key: "Call signature, which lacks return-type annotation, implicitly has an 'any' return type." }, - _0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer." }, + _0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer." }, _0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: ts.DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type: { code: 7025, category: ts.DiagnosticCategory.Error, key: "Generator implicitly has type '{0}' because it does not yield any values. Consider supplying a return type." }, @@ -1642,9 +1656,9 @@ var ts; } function makeReverseMap(source) { var result = []; - for (var name_2 in source) { - if (source.hasOwnProperty(name_2)) { - result[source[name_2]] = name_2; + for (var name_3 in source) { + if (source.hasOwnProperty(name_3)) { + result[source[name_3]] = name_3; } } return result; @@ -3661,9 +3675,9 @@ var ts; return; default: if (isFunctionLike(node)) { - var name_3 = node.name; - if (name_3 && name_3.kind === 128) { - traverse(name_3.expression); + var name_4 = node.name; + if (name_4 && name_4.kind === 128) { + traverse(name_4.expression); return; } } @@ -4073,8 +4087,8 @@ var ts; return ts.forEach(docComment.tags, function (t) { if (t.kind === 247) { var parameterTag = t; - var name_4 = parameterTag.preParameterName || parameterTag.postParameterName; - if (name_4.text === parameterName) { + var name_5 = parameterTag.preParameterName || parameterTag.postParameterName; + if (name_5.text === parameterName) { return t; } } @@ -8164,8 +8178,8 @@ var ts; return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers); } if (decorators) { - var name_5 = createMissingNode(65, true, ts.Diagnostics.Declaration_expected); - return parsePropertyDeclaration(fullStart, decorators, modifiers, name_5, undefined); + var name_6 = createMissingNode(65, true, ts.Diagnostics.Declaration_expected); + return parsePropertyDeclaration(fullStart, decorators, modifiers, name_6, undefined); } ts.Debug.fail("Should not have attempted to parse class member declaration."); } @@ -9001,13 +9015,13 @@ var ts; while (true) { skipWhitespace(); var startPos = pos; - var name_6 = scanIdentifier(); - if (!name_6) { + var name_7 = scanIdentifier(); + if (!name_7) { parseErrorAtPosition(startPos, 0, ts.Diagnostics.Identifier_expected); return undefined; } - var typeParameter = createNode(129, name_6.pos); - typeParameter.name = name_6; + var typeParameter = createNode(129, name_7.pos); + typeParameter.name = name_7; finishNode(typeParameter, pos); typeParameters.push(typeParameter); skipWhitespace(); @@ -9401,10 +9415,10 @@ var ts; var stringType = createIntrinsicType(2, "string"); var numberType = createIntrinsicType(4, "number"); var booleanType = createIntrinsicType(8, "boolean"); - var esSymbolType = createIntrinsicType(1048576, "symbol"); + var esSymbolType = createIntrinsicType(2097152, "symbol"); var voidType = createIntrinsicType(16, "void"); - var undefinedType = createIntrinsicType(32 | 262144, "undefined"); - var nullType = createIntrinsicType(64 | 262144, "null"); + var undefinedType = createIntrinsicType(32 | 524288, "undefined"); + var nullType = createIntrinsicType(64 | 524288, "null"); var unknownType = createIntrinsicType(1, "unknown"); var circularType = createIntrinsicType(1, "__circular__"); var emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); @@ -9461,7 +9475,7 @@ var ts; }, "symbol": { type: esSymbolType, - flags: 1048576 + flags: 2097152 } }; function getEmitResolver(sourceFile) { @@ -9886,15 +9900,15 @@ var ts; var moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier); var targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier); if (targetSymbol) { - var name_7 = specifier.propertyName || specifier.name; - if (name_7.text) { - var symbolFromModule = getExportOfModule(targetSymbol, name_7.text); - var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_7.text); + var name_8 = specifier.propertyName || specifier.name; + if (name_8.text) { + var symbolFromModule = getExportOfModule(targetSymbol, name_8.text); + var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_8.text); var symbol = symbolFromModule && symbolFromVariable ? combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - error(name_7, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_7)); + error(name_8, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_8)); } return symbol; } @@ -10496,13 +10510,14 @@ var ts; } return appendParentTypeArgumentsAndSymbolName(symbol); } - function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, typeStack) { + function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, symbolStack) { var globalFlagsToPass = globalFlags & 16; return writeType(type, globalFlags); function writeType(type, flags) { - if (type.flags & 1048703) { - writer.writeKeyword(!(globalFlags & 16) && - (type.flags & 1) ? "any" : type.intrinsicName); + if (type.flags & 2097279) { + writer.writeKeyword(!(globalFlags & 16) && isTypeAny(type) + ? "any" + : type.intrinsicName); } else if (type.flags & 4096) { writeTypeReference(type, flags); @@ -10599,42 +10614,46 @@ var ts; } } function writeAnonymousType(type, flags) { - if (type.symbol && type.symbol.flags & (32 | 384 | 512)) { - writeTypeofSymbol(type, flags); - } - else if (shouldWriteTypeOfFunctionSymbol()) { - writeTypeofSymbol(type, flags); - } - else if (typeStack && ts.contains(typeStack, type)) { - var typeAlias = getTypeAliasForTypeLiteral(type); - if (typeAlias) { - buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056, 0, flags); + var symbol = type.symbol; + if (symbol) { + if (symbol.flags & (32 | 384 | 512)) { + writeTypeofSymbol(type, flags); + } + else if (shouldWriteTypeOfFunctionSymbol()) { + writeTypeofSymbol(type, flags); + } + else if (ts.contains(symbolStack, symbol)) { + var typeAlias = getTypeAliasForTypeLiteral(type); + if (typeAlias) { + buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056, 0, flags); + } + else { + writeKeyword(writer, 112); + } } else { - writeKeyword(writer, 112); + if (!symbolStack) { + symbolStack = []; + } + symbolStack.push(symbol); + writeLiteralType(type, flags); + symbolStack.pop(); } } else { - if (!typeStack) { - typeStack = []; - } - typeStack.push(type); writeLiteralType(type, flags); - typeStack.pop(); } function shouldWriteTypeOfFunctionSymbol() { - if (type.symbol) { - var isStaticMethodSymbol = !!(type.symbol.flags & 8192 && - ts.forEach(type.symbol.declarations, function (declaration) { return declaration.flags & 128; })); - var isNonLocalFunctionSymbol = !!(type.symbol.flags & 16) && - (type.symbol.parent || - ts.forEach(type.symbol.declarations, function (declaration) { - return declaration.parent.kind === 228 || declaration.parent.kind === 207; - })); - if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { - return !!(flags & 2) || - (typeStack && ts.contains(typeStack, type)); - } + var isStaticMethodSymbol = !!(symbol.flags & 8192 && + ts.forEach(symbol.declarations, function (declaration) { return declaration.flags & 128; })); + var isNonLocalFunctionSymbol = !!(symbol.flags & 16) && + (symbol.parent || + ts.forEach(symbol.declarations, function (declaration) { + return declaration.parent.kind === 228 || declaration.parent.kind === 207; + })); + if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { + return !!(flags & 2) || + (ts.contains(symbolStack, symbol)); } } } @@ -10663,7 +10682,7 @@ var ts; if (flags & 64) { writePunctuation(writer, 16); } - buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, typeStack); + buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, symbolStack); if (flags & 64) { writePunctuation(writer, 17); } @@ -10675,7 +10694,7 @@ var ts; } writeKeyword(writer, 88); writeSpace(writer); - buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, typeStack); + buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, symbolStack); if (flags & 64) { writePunctuation(writer, 17); } @@ -10687,7 +10706,7 @@ var ts; writer.increaseIndent(); for (var _i = 0, _a = resolved.callSignatures; _i < _a.length; _i++) { var signature = _a[_i]; - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22); writer.writeLine(); } @@ -10695,7 +10714,7 @@ var ts; var signature = _c[_b]; writeKeyword(writer, 88); writeSpace(writer); - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22); writer.writeLine(); } @@ -10736,7 +10755,7 @@ var ts; if (p.flags & 536870912) { writePunctuation(writer, 50); } - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22); writer.writeLine(); } @@ -10763,17 +10782,17 @@ var ts; buildDisplayForTypeParametersAndDelimiters(getLocalTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); } } - function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, typeStack) { + function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, symbolStack) { appendSymbolNameOnly(tp.symbol, writer); var constraint = getConstraintOfTypeParameter(tp); if (constraint) { writeSpace(writer); writeKeyword(writer, 79); writeSpace(writer); - buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, symbolStack); } } - function buildParameterDisplay(p, writer, enclosingDeclaration, flags, typeStack) { + function buildParameterDisplay(p, writer, enclosingDeclaration, flags, symbolStack) { var parameterNode = p.valueDeclaration; if (ts.isRestParameter(parameterNode)) { writePunctuation(writer, 21); @@ -10784,9 +10803,9 @@ var ts; } writePunctuation(writer, 51); writeSpace(writer); - buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, symbolStack); } - function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, symbolStack) { if (typeParameters && typeParameters.length) { writePunctuation(writer, 24); for (var i = 0; i < typeParameters.length; i++) { @@ -10794,12 +10813,12 @@ var ts; writePunctuation(writer, 23); writeSpace(writer); } - buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, typeStack); + buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, symbolStack); } writePunctuation(writer, 25); } } - function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, symbolStack) { if (typeParameters && typeParameters.length) { writePunctuation(writer, 24); for (var i = 0; i < typeParameters.length; i++) { @@ -10812,18 +10831,18 @@ var ts; writePunctuation(writer, 25); } } - function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, symbolStack) { writePunctuation(writer, 16); for (var i = 0; i < parameters.length; i++) { if (i > 0) { writePunctuation(writer, 23); writeSpace(writer); } - buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, typeStack); + buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, symbolStack); } writePunctuation(writer, 17); } - function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack) { if (flags & 8) { writeSpace(writer); writePunctuation(writer, 32); @@ -10832,17 +10851,17 @@ var ts; writePunctuation(writer, 51); } writeSpace(writer); - buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, symbolStack); } - function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, symbolStack) { if (signature.target && (flags & 32)) { buildDisplayForTypeArgumentsAndDelimiters(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration); } else { - buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, typeStack); + buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, symbolStack); } - buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, typeStack); - buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack); + buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, symbolStack); + buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack); } return _displayBuilder || (_displayBuilder = { symbolToString: symbolToString, @@ -11036,13 +11055,16 @@ var ts; var prop = getPropertyOfType(type, name); return prop ? getTypeOfSymbol(prop) : undefined; } + function isTypeAny(type) { + return type && (type.flags & 1) !== 0; + } function getTypeForBindingElement(declaration) { var pattern = declaration.parent; var parentType = getTypeForVariableLikeDeclaration(pattern.parent); if (parentType === unknownType) { return unknownType; } - if (!parentType || parentType === anyType) { + if (!parentType || isTypeAny(parentType)) { if (declaration.initializer) { return checkExpressionCached(declaration.initializer); } @@ -11050,19 +11072,19 @@ var ts; } var type; if (pattern.kind === 151) { - var name_8 = declaration.propertyName || declaration.name; - type = getTypeOfPropertyOfType(parentType, name_8.text) || - isNumericLiteralName(name_8.text) && getIndexTypeOfType(parentType, 1) || + var name_9 = declaration.propertyName || declaration.name; + type = getTypeOfPropertyOfType(parentType, name_9.text) || + isNumericLiteralName(name_9.text) && getIndexTypeOfType(parentType, 1) || getIndexTypeOfType(parentType, 0); if (!type) { - error(name_8, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_8)); + error(name_9, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_9)); return unknownType; } } else { var elementType = checkIteratedTypeOrElementType(parentType, pattern, false); if (!declaration.dotDotDotToken) { - if (elementType.flags & 1) { + if (isTypeAny(elementType)) { return elementType; } var propName = "" + ts.indexOf(pattern.elements, declaration); @@ -11207,7 +11229,7 @@ var ts; else { type = anyType; if (compilerOptions.noImplicitAny) { - error(symbol.valueDeclaration, ts.Diagnostics._0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol)); + error(symbol.valueDeclaration, ts.Diagnostics._0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol)); } } } @@ -11817,7 +11839,7 @@ var ts; else if (type.flags & 8) { type = globalBooleanType; } - else if (type.flags & 1048576) { + else if (type.flags & 2097152) { type = globalESSymbolType; } return type; @@ -12074,7 +12096,7 @@ var ts; function getOrCreateTypeFromSignature(signature) { if (!signature.isolatedSignatureType) { var isConstructor = signature.declaration.kind === 136 || signature.declaration.kind === 140; - var type = createObjectType(32768 | 65536); + var type = createObjectType(32768 | 131072); type.members = emptySymbols; type.properties = emptyArray; type.callSignatures = !isConstructor ? [signature] : emptyArray; @@ -12148,7 +12170,7 @@ var ts; var type = types[_i]; result |= type.flags; } - return result & 786432; + return result & 1572864; } function createTypeReference(target, typeArguments) { var id = getTypeListId(typeArguments); @@ -12364,10 +12386,10 @@ var ts; } } } - function containsAnyType(types) { + function containsTypeAny(types) { for (var _i = 0; _i < types.length; _i++) { var type = types[_i]; - if (type.flags & 1) { + if (isTypeAny(type)) { return true; } } @@ -12389,7 +12411,7 @@ var ts; var sortedTypes = []; addTypesToSortedSet(sortedTypes, types); if (noSubtypeReduction) { - if (containsAnyType(sortedTypes)) { + if (containsTypeAny(sortedTypes)) { return anyType; } removeAllButLast(sortedTypes, undefinedType); @@ -12603,16 +12625,7 @@ var ts; return result; } function instantiateAnonymousType(type, mapper) { - if (mapper.mappings) { - var cached = mapper.mappings[type.id]; - if (cached) { - return cached; - } - } - else { - mapper.mappings = {}; - } - var result = createObjectType(32768, type.symbol); + var result = createObjectType(32768 | 65536, type.symbol); result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); result.members = createSymbolTable(result.properties); result.callSignatures = instantiateList(getSignaturesOfType(type, 0), mapper, instantiateSignature); @@ -12623,7 +12636,6 @@ var ts; result.stringIndexType = instantiateType(stringIndexType, mapper); if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper); - mapper.mappings[type.id] = result; return result; } function instantiateType(type, mapper) { @@ -12750,7 +12762,7 @@ var ts; if (source === target) return -1; if (relation !== identityRelation) { - if (target.flags & 1) + if (isTypeAny(target)) return -1; if (source === undefinedType) return -1; @@ -12761,7 +12773,7 @@ var ts; if (source.flags & 256 && target === stringType) return -1; if (relation === assignableRelation) { - if (source.flags & 1) + if (isTypeAny(source)) return -1; if (source === numberType && target.flags & 128) return -1; @@ -12979,12 +12991,12 @@ var ts; return result; } function isDeeplyNestedGeneric(type, stack) { - if (type.flags & 4096 && depth >= 10) { - var target_1 = type.target; + if (type.flags & (4096 | 65536) && depth >= 10) { + var symbol = type.symbol; var count = 0; for (var i = 0; i < depth; i++) { var t = stack[i]; - if (t.flags & 4096 && t.target === target_1) { + if (t.flags & (4096 | 65536) && t.symbol === symbol) { count++; if (count >= 10) return true; @@ -12999,7 +13011,7 @@ var ts; } var result = -1; var properties = getPropertiesOfObjectType(target); - var requireOptionalProperties = relation === subtypeRelation && !(source.flags & 131072); + var requireOptionalProperties = relation === subtypeRelation && !(source.flags & 262144); for (var _i = 0; _i < properties.length; _i++) { var targetProp = properties[_i]; var sourceProp = getPropertyOfType(source, targetProp.name); @@ -13098,11 +13110,11 @@ var ts; var saveErrorInfo = errorInfo; outer: for (var _i = 0; _i < targetSignatures.length; _i++) { var t = targetSignatures[_i]; - if (!t.hasStringLiterals || target.flags & 65536) { + if (!t.hasStringLiterals || target.flags & 131072) { var localErrors = reportErrors; for (var _a = 0; _a < sourceSignatures.length; _a++) { var s = sourceSignatures[_a]; - if (!s.hasStringLiterals || source.flags & 65536) { + if (!s.hasStringLiterals || source.flags & 131072) { var related = signatureRelatedTo(s, t, localErrors); if (related) { result &= related; @@ -13394,11 +13406,11 @@ var ts; return createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType); } function getWidenedType(type) { - if (type.flags & 786432) { + if (type.flags & 1572864) { if (type.flags & (32 | 64)) { return anyType; } - if (type.flags & 131072) { + if (type.flags & 262144) { return getWidenedTypeOfObjectLiteral(type); } if (type.flags & 16384) { @@ -13423,11 +13435,11 @@ var ts; if (isArrayType(type)) { return reportWideningErrorsInType(type.typeArguments[0]); } - if (type.flags & 131072) { + if (type.flags & 262144) { var errorReported = false; ts.forEach(getPropertiesOfObjectType(type), function (p) { var t = getTypeOfSymbol(p); - if (t.flags & 262144) { + if (t.flags & 524288) { if (!reportWideningErrorsInType(t)) { error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(getWidenedType(t))); } @@ -13470,7 +13482,7 @@ var ts; error(declaration, diagnostic, ts.declarationNameToString(declaration.name), typeAsString); } function reportErrorsFromWidening(declaration, type) { - if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 262144) { + if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 524288) { if (!reportWideningErrorsInType(type)) { reportImplicitAnyError(declaration, type); } @@ -13531,11 +13543,11 @@ var ts; } function isWithinDepthLimit(type, stack) { if (depth >= 5) { - var target_2 = type.target; + var target_1 = type.target; var count = 0; for (var i = 0; i < depth; i++) { var t = stack[i]; - if (t.flags & 4096 && t.target === target_2) { + if (t.flags & 4096 && t.target === target_1) { count++; } } @@ -13831,47 +13843,49 @@ var ts; } function getNarrowedTypeOfSymbol(symbol, node) { var type = getTypeOfSymbol(symbol); - if (node && symbol.flags & 3 && type.flags & (1 | 48128 | 16384 | 512)) { - loop: while (node.parent) { - var child = node; - node = node.parent; - var narrowedType = type; - switch (node.kind) { - case 184: - if (child !== node.expression) { - narrowedType = narrowType(type, node.expression, child === node.thenStatement); - } - break; - case 171: - if (child !== node.condition) { - narrowedType = narrowType(type, node.condition, child === node.whenTrue); - } - break; - case 170: - if (child === node.right) { - if (node.operatorToken.kind === 48) { - narrowedType = narrowType(type, node.left, true); + if (node && symbol.flags & 3) { + if (isTypeAny(type) || type.flags & (48128 | 16384 | 512)) { + loop: while (node.parent) { + var child = node; + node = node.parent; + var narrowedType = type; + switch (node.kind) { + case 184: + if (child !== node.expression) { + narrowedType = narrowType(type, node.expression, child === node.thenStatement); } - else if (node.operatorToken.kind === 49) { - narrowedType = narrowType(type, node.left, false); + break; + case 171: + if (child !== node.condition) { + narrowedType = narrowType(type, node.condition, child === node.whenTrue); } - } - break; - case 228: - case 206: - case 201: - case 135: - case 134: - case 137: - case 138: - case 136: - break loop; - } - if (narrowedType !== type) { - if (isVariableAssignedWithin(symbol, node)) { - break; + break; + case 170: + if (child === node.right) { + if (node.operatorToken.kind === 48) { + narrowedType = narrowType(type, node.left, true); + } + else if (node.operatorToken.kind === 49) { + narrowedType = narrowType(type, node.left, false); + } + } + break; + case 228: + case 206: + case 201: + case 135: + case 134: + case 137: + case 138: + case 136: + break loop; + } + if (narrowedType !== type) { + if (isVariableAssignedWithin(symbol, node)) { + break; + } + type = narrowedType; } - type = narrowedType; } } } @@ -13891,7 +13905,7 @@ var ts; } if (assumeTrue) { if (!typeInfo) { - return removeTypesFromUnionType(type, 258 | 132 | 8 | 1048576, true, false); + return removeTypesFromUnionType(type, 258 | 132 | 8 | 2097152, true, false); } if (isTypeSubtypeOf(typeInfo.type, type)) { return typeInfo.type; @@ -13928,7 +13942,7 @@ var ts; } } function narrowTypeByInstanceof(type, expr, assumeTrue) { - if (type.flags & 1 || !assumeTrue || expr.left.kind !== 65 || getResolvedSymbol(expr.left) !== symbol) { + if (isTypeAny(type) || !assumeTrue || expr.left.kind !== 65 || getResolvedSymbol(expr.left) !== symbol) { return type; } var rightType = checkExpression(expr.right); @@ -13939,7 +13953,7 @@ var ts; var prototypeProperty = getPropertyOfType(rightType, "prototype"); if (prototypeProperty) { var prototypePropertyType = getTypeOfSymbol(prototypeProperty); - if (prototypePropertyType !== anyType) { + if (!isTypeAny(prototypePropertyType)) { targetType = prototypePropertyType; } } @@ -14510,7 +14524,10 @@ var ts; return name.kind === 128 ? isNumericComputedName(name) : isNumericLiteralName(name.text); } function isNumericComputedName(name) { - return allConstituentTypesHaveKind(checkComputedPropertyName(name), 1 | 132); + return isTypeAnyOrAllConstituentTypesHaveKind(checkComputedPropertyName(name), 132); + } + function isTypeAnyOrAllConstituentTypesHaveKind(type, kind) { + return isTypeAny(type) || allConstituentTypesHaveKind(type, kind); } function isNumericLiteralName(name) { return (+name).toString() === name; @@ -14519,7 +14536,7 @@ var ts; var links = getNodeLinks(node.expression); if (!links.resolvedType) { links.resolvedType = checkExpression(node.expression); - if (!allConstituentTypesHaveKind(links.resolvedType, 1 | 132 | 258 | 1048576)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(links.resolvedType, 132 | 258 | 2097152)) { error(node, ts.Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any); } else { @@ -14574,7 +14591,7 @@ var ts; var stringIndexType = getIndexType(0); var numberIndexType = getIndexType(1); var result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType); - result.flags |= 131072 | 524288 | (typeFlags & 262144); + result.flags |= 262144 | 1048576 | (typeFlags & 524288); return result; function getIndexType(kind) { if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { @@ -14637,39 +14654,37 @@ var ts; } function checkPropertyAccessExpressionOrQualifiedName(node, left, right) { var type = checkExpressionOrQualifiedName(left); - if (type === unknownType) + if (isTypeAny(type)) { return type; - if (type !== anyType) { - var apparentType = getApparentType(getWidenedType(type)); - if (apparentType === unknownType) { - return unknownType; - } - var prop = getPropertyOfType(apparentType, right.text); - if (!prop) { - if (right.text) { - error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type)); - } - return unknownType; - } - getNodeLinks(node).resolvedSymbol = prop; - if (prop.parent && prop.parent.flags & 32) { - if (left.kind === 91 && getDeclarationKindFromSymbol(prop) !== 135) { - error(right, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); - } - else { - checkClassPropertyAccess(node, left, type, prop); - } - } - return getTypeOfSymbol(prop); } - return anyType; + var apparentType = getApparentType(getWidenedType(type)); + if (apparentType === unknownType) { + return unknownType; + } + var prop = getPropertyOfType(apparentType, right.text); + if (!prop) { + if (right.text) { + error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type)); + } + return unknownType; + } + getNodeLinks(node).resolvedSymbol = prop; + if (prop.parent && prop.parent.flags & 32) { + if (left.kind === 91 && getDeclarationKindFromSymbol(prop) !== 135) { + error(right, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); + } + else { + checkClassPropertyAccess(node, left, type, prop); + } + } + return getTypeOfSymbol(prop); } function isValidPropertyAccess(node, propertyName) { var left = node.kind === 156 ? node.expression : node.left; var type = checkExpressionOrQualifiedName(left); - if (type !== unknownType && type !== anyType) { + if (type !== unknownType && !isTypeAny(type)) { var prop = getPropertyOfType(getWidenedType(type), propertyName); if (prop && prop.parent && prop.parent.flags & 32) { if (left.kind === 91 && getDeclarationKindFromSymbol(prop) !== 135) { @@ -14710,21 +14725,21 @@ var ts; return unknownType; } if (node.argumentExpression) { - var name_9 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); - if (name_9 !== undefined) { - var prop = getPropertyOfType(objectType, name_9); + var name_10 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); + if (name_10 !== undefined) { + var prop = getPropertyOfType(objectType, name_10); if (prop) { getNodeLinks(node).resolvedSymbol = prop; return getTypeOfSymbol(prop); } else if (isConstEnum) { - error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_9, symbolToString(objectType.symbol)); + error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_10, symbolToString(objectType.symbol)); return unknownType; } } } - if (allConstituentTypesHaveKind(indexType, 1 | 258 | 132 | 1048576)) { - if (allConstituentTypesHaveKind(indexType, 1 | 132)) { + if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, 258 | 132 | 2097152)) { + if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, 132)) { var numberIndexType = getIndexTypeOfType(objectType, 1); if (numberIndexType) { return numberIndexType; @@ -14734,7 +14749,7 @@ var ts; if (stringIndexType) { return stringIndexType; } - if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && objectType !== anyType) { + if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && !isTypeAny(objectType)) { error(node, ts.Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type); } return anyType; @@ -14759,7 +14774,7 @@ var ts; if (!ts.isWellKnownSymbolSyntactically(expression)) { return false; } - if ((expressionType.flags & 1048576) === 0) { + if ((expressionType.flags & 2097152) === 0) { if (reportError) { error(expression, ts.Diagnostics.A_computed_property_name_of_the_form_0_must_be_of_type_symbol, ts.getTextOfNode(expression)); } @@ -15141,8 +15156,8 @@ var ts; } var callSignatures = getSignaturesOfType(apparentType, 0); var constructSignatures = getSignaturesOfType(apparentType, 1); - if (funcType === anyType || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384) && isTypeAssignableTo(funcType, globalFunctionType))) { - if (node.typeArguments) { + if (isTypeAny(funcType) || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384) && isTypeAssignableTo(funcType, globalFunctionType))) { + if (funcType !== unknownType && node.typeArguments) { error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } return resolveUntypedCall(node); @@ -15166,16 +15181,16 @@ var ts; } } var expressionType = checkExpression(node.expression); - if (expressionType === anyType) { + expressionType = getApparentType(expressionType); + if (expressionType === unknownType) { + return resolveErrorCall(node); + } + if (isTypeAny(expressionType)) { if (node.typeArguments) { error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } return resolveUntypedCall(node); } - expressionType = getApparentType(expressionType); - if (expressionType === unknownType) { - return resolveErrorCall(node); - } var constructSignatures = getSignaturesOfType(expressionType, 1); if (constructSignatures.length) { return resolveCall(node, constructSignatures, candidatesOutArray); @@ -15198,7 +15213,7 @@ var ts; return resolveErrorCall(node); } var callSignatures = getSignaturesOfType(apparentType, 0); - if (tagType === anyType || (!callSignatures.length && !(tagType.flags & 16384) && isTypeAssignableTo(tagType, globalFunctionType))) { + if (isTypeAny(tagType) || (!callSignatures.length && !(tagType.flags & 16384) && isTypeAssignableTo(tagType, globalFunctionType))) { return resolveUntypedCall(node); } if (!callSignatures.length) { @@ -15367,7 +15382,7 @@ var ts; if (!produceDiagnostics) { return; } - if (returnType === voidType || returnType === anyType) { + if (returnType === voidType || isTypeAny(returnType)) { return; } if (ts.nodeIsMissing(func.body) || func.body.kind !== 180) { @@ -15440,7 +15455,7 @@ var ts; } } function checkArithmeticOperandType(operand, type, diagnostic) { - if (!allConstituentTypesHaveKind(type, 1 | 132)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(type, 132)) { error(operand, diagnostic); return false; } @@ -15480,8 +15495,8 @@ var ts; var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 8) { - var name_10 = index.text; - var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_10); + var name_11 = index.text; + var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_11); return prop && (prop.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 8192) !== 0; } return false; @@ -15526,7 +15541,7 @@ var ts; case 33: case 34: case 47: - if (someConstituentTypeHasKind(operandType, 1048576)) { + if (someConstituentTypeHasKind(operandType, 2097152)) { error(node.operand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(node.operator)); } return numberType; @@ -15590,19 +15605,19 @@ var ts; return (symbol.flags & 128) !== 0; } function checkInstanceOfExpression(node, leftType, rightType) { - if (allConstituentTypesHaveKind(leftType, 1049086)) { + if (allConstituentTypesHaveKind(leftType, 2097662)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } - if (!(rightType.flags & 1 || isTypeSubtypeOf(rightType, globalFunctionType))) { + if (!(isTypeAny(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type); } return booleanType; } function checkInExpression(node, leftType, rightType) { - if (!allConstituentTypesHaveKind(leftType, 1 | 258 | 132 | 1048576)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258 | 132 | 2097152)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); } - if (!allConstituentTypesHaveKind(rightType, 1 | 48128 | 512)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 48128 | 512)) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; @@ -15612,16 +15627,17 @@ var ts; for (var _i = 0; _i < properties.length; _i++) { var p = properties[_i]; if (p.kind === 225 || p.kind === 226) { - var name_11 = p.name; - var type = sourceType.flags & 1 ? sourceType : - getTypeOfPropertyOfType(sourceType, name_11.text) || - isNumericLiteralName(name_11.text) && getIndexTypeOfType(sourceType, 1) || + var name_12 = p.name; + var type = isTypeAny(sourceType) + ? sourceType + : getTypeOfPropertyOfType(sourceType, name_12.text) || + isNumericLiteralName(name_12.text) && getIndexTypeOfType(sourceType, 1) || getIndexTypeOfType(sourceType, 0); if (type) { - checkDestructuringAssignment(p.initializer || name_11, type); + checkDestructuringAssignment(p.initializer || name_12, type); } else { - error(name_11, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_11)); + error(name_12, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_12)); } } else { @@ -15638,8 +15654,9 @@ var ts; if (e.kind !== 176) { if (e.kind !== 174) { var propName = "" + i; - var type = sourceType.flags & 1 ? sourceType : - isTupleLikeType(sourceType) + var type = isTypeAny(sourceType) + ? sourceType + : isTupleLikeType(sourceType) ? getTypeOfPropertyOfType(sourceType, propName) : elementType; if (type) { @@ -15755,8 +15772,8 @@ var ts; if (allConstituentTypesHaveKind(leftType, 258) || allConstituentTypesHaveKind(rightType, 258)) { resultType = stringType; } - else if (leftType.flags & 1 || rightType.flags & 1) { - resultType = anyType; + else if (isTypeAny(leftType) || isTypeAny(rightType)) { + resultType = leftType === unknownType || rightType === unknownType ? unknownType : anyType; } if (resultType && !checkForDisallowedESSymbolOperand(operator)) { return resultType; @@ -15800,8 +15817,8 @@ var ts; return rightType; } function checkForDisallowedESSymbolOperand(operator) { - var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 1048576) ? node.left : - someConstituentTypeHasKind(rightType, 1048576) ? node.right : + var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 2097152) ? node.left : + someConstituentTypeHasKind(rightType, 2097152) ? node.right : undefined; if (offendingSymbolOperand) { error(offendingSymbolOperand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(operator)); @@ -16580,7 +16597,7 @@ var ts; if (node && node.kind === 142) { var type = getTypeFromTypeNode(node); var shouldCheckIfUnknownType = type === unknownType && compilerOptions.isolatedModules; - if (!type || (!shouldCheckIfUnknownType && type.flags & (1048703 | 132 | 258))) { + if (!type || (!shouldCheckIfUnknownType && type.flags & (2097279 | 132 | 258))) { return; } if (shouldCheckIfUnknownType || type.symbol.valueDeclaration) { @@ -16808,8 +16825,8 @@ var ts; container.kind === 206 || container.kind === 228); if (!namesShareScope) { - var name_12 = symbolToString(localDeclarationSymbol); - error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_12, name_12); + var name_13 = symbolToString(localDeclarationSymbol); + error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_13, name_13); } } } @@ -16996,7 +17013,7 @@ var ts; if (varExpr.kind === 154 || varExpr.kind === 155) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); } - else if (!allConstituentTypesHaveKind(leftType, 1 | 258)) { + else if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258)) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any); } else { @@ -17004,7 +17021,7 @@ var ts; } } var rightType = checkExpression(node.expression); - if (!allConstituentTypesHaveKind(rightType, 1 | 48128 | 512)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 48128 | 512)) { error(node.expression, ts.Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } checkSourceElement(node.statement); @@ -17021,7 +17038,7 @@ var ts; return checkIteratedTypeOrElementType(expressionType, rhsExpression, true); } function checkIteratedTypeOrElementType(inputType, errorNode, allowStringInput) { - if (inputType.flags & 1) { + if (isTypeAny(inputType)) { return inputType; } if (languageVersion >= 2) { @@ -17047,7 +17064,7 @@ var ts; return elementType || anyType; } function getElementTypeOfIterable(type, errorNode) { - if (type.flags & 1) { + if (isTypeAny(type)) { return undefined; } var typeAsIterable = type; @@ -17057,7 +17074,7 @@ var ts; } else { var iteratorFunction = getTypeOfPropertyOfType(type, ts.getPropertyNameForKnownSymbolName("iterator")); - if (iteratorFunction && iteratorFunction.flags & 1) { + if (isTypeAny(iteratorFunction)) { return undefined; } var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0) : emptyArray; @@ -17073,7 +17090,7 @@ var ts; return typeAsIterable.iterableElementType; } function getElementTypeOfIterator(type, errorNode) { - if (type.flags & 1) { + if (isTypeAny(type)) { return undefined; } var typeAsIterator = type; @@ -17083,7 +17100,7 @@ var ts; } else { var iteratorNextFunction = getTypeOfPropertyOfType(type, "next"); - if (iteratorNextFunction && iteratorNextFunction.flags & 1) { + if (isTypeAny(iteratorNextFunction)) { return undefined; } var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0) : emptyArray; @@ -17094,7 +17111,7 @@ var ts; return undefined; } var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); - if (iteratorNextResult.flags & 1) { + if (isTypeAny(iteratorNextResult)) { return undefined; } var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value"); @@ -17110,7 +17127,7 @@ var ts; return typeAsIterator.iteratorElementType; } function getElementTypeOfIterableIterator(type) { - if (type.flags & 1) { + if (isTypeAny(type)) { return undefined; } if ((type.flags & 4096) && type.target === globalIterableIteratorType) { @@ -18589,9 +18606,9 @@ var ts; function getRootSymbols(symbol) { if (symbol.flags & 268435456) { var symbols = []; - var name_13 = symbol.name; + var name_14 = symbol.name; ts.forEach(getSymbolLinks(symbol).unionType.types, function (t) { - symbols.push(getPropertyOfType(t, name_13)); + symbols.push(getPropertyOfType(t, name_14)); }); return symbols; } @@ -18769,7 +18786,7 @@ var ts; else if (type.flags & 8192) { return "Array"; } - else if (type.flags & 1048576) { + else if (type.flags & 2097152) { return "Symbol"; } else if (type === unknownType) { @@ -19014,20 +19031,20 @@ var ts; if (impotClause.namedBindings) { var nameBindings = impotClause.namedBindings; if (nameBindings.kind === 212) { - var name_14 = nameBindings.name; - if (isReservedWordInStrictMode(name_14)) { - var nameText = ts.declarationNameToString(name_14); - return grammarErrorOnNode(name_14, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_15 = nameBindings.name; + if (isReservedWordInStrictMode(name_15)) { + var nameText = ts.declarationNameToString(name_15); + return grammarErrorOnNode(name_15, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } else if (nameBindings.kind === 213) { var reportError = false; for (var _i = 0, _a = nameBindings.elements; _i < _a.length; _i++) { var element = _a[_i]; - var name_15 = element.name; - if (isReservedWordInStrictMode(name_15)) { - var nameText = ts.declarationNameToString(name_15); - reportError = reportError || grammarErrorOnNode(name_15, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_16 = element.name; + if (isReservedWordInStrictMode(name_16)) { + var nameText = ts.declarationNameToString(name_16); + reportError = reportError || grammarErrorOnNode(name_16, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } return reportError; @@ -19486,17 +19503,17 @@ var ts; var inStrictMode = (node.parserContextFlags & 1) !== 0; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - var name_16 = prop.name; + var name_17 = prop.name; if (prop.kind === 176 || - name_16.kind === 128) { - checkGrammarComputedPropertyName(name_16); + name_17.kind === 128) { + checkGrammarComputedPropertyName(name_17); continue; } var currentKind = void 0; if (prop.kind === 225 || prop.kind === 226) { checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); - if (name_16.kind === 7) { - checkGrammarNumericLiteral(name_16); + if (name_17.kind === 7) { + checkGrammarNumericLiteral(name_17); } currentKind = Property; } @@ -19512,26 +19529,26 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_16.text)) { - seen[name_16.text] = currentKind; + if (!ts.hasProperty(seen, name_17.text)) { + seen[name_17.text] = currentKind; } else { - var existingKind = seen[name_16.text]; + var existingKind = seen[name_17.text]; if (currentKind === Property && existingKind === Property) { if (inStrictMode) { - grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); + grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); } } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_16.text] = currentKind | existingKind; + seen[name_17.text] = currentKind | existingKind; } else { - return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + return grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); } } else { - return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + return grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); } } } @@ -20310,9 +20327,9 @@ var ts; } var count = 0; while (true) { - var name_17 = baseName + "_" + (++count); - if (!ts.hasProperty(currentSourceFile.identifiers, name_17)) { - return name_17; + var name_18 = baseName + "_" + (++count); + if (!ts.hasProperty(currentSourceFile.identifiers, name_18)) { + return name_18; } } } @@ -21396,9 +21413,9 @@ var ts; var count = tempFlags & 268435455; tempFlags++; if (count !== 8 && count !== 13) { - var name_18 = count < 26 ? "_" + String.fromCharCode(97 + count) : "_" + (count - 26); - if (isUniqueName(name_18)) { - return name_18; + var name_19 = count < 26 ? "_" + String.fromCharCode(97 + count) : "_" + (count - 26); + if (isUniqueName(name_19)) { + return name_19; } } } @@ -21426,8 +21443,8 @@ var ts; } function generateNameForModuleOrEnum(node) { if (node.name.kind === 65) { - var name_19 = node.name.text; - assignGeneratedName(node, isUniqueLocalName(name_19, node) ? name_19 : makeUniqueName(name_19)); + var name_20 = node.name.text; + assignGeneratedName(node, isUniqueLocalName(name_20, node) ? name_20 : makeUniqueName(name_20)); } } function generateNameForImportOrExportDeclaration(node) { @@ -21613,8 +21630,8 @@ var ts; if (scopeName) { var parentIndex = getSourceMapNameIndex(); if (parentIndex !== -1) { - var name_20 = node.name; - if (!name_20 || name_20.kind !== 128) { + var name_21 = node.name; + if (!name_21 || name_21.kind !== 128) { scopeName = "." + scopeName; } scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; @@ -21641,9 +21658,9 @@ var ts; node.kind === 202 || node.kind === 205) { if (node.name) { - var name_21 = node.name; - scopeName = name_21.kind === 128 - ? ts.getTextOfNode(name_21) + var name_22 = node.name; + scopeName = name_22.kind === 128 + ? ts.getTextOfNode(name_22) : node.name.text; } recordScopeNameStart(scopeName); @@ -22493,7 +22510,12 @@ var ts; return result; } function parenthesizeForAccess(expr) { - if (ts.isLeftHandSideExpression(expr) && expr.kind !== 159 && expr.kind !== 7) { + while (expr.kind === 161) { + expr = expr.expression; + } + if (ts.isLeftHandSideExpression(expr) && + expr.kind !== 159 && + expr.kind !== 7) { return expr; } var node = ts.createSynthesizedNode(162); @@ -22714,7 +22736,7 @@ var ts; } } function emitParenExpression(node) { - if (!node.parent || node.parent.kind !== 164) { + if (!ts.nodeIsSynthesized(node) && node.parent.kind !== 164) { if (node.expression.kind === 161) { var operand = node.expression.expression; while (operand.kind == 161) { @@ -23670,12 +23692,12 @@ var ts; function emitParameter(node) { if (languageVersion < 2) { if (ts.isBindingPattern(node.name)) { - var name_22 = createTempVariable(0); + var name_23 = createTempVariable(0); if (!tempParameters) { tempParameters = []; } - tempParameters.push(name_22); - emit(name_22); + tempParameters.push(name_23); + emit(name_23); } else { emit(node.name); @@ -25135,8 +25157,8 @@ var ts; else { for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { var specifier = _d[_c]; - var name_23 = (specifier.propertyName || specifier.name).text; - (exportSpecifiers[name_23] || (exportSpecifiers[name_23] = [])).push(specifier); + var name_24 = (specifier.propertyName || specifier.name).text; + (exportSpecifiers[name_24] || (exportSpecifiers[name_24] = [])).push(specifier); } } break; @@ -25309,11 +25331,11 @@ var ts; var seen = {}; for (var i = 0; i < hoistedVars.length; ++i) { var local = hoistedVars[i]; - var name_24 = local.kind === 65 + var name_25 = local.kind === 65 ? local : local.name; - if (name_24) { - var text = ts.unescapeIdentifier(name_24.text); + if (name_25) { + var text = ts.unescapeIdentifier(name_25.text); if (ts.hasProperty(seen, text)) { continue; } @@ -25392,15 +25414,15 @@ var ts; } if (node.kind === 199 || node.kind === 153) { if (shouldHoistVariable(node, false)) { - var name_25 = node.name; - if (name_25.kind === 65) { + var name_26 = node.name; + if (name_26.kind === 65) { if (!hoistedVars) { hoistedVars = []; } - hoistedVars.push(name_25); + hoistedVars.push(name_26); } else { - ts.forEachChild(name_25, visit); + ts.forEachChild(name_26, visit); } } return; @@ -26909,7 +26931,7 @@ var ts; var errors = []; return { options: getCompilerOptions(), - fileNames: getFiles(), + fileNames: getFileNames(), errors: errors }; function getCompilerOptions() { @@ -26953,23 +26975,24 @@ var ts; } return options; } - function getFiles() { - var files = []; + function getFileNames() { + var fileNames = []; if (ts.hasProperty(json, "files")) { if (json["files"] instanceof Array) { - var files = ts.map(json["files"], function (s) { return ts.combinePaths(basePath, s); }); + fileNames = ts.map(json["files"], function (s) { return ts.combinePaths(basePath, s); }); } } else { - var sysFiles = host.readDirectory(basePath, ".ts"); + var exclude = json["exclude"] instanceof Array ? ts.map(json["exclude"], ts.normalizeSlashes) : undefined; + var sysFiles = host.readDirectory(basePath, ".ts", exclude); for (var i = 0; i < sysFiles.length; i++) { var name = sysFiles[i]; if (!ts.fileExtensionIs(name, ".d.ts") || !ts.contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) { - files.push(name); + fileNames.push(name); } } } - return files; + return fileNames; } } ts.parseConfigFile = parseConfigFile; diff --git a/bin/tsserver.js b/bin/tsserver.js index 591da07f260..71ff883dbce 100644 --- a/bin/tsserver.js +++ b/bin/tsserver.js @@ -738,6 +738,9 @@ var ts; fileStream.Close(); } } + function getCanonicalPath(path) { + return path.toLowerCase(); + } function getNames(collection) { var result = []; for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) { @@ -745,23 +748,28 @@ var ts; } return result.sort(); } - function readDirectory(path, extension) { + function readDirectory(path, extension, exclude) { var result = []; + exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); visitDirectory(path); return result; function visitDirectory(path) { var folder = fso.GetFolder(path || "."); var files = getNames(folder.files); for (var _i = 0; _i < files.length; _i++) { - var name_1 = files[_i]; - if (!extension || ts.fileExtensionIs(name_1, extension)) { - result.push(ts.combinePaths(path, name_1)); + var current = files[_i]; + var name_1 = ts.combinePaths(path, current); + if ((!extension || ts.fileExtensionIs(name_1, extension)) && !ts.contains(exclude, getCanonicalPath(name_1))) { + result.push(name_1); } } var subfolders = getNames(folder.subfolders); for (var _a = 0; _a < subfolders.length; _a++) { var current = subfolders[_a]; - visitDirectory(ts.combinePaths(path, current)); + var name_2 = ts.combinePaths(path, current); + if (!ts.contains(exclude, getCanonicalPath(name_2))) { + visitDirectory(name_2); + } } } } @@ -839,8 +847,12 @@ var ts; } _fs.writeFileSync(fileName, data, "utf8"); } - function readDirectory(path, extension) { + function getCanonicalPath(path) { + return useCaseSensitiveFileNames ? path.toLowerCase() : path; + } + function readDirectory(path, extension, exclude) { var result = []; + exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); visitDirectory(path); return result; function visitDirectory(path) { @@ -849,14 +861,16 @@ var ts; for (var _i = 0; _i < files.length; _i++) { var current = files[_i]; var name = ts.combinePaths(path, current); - var stat = _fs.statSync(name); - if (stat.isFile()) { - if (!extension || ts.fileExtensionIs(name, extension)) { - result.push(name); + if (!ts.contains(exclude, getCanonicalPath(name))) { + var stat = _fs.statSync(name); + if (stat.isFile()) { + if (!extension || ts.fileExtensionIs(name, extension)) { + result.push(name); + } + } + else if (stat.isDirectory()) { + directories.push(name); } - } - else if (stat.isDirectory()) { - directories.push(name); } } for (var _a = 0; _a < directories.length; _a++) { @@ -1460,7 +1474,7 @@ var ts; Object_literal_s_property_0_implicitly_has_an_1_type: { code: 7018, category: ts.DiagnosticCategory.Error, key: "Object literal's property '{0}' implicitly has an '{1}' type." }, Rest_parameter_0_implicitly_has_an_any_type: { code: 7019, category: ts.DiagnosticCategory.Error, key: "Rest parameter '{0}' implicitly has an 'any[]' type." }, Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: { code: 7020, category: ts.DiagnosticCategory.Error, key: "Call signature, which lacks return-type annotation, implicitly has an 'any' return type." }, - _0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer." }, + _0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer." }, _0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: ts.DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type: { code: 7025, category: ts.DiagnosticCategory.Error, key: "Generator implicitly has type '{0}' because it does not yield any values. Consider supplying a return type." }, @@ -1642,9 +1656,9 @@ var ts; } function makeReverseMap(source) { var result = []; - for (var name_2 in source) { - if (source.hasOwnProperty(name_2)) { - result[source[name_2]] = name_2; + for (var name_3 in source) { + if (source.hasOwnProperty(name_3)) { + result[source[name_3]] = name_3; } } return result; @@ -3056,7 +3070,7 @@ var ts; var errors = []; return { options: getCompilerOptions(), - fileNames: getFiles(), + fileNames: getFileNames(), errors: errors }; function getCompilerOptions() { @@ -3100,23 +3114,24 @@ var ts; } return options; } - function getFiles() { - var files = []; + function getFileNames() { + var fileNames = []; if (ts.hasProperty(json, "files")) { if (json["files"] instanceof Array) { - var files = ts.map(json["files"], function (s) { return ts.combinePaths(basePath, s); }); + fileNames = ts.map(json["files"], function (s) { return ts.combinePaths(basePath, s); }); } } else { - var sysFiles = host.readDirectory(basePath, ".ts"); + var exclude = json["exclude"] instanceof Array ? ts.map(json["exclude"], ts.normalizeSlashes) : undefined; + var sysFiles = host.readDirectory(basePath, ".ts", exclude); for (var i = 0; i < sysFiles.length; i++) { var name = sysFiles[i]; if (!ts.fileExtensionIs(name, ".d.ts") || !ts.contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) { - files.push(name); + fileNames.push(name); } } } - return files; + return fileNames; } } ts.parseConfigFile = parseConfigFile; @@ -3536,9 +3551,9 @@ var ts; return; default: if (isFunctionLike(node)) { - var name_3 = node.name; - if (name_3 && name_3.kind === 128) { - traverse(name_3.expression); + var name_4 = node.name; + if (name_4 && name_4.kind === 128) { + traverse(name_4.expression); return; } } @@ -3948,8 +3963,8 @@ var ts; return ts.forEach(docComment.tags, function (t) { if (t.kind === 247) { var parameterTag = t; - var name_4 = parameterTag.preParameterName || parameterTag.postParameterName; - if (name_4.text === parameterName) { + var name_5 = parameterTag.preParameterName || parameterTag.postParameterName; + if (name_5.text === parameterName) { return t; } } @@ -8039,8 +8054,8 @@ var ts; return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers); } if (decorators) { - var name_5 = createMissingNode(65, true, ts.Diagnostics.Declaration_expected); - return parsePropertyDeclaration(fullStart, decorators, modifiers, name_5, undefined); + var name_6 = createMissingNode(65, true, ts.Diagnostics.Declaration_expected); + return parsePropertyDeclaration(fullStart, decorators, modifiers, name_6, undefined); } ts.Debug.fail("Should not have attempted to parse class member declaration."); } @@ -8876,13 +8891,13 @@ var ts; while (true) { skipWhitespace(); var startPos = pos; - var name_6 = scanIdentifier(); - if (!name_6) { + var name_7 = scanIdentifier(); + if (!name_7) { parseErrorAtPosition(startPos, 0, ts.Diagnostics.Identifier_expected); return undefined; } - var typeParameter = createNode(129, name_6.pos); - typeParameter.name = name_6; + var typeParameter = createNode(129, name_7.pos); + typeParameter.name = name_7; finishNode(typeParameter, pos); typeParameters.push(typeParameter); skipWhitespace(); @@ -9791,10 +9806,10 @@ var ts; var stringType = createIntrinsicType(2, "string"); var numberType = createIntrinsicType(4, "number"); var booleanType = createIntrinsicType(8, "boolean"); - var esSymbolType = createIntrinsicType(1048576, "symbol"); + var esSymbolType = createIntrinsicType(2097152, "symbol"); var voidType = createIntrinsicType(16, "void"); - var undefinedType = createIntrinsicType(32 | 262144, "undefined"); - var nullType = createIntrinsicType(64 | 262144, "null"); + var undefinedType = createIntrinsicType(32 | 524288, "undefined"); + var nullType = createIntrinsicType(64 | 524288, "null"); var unknownType = createIntrinsicType(1, "unknown"); var circularType = createIntrinsicType(1, "__circular__"); var emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); @@ -9851,7 +9866,7 @@ var ts; }, "symbol": { type: esSymbolType, - flags: 1048576 + flags: 2097152 } }; function getEmitResolver(sourceFile) { @@ -10276,15 +10291,15 @@ var ts; var moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier); var targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier); if (targetSymbol) { - var name_7 = specifier.propertyName || specifier.name; - if (name_7.text) { - var symbolFromModule = getExportOfModule(targetSymbol, name_7.text); - var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_7.text); + var name_8 = specifier.propertyName || specifier.name; + if (name_8.text) { + var symbolFromModule = getExportOfModule(targetSymbol, name_8.text); + var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_8.text); var symbol = symbolFromModule && symbolFromVariable ? combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - error(name_7, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_7)); + error(name_8, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_8)); } return symbol; } @@ -10886,13 +10901,14 @@ var ts; } return appendParentTypeArgumentsAndSymbolName(symbol); } - function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, typeStack) { + function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, symbolStack) { var globalFlagsToPass = globalFlags & 16; return writeType(type, globalFlags); function writeType(type, flags) { - if (type.flags & 1048703) { - writer.writeKeyword(!(globalFlags & 16) && - (type.flags & 1) ? "any" : type.intrinsicName); + if (type.flags & 2097279) { + writer.writeKeyword(!(globalFlags & 16) && isTypeAny(type) + ? "any" + : type.intrinsicName); } else if (type.flags & 4096) { writeTypeReference(type, flags); @@ -10989,42 +11005,46 @@ var ts; } } function writeAnonymousType(type, flags) { - if (type.symbol && type.symbol.flags & (32 | 384 | 512)) { - writeTypeofSymbol(type, flags); - } - else if (shouldWriteTypeOfFunctionSymbol()) { - writeTypeofSymbol(type, flags); - } - else if (typeStack && ts.contains(typeStack, type)) { - var typeAlias = getTypeAliasForTypeLiteral(type); - if (typeAlias) { - buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056, 0, flags); + var symbol = type.symbol; + if (symbol) { + if (symbol.flags & (32 | 384 | 512)) { + writeTypeofSymbol(type, flags); + } + else if (shouldWriteTypeOfFunctionSymbol()) { + writeTypeofSymbol(type, flags); + } + else if (ts.contains(symbolStack, symbol)) { + var typeAlias = getTypeAliasForTypeLiteral(type); + if (typeAlias) { + buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056, 0, flags); + } + else { + writeKeyword(writer, 112); + } } else { - writeKeyword(writer, 112); + if (!symbolStack) { + symbolStack = []; + } + symbolStack.push(symbol); + writeLiteralType(type, flags); + symbolStack.pop(); } } else { - if (!typeStack) { - typeStack = []; - } - typeStack.push(type); writeLiteralType(type, flags); - typeStack.pop(); } function shouldWriteTypeOfFunctionSymbol() { - if (type.symbol) { - var isStaticMethodSymbol = !!(type.symbol.flags & 8192 && - ts.forEach(type.symbol.declarations, function (declaration) { return declaration.flags & 128; })); - var isNonLocalFunctionSymbol = !!(type.symbol.flags & 16) && - (type.symbol.parent || - ts.forEach(type.symbol.declarations, function (declaration) { - return declaration.parent.kind === 228 || declaration.parent.kind === 207; - })); - if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { - return !!(flags & 2) || - (typeStack && ts.contains(typeStack, type)); - } + var isStaticMethodSymbol = !!(symbol.flags & 8192 && + ts.forEach(symbol.declarations, function (declaration) { return declaration.flags & 128; })); + var isNonLocalFunctionSymbol = !!(symbol.flags & 16) && + (symbol.parent || + ts.forEach(symbol.declarations, function (declaration) { + return declaration.parent.kind === 228 || declaration.parent.kind === 207; + })); + if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { + return !!(flags & 2) || + (ts.contains(symbolStack, symbol)); } } } @@ -11053,7 +11073,7 @@ var ts; if (flags & 64) { writePunctuation(writer, 16); } - buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, typeStack); + buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, symbolStack); if (flags & 64) { writePunctuation(writer, 17); } @@ -11065,7 +11085,7 @@ var ts; } writeKeyword(writer, 88); writeSpace(writer); - buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, typeStack); + buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, symbolStack); if (flags & 64) { writePunctuation(writer, 17); } @@ -11077,7 +11097,7 @@ var ts; writer.increaseIndent(); for (var _i = 0, _a = resolved.callSignatures; _i < _a.length; _i++) { var signature = _a[_i]; - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22); writer.writeLine(); } @@ -11085,7 +11105,7 @@ var ts; var signature = _c[_b]; writeKeyword(writer, 88); writeSpace(writer); - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22); writer.writeLine(); } @@ -11126,7 +11146,7 @@ var ts; if (p.flags & 536870912) { writePunctuation(writer, 50); } - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22); writer.writeLine(); } @@ -11153,17 +11173,17 @@ var ts; buildDisplayForTypeParametersAndDelimiters(getLocalTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); } } - function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, typeStack) { + function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, symbolStack) { appendSymbolNameOnly(tp.symbol, writer); var constraint = getConstraintOfTypeParameter(tp); if (constraint) { writeSpace(writer); writeKeyword(writer, 79); writeSpace(writer); - buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, symbolStack); } } - function buildParameterDisplay(p, writer, enclosingDeclaration, flags, typeStack) { + function buildParameterDisplay(p, writer, enclosingDeclaration, flags, symbolStack) { var parameterNode = p.valueDeclaration; if (ts.isRestParameter(parameterNode)) { writePunctuation(writer, 21); @@ -11174,9 +11194,9 @@ var ts; } writePunctuation(writer, 51); writeSpace(writer); - buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, symbolStack); } - function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, symbolStack) { if (typeParameters && typeParameters.length) { writePunctuation(writer, 24); for (var i = 0; i < typeParameters.length; i++) { @@ -11184,12 +11204,12 @@ var ts; writePunctuation(writer, 23); writeSpace(writer); } - buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, typeStack); + buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, symbolStack); } writePunctuation(writer, 25); } } - function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, symbolStack) { if (typeParameters && typeParameters.length) { writePunctuation(writer, 24); for (var i = 0; i < typeParameters.length; i++) { @@ -11202,18 +11222,18 @@ var ts; writePunctuation(writer, 25); } } - function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, symbolStack) { writePunctuation(writer, 16); for (var i = 0; i < parameters.length; i++) { if (i > 0) { writePunctuation(writer, 23); writeSpace(writer); } - buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, typeStack); + buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, symbolStack); } writePunctuation(writer, 17); } - function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack) { if (flags & 8) { writeSpace(writer); writePunctuation(writer, 32); @@ -11222,17 +11242,17 @@ var ts; writePunctuation(writer, 51); } writeSpace(writer); - buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, symbolStack); } - function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, symbolStack) { if (signature.target && (flags & 32)) { buildDisplayForTypeArgumentsAndDelimiters(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration); } else { - buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, typeStack); + buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, symbolStack); } - buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, typeStack); - buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack); + buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, symbolStack); + buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack); } return _displayBuilder || (_displayBuilder = { symbolToString: symbolToString, @@ -11426,13 +11446,16 @@ var ts; var prop = getPropertyOfType(type, name); return prop ? getTypeOfSymbol(prop) : undefined; } + function isTypeAny(type) { + return type && (type.flags & 1) !== 0; + } function getTypeForBindingElement(declaration) { var pattern = declaration.parent; var parentType = getTypeForVariableLikeDeclaration(pattern.parent); if (parentType === unknownType) { return unknownType; } - if (!parentType || parentType === anyType) { + if (!parentType || isTypeAny(parentType)) { if (declaration.initializer) { return checkExpressionCached(declaration.initializer); } @@ -11440,19 +11463,19 @@ var ts; } var type; if (pattern.kind === 151) { - var name_8 = declaration.propertyName || declaration.name; - type = getTypeOfPropertyOfType(parentType, name_8.text) || - isNumericLiteralName(name_8.text) && getIndexTypeOfType(parentType, 1) || + var name_9 = declaration.propertyName || declaration.name; + type = getTypeOfPropertyOfType(parentType, name_9.text) || + isNumericLiteralName(name_9.text) && getIndexTypeOfType(parentType, 1) || getIndexTypeOfType(parentType, 0); if (!type) { - error(name_8, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_8)); + error(name_9, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_9)); return unknownType; } } else { var elementType = checkIteratedTypeOrElementType(parentType, pattern, false); if (!declaration.dotDotDotToken) { - if (elementType.flags & 1) { + if (isTypeAny(elementType)) { return elementType; } var propName = "" + ts.indexOf(pattern.elements, declaration); @@ -11597,7 +11620,7 @@ var ts; else { type = anyType; if (compilerOptions.noImplicitAny) { - error(symbol.valueDeclaration, ts.Diagnostics._0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol)); + error(symbol.valueDeclaration, ts.Diagnostics._0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol)); } } } @@ -12207,7 +12230,7 @@ var ts; else if (type.flags & 8) { type = globalBooleanType; } - else if (type.flags & 1048576) { + else if (type.flags & 2097152) { type = globalESSymbolType; } return type; @@ -12464,7 +12487,7 @@ var ts; function getOrCreateTypeFromSignature(signature) { if (!signature.isolatedSignatureType) { var isConstructor = signature.declaration.kind === 136 || signature.declaration.kind === 140; - var type = createObjectType(32768 | 65536); + var type = createObjectType(32768 | 131072); type.members = emptySymbols; type.properties = emptyArray; type.callSignatures = !isConstructor ? [signature] : emptyArray; @@ -12538,7 +12561,7 @@ var ts; var type = types[_i]; result |= type.flags; } - return result & 786432; + return result & 1572864; } function createTypeReference(target, typeArguments) { var id = getTypeListId(typeArguments); @@ -12754,10 +12777,10 @@ var ts; } } } - function containsAnyType(types) { + function containsTypeAny(types) { for (var _i = 0; _i < types.length; _i++) { var type = types[_i]; - if (type.flags & 1) { + if (isTypeAny(type)) { return true; } } @@ -12779,7 +12802,7 @@ var ts; var sortedTypes = []; addTypesToSortedSet(sortedTypes, types); if (noSubtypeReduction) { - if (containsAnyType(sortedTypes)) { + if (containsTypeAny(sortedTypes)) { return anyType; } removeAllButLast(sortedTypes, undefinedType); @@ -12993,16 +13016,7 @@ var ts; return result; } function instantiateAnonymousType(type, mapper) { - if (mapper.mappings) { - var cached = mapper.mappings[type.id]; - if (cached) { - return cached; - } - } - else { - mapper.mappings = {}; - } - var result = createObjectType(32768, type.symbol); + var result = createObjectType(32768 | 65536, type.symbol); result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); result.members = createSymbolTable(result.properties); result.callSignatures = instantiateList(getSignaturesOfType(type, 0), mapper, instantiateSignature); @@ -13013,7 +13027,6 @@ var ts; result.stringIndexType = instantiateType(stringIndexType, mapper); if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper); - mapper.mappings[type.id] = result; return result; } function instantiateType(type, mapper) { @@ -13140,7 +13153,7 @@ var ts; if (source === target) return -1; if (relation !== identityRelation) { - if (target.flags & 1) + if (isTypeAny(target)) return -1; if (source === undefinedType) return -1; @@ -13151,7 +13164,7 @@ var ts; if (source.flags & 256 && target === stringType) return -1; if (relation === assignableRelation) { - if (source.flags & 1) + if (isTypeAny(source)) return -1; if (source === numberType && target.flags & 128) return -1; @@ -13369,12 +13382,12 @@ var ts; return result; } function isDeeplyNestedGeneric(type, stack) { - if (type.flags & 4096 && depth >= 10) { - var target_1 = type.target; + if (type.flags & (4096 | 65536) && depth >= 10) { + var symbol = type.symbol; var count = 0; for (var i = 0; i < depth; i++) { var t = stack[i]; - if (t.flags & 4096 && t.target === target_1) { + if (t.flags & (4096 | 65536) && t.symbol === symbol) { count++; if (count >= 10) return true; @@ -13389,7 +13402,7 @@ var ts; } var result = -1; var properties = getPropertiesOfObjectType(target); - var requireOptionalProperties = relation === subtypeRelation && !(source.flags & 131072); + var requireOptionalProperties = relation === subtypeRelation && !(source.flags & 262144); for (var _i = 0; _i < properties.length; _i++) { var targetProp = properties[_i]; var sourceProp = getPropertyOfType(source, targetProp.name); @@ -13488,11 +13501,11 @@ var ts; var saveErrorInfo = errorInfo; outer: for (var _i = 0; _i < targetSignatures.length; _i++) { var t = targetSignatures[_i]; - if (!t.hasStringLiterals || target.flags & 65536) { + if (!t.hasStringLiterals || target.flags & 131072) { var localErrors = reportErrors; for (var _a = 0; _a < sourceSignatures.length; _a++) { var s = sourceSignatures[_a]; - if (!s.hasStringLiterals || source.flags & 65536) { + if (!s.hasStringLiterals || source.flags & 131072) { var related = signatureRelatedTo(s, t, localErrors); if (related) { result &= related; @@ -13784,11 +13797,11 @@ var ts; return createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType); } function getWidenedType(type) { - if (type.flags & 786432) { + if (type.flags & 1572864) { if (type.flags & (32 | 64)) { return anyType; } - if (type.flags & 131072) { + if (type.flags & 262144) { return getWidenedTypeOfObjectLiteral(type); } if (type.flags & 16384) { @@ -13813,11 +13826,11 @@ var ts; if (isArrayType(type)) { return reportWideningErrorsInType(type.typeArguments[0]); } - if (type.flags & 131072) { + if (type.flags & 262144) { var errorReported = false; ts.forEach(getPropertiesOfObjectType(type), function (p) { var t = getTypeOfSymbol(p); - if (t.flags & 262144) { + if (t.flags & 524288) { if (!reportWideningErrorsInType(t)) { error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(getWidenedType(t))); } @@ -13860,7 +13873,7 @@ var ts; error(declaration, diagnostic, ts.declarationNameToString(declaration.name), typeAsString); } function reportErrorsFromWidening(declaration, type) { - if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 262144) { + if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 524288) { if (!reportWideningErrorsInType(type)) { reportImplicitAnyError(declaration, type); } @@ -13921,11 +13934,11 @@ var ts; } function isWithinDepthLimit(type, stack) { if (depth >= 5) { - var target_2 = type.target; + var target_1 = type.target; var count = 0; for (var i = 0; i < depth; i++) { var t = stack[i]; - if (t.flags & 4096 && t.target === target_2) { + if (t.flags & 4096 && t.target === target_1) { count++; } } @@ -14221,47 +14234,49 @@ var ts; } function getNarrowedTypeOfSymbol(symbol, node) { var type = getTypeOfSymbol(symbol); - if (node && symbol.flags & 3 && type.flags & (1 | 48128 | 16384 | 512)) { - loop: while (node.parent) { - var child = node; - node = node.parent; - var narrowedType = type; - switch (node.kind) { - case 184: - if (child !== node.expression) { - narrowedType = narrowType(type, node.expression, child === node.thenStatement); - } - break; - case 171: - if (child !== node.condition) { - narrowedType = narrowType(type, node.condition, child === node.whenTrue); - } - break; - case 170: - if (child === node.right) { - if (node.operatorToken.kind === 48) { - narrowedType = narrowType(type, node.left, true); + if (node && symbol.flags & 3) { + if (isTypeAny(type) || type.flags & (48128 | 16384 | 512)) { + loop: while (node.parent) { + var child = node; + node = node.parent; + var narrowedType = type; + switch (node.kind) { + case 184: + if (child !== node.expression) { + narrowedType = narrowType(type, node.expression, child === node.thenStatement); } - else if (node.operatorToken.kind === 49) { - narrowedType = narrowType(type, node.left, false); + break; + case 171: + if (child !== node.condition) { + narrowedType = narrowType(type, node.condition, child === node.whenTrue); } - } - break; - case 228: - case 206: - case 201: - case 135: - case 134: - case 137: - case 138: - case 136: - break loop; - } - if (narrowedType !== type) { - if (isVariableAssignedWithin(symbol, node)) { - break; + break; + case 170: + if (child === node.right) { + if (node.operatorToken.kind === 48) { + narrowedType = narrowType(type, node.left, true); + } + else if (node.operatorToken.kind === 49) { + narrowedType = narrowType(type, node.left, false); + } + } + break; + case 228: + case 206: + case 201: + case 135: + case 134: + case 137: + case 138: + case 136: + break loop; + } + if (narrowedType !== type) { + if (isVariableAssignedWithin(symbol, node)) { + break; + } + type = narrowedType; } - type = narrowedType; } } } @@ -14281,7 +14296,7 @@ var ts; } if (assumeTrue) { if (!typeInfo) { - return removeTypesFromUnionType(type, 258 | 132 | 8 | 1048576, true, false); + return removeTypesFromUnionType(type, 258 | 132 | 8 | 2097152, true, false); } if (isTypeSubtypeOf(typeInfo.type, type)) { return typeInfo.type; @@ -14318,7 +14333,7 @@ var ts; } } function narrowTypeByInstanceof(type, expr, assumeTrue) { - if (type.flags & 1 || !assumeTrue || expr.left.kind !== 65 || getResolvedSymbol(expr.left) !== symbol) { + if (isTypeAny(type) || !assumeTrue || expr.left.kind !== 65 || getResolvedSymbol(expr.left) !== symbol) { return type; } var rightType = checkExpression(expr.right); @@ -14329,7 +14344,7 @@ var ts; var prototypeProperty = getPropertyOfType(rightType, "prototype"); if (prototypeProperty) { var prototypePropertyType = getTypeOfSymbol(prototypeProperty); - if (prototypePropertyType !== anyType) { + if (!isTypeAny(prototypePropertyType)) { targetType = prototypePropertyType; } } @@ -14900,7 +14915,10 @@ var ts; return name.kind === 128 ? isNumericComputedName(name) : isNumericLiteralName(name.text); } function isNumericComputedName(name) { - return allConstituentTypesHaveKind(checkComputedPropertyName(name), 1 | 132); + return isTypeAnyOrAllConstituentTypesHaveKind(checkComputedPropertyName(name), 132); + } + function isTypeAnyOrAllConstituentTypesHaveKind(type, kind) { + return isTypeAny(type) || allConstituentTypesHaveKind(type, kind); } function isNumericLiteralName(name) { return (+name).toString() === name; @@ -14909,7 +14927,7 @@ var ts; var links = getNodeLinks(node.expression); if (!links.resolvedType) { links.resolvedType = checkExpression(node.expression); - if (!allConstituentTypesHaveKind(links.resolvedType, 1 | 132 | 258 | 1048576)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(links.resolvedType, 132 | 258 | 2097152)) { error(node, ts.Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any); } else { @@ -14964,7 +14982,7 @@ var ts; var stringIndexType = getIndexType(0); var numberIndexType = getIndexType(1); var result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType); - result.flags |= 131072 | 524288 | (typeFlags & 262144); + result.flags |= 262144 | 1048576 | (typeFlags & 524288); return result; function getIndexType(kind) { if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { @@ -15027,39 +15045,37 @@ var ts; } function checkPropertyAccessExpressionOrQualifiedName(node, left, right) { var type = checkExpressionOrQualifiedName(left); - if (type === unknownType) + if (isTypeAny(type)) { return type; - if (type !== anyType) { - var apparentType = getApparentType(getWidenedType(type)); - if (apparentType === unknownType) { - return unknownType; - } - var prop = getPropertyOfType(apparentType, right.text); - if (!prop) { - if (right.text) { - error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type)); - } - return unknownType; - } - getNodeLinks(node).resolvedSymbol = prop; - if (prop.parent && prop.parent.flags & 32) { - if (left.kind === 91 && getDeclarationKindFromSymbol(prop) !== 135) { - error(right, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); - } - else { - checkClassPropertyAccess(node, left, type, prop); - } - } - return getTypeOfSymbol(prop); } - return anyType; + var apparentType = getApparentType(getWidenedType(type)); + if (apparentType === unknownType) { + return unknownType; + } + var prop = getPropertyOfType(apparentType, right.text); + if (!prop) { + if (right.text) { + error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type)); + } + return unknownType; + } + getNodeLinks(node).resolvedSymbol = prop; + if (prop.parent && prop.parent.flags & 32) { + if (left.kind === 91 && getDeclarationKindFromSymbol(prop) !== 135) { + error(right, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); + } + else { + checkClassPropertyAccess(node, left, type, prop); + } + } + return getTypeOfSymbol(prop); } function isValidPropertyAccess(node, propertyName) { var left = node.kind === 156 ? node.expression : node.left; var type = checkExpressionOrQualifiedName(left); - if (type !== unknownType && type !== anyType) { + if (type !== unknownType && !isTypeAny(type)) { var prop = getPropertyOfType(getWidenedType(type), propertyName); if (prop && prop.parent && prop.parent.flags & 32) { if (left.kind === 91 && getDeclarationKindFromSymbol(prop) !== 135) { @@ -15100,21 +15116,21 @@ var ts; return unknownType; } if (node.argumentExpression) { - var name_9 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); - if (name_9 !== undefined) { - var prop = getPropertyOfType(objectType, name_9); + var name_10 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); + if (name_10 !== undefined) { + var prop = getPropertyOfType(objectType, name_10); if (prop) { getNodeLinks(node).resolvedSymbol = prop; return getTypeOfSymbol(prop); } else if (isConstEnum) { - error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_9, symbolToString(objectType.symbol)); + error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_10, symbolToString(objectType.symbol)); return unknownType; } } } - if (allConstituentTypesHaveKind(indexType, 1 | 258 | 132 | 1048576)) { - if (allConstituentTypesHaveKind(indexType, 1 | 132)) { + if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, 258 | 132 | 2097152)) { + if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, 132)) { var numberIndexType = getIndexTypeOfType(objectType, 1); if (numberIndexType) { return numberIndexType; @@ -15124,7 +15140,7 @@ var ts; if (stringIndexType) { return stringIndexType; } - if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && objectType !== anyType) { + if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && !isTypeAny(objectType)) { error(node, ts.Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type); } return anyType; @@ -15149,7 +15165,7 @@ var ts; if (!ts.isWellKnownSymbolSyntactically(expression)) { return false; } - if ((expressionType.flags & 1048576) === 0) { + if ((expressionType.flags & 2097152) === 0) { if (reportError) { error(expression, ts.Diagnostics.A_computed_property_name_of_the_form_0_must_be_of_type_symbol, ts.getTextOfNode(expression)); } @@ -15531,8 +15547,8 @@ var ts; } var callSignatures = getSignaturesOfType(apparentType, 0); var constructSignatures = getSignaturesOfType(apparentType, 1); - if (funcType === anyType || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384) && isTypeAssignableTo(funcType, globalFunctionType))) { - if (node.typeArguments) { + if (isTypeAny(funcType) || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384) && isTypeAssignableTo(funcType, globalFunctionType))) { + if (funcType !== unknownType && node.typeArguments) { error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } return resolveUntypedCall(node); @@ -15556,16 +15572,16 @@ var ts; } } var expressionType = checkExpression(node.expression); - if (expressionType === anyType) { + expressionType = getApparentType(expressionType); + if (expressionType === unknownType) { + return resolveErrorCall(node); + } + if (isTypeAny(expressionType)) { if (node.typeArguments) { error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } return resolveUntypedCall(node); } - expressionType = getApparentType(expressionType); - if (expressionType === unknownType) { - return resolveErrorCall(node); - } var constructSignatures = getSignaturesOfType(expressionType, 1); if (constructSignatures.length) { return resolveCall(node, constructSignatures, candidatesOutArray); @@ -15588,7 +15604,7 @@ var ts; return resolveErrorCall(node); } var callSignatures = getSignaturesOfType(apparentType, 0); - if (tagType === anyType || (!callSignatures.length && !(tagType.flags & 16384) && isTypeAssignableTo(tagType, globalFunctionType))) { + if (isTypeAny(tagType) || (!callSignatures.length && !(tagType.flags & 16384) && isTypeAssignableTo(tagType, globalFunctionType))) { return resolveUntypedCall(node); } if (!callSignatures.length) { @@ -15757,7 +15773,7 @@ var ts; if (!produceDiagnostics) { return; } - if (returnType === voidType || returnType === anyType) { + if (returnType === voidType || isTypeAny(returnType)) { return; } if (ts.nodeIsMissing(func.body) || func.body.kind !== 180) { @@ -15830,7 +15846,7 @@ var ts; } } function checkArithmeticOperandType(operand, type, diagnostic) { - if (!allConstituentTypesHaveKind(type, 1 | 132)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(type, 132)) { error(operand, diagnostic); return false; } @@ -15870,8 +15886,8 @@ var ts; var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 8) { - var name_10 = index.text; - var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_10); + var name_11 = index.text; + var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_11); return prop && (prop.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 8192) !== 0; } return false; @@ -15916,7 +15932,7 @@ var ts; case 33: case 34: case 47: - if (someConstituentTypeHasKind(operandType, 1048576)) { + if (someConstituentTypeHasKind(operandType, 2097152)) { error(node.operand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(node.operator)); } return numberType; @@ -15980,19 +15996,19 @@ var ts; return (symbol.flags & 128) !== 0; } function checkInstanceOfExpression(node, leftType, rightType) { - if (allConstituentTypesHaveKind(leftType, 1049086)) { + if (allConstituentTypesHaveKind(leftType, 2097662)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } - if (!(rightType.flags & 1 || isTypeSubtypeOf(rightType, globalFunctionType))) { + if (!(isTypeAny(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type); } return booleanType; } function checkInExpression(node, leftType, rightType) { - if (!allConstituentTypesHaveKind(leftType, 1 | 258 | 132 | 1048576)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258 | 132 | 2097152)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); } - if (!allConstituentTypesHaveKind(rightType, 1 | 48128 | 512)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 48128 | 512)) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; @@ -16002,16 +16018,17 @@ var ts; for (var _i = 0; _i < properties.length; _i++) { var p = properties[_i]; if (p.kind === 225 || p.kind === 226) { - var name_11 = p.name; - var type = sourceType.flags & 1 ? sourceType : - getTypeOfPropertyOfType(sourceType, name_11.text) || - isNumericLiteralName(name_11.text) && getIndexTypeOfType(sourceType, 1) || + var name_12 = p.name; + var type = isTypeAny(sourceType) + ? sourceType + : getTypeOfPropertyOfType(sourceType, name_12.text) || + isNumericLiteralName(name_12.text) && getIndexTypeOfType(sourceType, 1) || getIndexTypeOfType(sourceType, 0); if (type) { - checkDestructuringAssignment(p.initializer || name_11, type); + checkDestructuringAssignment(p.initializer || name_12, type); } else { - error(name_11, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_11)); + error(name_12, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_12)); } } else { @@ -16028,8 +16045,9 @@ var ts; if (e.kind !== 176) { if (e.kind !== 174) { var propName = "" + i; - var type = sourceType.flags & 1 ? sourceType : - isTupleLikeType(sourceType) + var type = isTypeAny(sourceType) + ? sourceType + : isTupleLikeType(sourceType) ? getTypeOfPropertyOfType(sourceType, propName) : elementType; if (type) { @@ -16145,8 +16163,8 @@ var ts; if (allConstituentTypesHaveKind(leftType, 258) || allConstituentTypesHaveKind(rightType, 258)) { resultType = stringType; } - else if (leftType.flags & 1 || rightType.flags & 1) { - resultType = anyType; + else if (isTypeAny(leftType) || isTypeAny(rightType)) { + resultType = leftType === unknownType || rightType === unknownType ? unknownType : anyType; } if (resultType && !checkForDisallowedESSymbolOperand(operator)) { return resultType; @@ -16190,8 +16208,8 @@ var ts; return rightType; } function checkForDisallowedESSymbolOperand(operator) { - var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 1048576) ? node.left : - someConstituentTypeHasKind(rightType, 1048576) ? node.right : + var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 2097152) ? node.left : + someConstituentTypeHasKind(rightType, 2097152) ? node.right : undefined; if (offendingSymbolOperand) { error(offendingSymbolOperand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(operator)); @@ -16970,7 +16988,7 @@ var ts; if (node && node.kind === 142) { var type = getTypeFromTypeNode(node); var shouldCheckIfUnknownType = type === unknownType && compilerOptions.isolatedModules; - if (!type || (!shouldCheckIfUnknownType && type.flags & (1048703 | 132 | 258))) { + if (!type || (!shouldCheckIfUnknownType && type.flags & (2097279 | 132 | 258))) { return; } if (shouldCheckIfUnknownType || type.symbol.valueDeclaration) { @@ -17198,8 +17216,8 @@ var ts; container.kind === 206 || container.kind === 228); if (!namesShareScope) { - var name_12 = symbolToString(localDeclarationSymbol); - error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_12, name_12); + var name_13 = symbolToString(localDeclarationSymbol); + error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_13, name_13); } } } @@ -17386,7 +17404,7 @@ var ts; if (varExpr.kind === 154 || varExpr.kind === 155) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); } - else if (!allConstituentTypesHaveKind(leftType, 1 | 258)) { + else if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258)) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any); } else { @@ -17394,7 +17412,7 @@ var ts; } } var rightType = checkExpression(node.expression); - if (!allConstituentTypesHaveKind(rightType, 1 | 48128 | 512)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 48128 | 512)) { error(node.expression, ts.Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } checkSourceElement(node.statement); @@ -17411,7 +17429,7 @@ var ts; return checkIteratedTypeOrElementType(expressionType, rhsExpression, true); } function checkIteratedTypeOrElementType(inputType, errorNode, allowStringInput) { - if (inputType.flags & 1) { + if (isTypeAny(inputType)) { return inputType; } if (languageVersion >= 2) { @@ -17437,7 +17455,7 @@ var ts; return elementType || anyType; } function getElementTypeOfIterable(type, errorNode) { - if (type.flags & 1) { + if (isTypeAny(type)) { return undefined; } var typeAsIterable = type; @@ -17447,7 +17465,7 @@ var ts; } else { var iteratorFunction = getTypeOfPropertyOfType(type, ts.getPropertyNameForKnownSymbolName("iterator")); - if (iteratorFunction && iteratorFunction.flags & 1) { + if (isTypeAny(iteratorFunction)) { return undefined; } var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0) : emptyArray; @@ -17463,7 +17481,7 @@ var ts; return typeAsIterable.iterableElementType; } function getElementTypeOfIterator(type, errorNode) { - if (type.flags & 1) { + if (isTypeAny(type)) { return undefined; } var typeAsIterator = type; @@ -17473,7 +17491,7 @@ var ts; } else { var iteratorNextFunction = getTypeOfPropertyOfType(type, "next"); - if (iteratorNextFunction && iteratorNextFunction.flags & 1) { + if (isTypeAny(iteratorNextFunction)) { return undefined; } var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0) : emptyArray; @@ -17484,7 +17502,7 @@ var ts; return undefined; } var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); - if (iteratorNextResult.flags & 1) { + if (isTypeAny(iteratorNextResult)) { return undefined; } var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value"); @@ -17500,7 +17518,7 @@ var ts; return typeAsIterator.iteratorElementType; } function getElementTypeOfIterableIterator(type) { - if (type.flags & 1) { + if (isTypeAny(type)) { return undefined; } if ((type.flags & 4096) && type.target === globalIterableIteratorType) { @@ -18979,9 +18997,9 @@ var ts; function getRootSymbols(symbol) { if (symbol.flags & 268435456) { var symbols = []; - var name_13 = symbol.name; + var name_14 = symbol.name; ts.forEach(getSymbolLinks(symbol).unionType.types, function (t) { - symbols.push(getPropertyOfType(t, name_13)); + symbols.push(getPropertyOfType(t, name_14)); }); return symbols; } @@ -19159,7 +19177,7 @@ var ts; else if (type.flags & 8192) { return "Array"; } - else if (type.flags & 1048576) { + else if (type.flags & 2097152) { return "Symbol"; } else if (type === unknownType) { @@ -19404,20 +19422,20 @@ var ts; if (impotClause.namedBindings) { var nameBindings = impotClause.namedBindings; if (nameBindings.kind === 212) { - var name_14 = nameBindings.name; - if (isReservedWordInStrictMode(name_14)) { - var nameText = ts.declarationNameToString(name_14); - return grammarErrorOnNode(name_14, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_15 = nameBindings.name; + if (isReservedWordInStrictMode(name_15)) { + var nameText = ts.declarationNameToString(name_15); + return grammarErrorOnNode(name_15, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } else if (nameBindings.kind === 213) { var reportError = false; for (var _i = 0, _a = nameBindings.elements; _i < _a.length; _i++) { var element = _a[_i]; - var name_15 = element.name; - if (isReservedWordInStrictMode(name_15)) { - var nameText = ts.declarationNameToString(name_15); - reportError = reportError || grammarErrorOnNode(name_15, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_16 = element.name; + if (isReservedWordInStrictMode(name_16)) { + var nameText = ts.declarationNameToString(name_16); + reportError = reportError || grammarErrorOnNode(name_16, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } return reportError; @@ -19876,17 +19894,17 @@ var ts; var inStrictMode = (node.parserContextFlags & 1) !== 0; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - var name_16 = prop.name; + var name_17 = prop.name; if (prop.kind === 176 || - name_16.kind === 128) { - checkGrammarComputedPropertyName(name_16); + name_17.kind === 128) { + checkGrammarComputedPropertyName(name_17); continue; } var currentKind = void 0; if (prop.kind === 225 || prop.kind === 226) { checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); - if (name_16.kind === 7) { - checkGrammarNumericLiteral(name_16); + if (name_17.kind === 7) { + checkGrammarNumericLiteral(name_17); } currentKind = Property; } @@ -19902,26 +19920,26 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_16.text)) { - seen[name_16.text] = currentKind; + if (!ts.hasProperty(seen, name_17.text)) { + seen[name_17.text] = currentKind; } else { - var existingKind = seen[name_16.text]; + var existingKind = seen[name_17.text]; if (currentKind === Property && existingKind === Property) { if (inStrictMode) { - grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); + grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); } } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_16.text] = currentKind | existingKind; + seen[name_17.text] = currentKind | existingKind; } else { - return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + return grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); } } else { - return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + return grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); } } } @@ -20700,9 +20718,9 @@ var ts; } var count = 0; while (true) { - var name_17 = baseName + "_" + (++count); - if (!ts.hasProperty(currentSourceFile.identifiers, name_17)) { - return name_17; + var name_18 = baseName + "_" + (++count); + if (!ts.hasProperty(currentSourceFile.identifiers, name_18)) { + return name_18; } } } @@ -21786,9 +21804,9 @@ var ts; var count = tempFlags & 268435455; tempFlags++; if (count !== 8 && count !== 13) { - var name_18 = count < 26 ? "_" + String.fromCharCode(97 + count) : "_" + (count - 26); - if (isUniqueName(name_18)) { - return name_18; + var name_19 = count < 26 ? "_" + String.fromCharCode(97 + count) : "_" + (count - 26); + if (isUniqueName(name_19)) { + return name_19; } } } @@ -21816,8 +21834,8 @@ var ts; } function generateNameForModuleOrEnum(node) { if (node.name.kind === 65) { - var name_19 = node.name.text; - assignGeneratedName(node, isUniqueLocalName(name_19, node) ? name_19 : makeUniqueName(name_19)); + var name_20 = node.name.text; + assignGeneratedName(node, isUniqueLocalName(name_20, node) ? name_20 : makeUniqueName(name_20)); } } function generateNameForImportOrExportDeclaration(node) { @@ -22003,8 +22021,8 @@ var ts; if (scopeName) { var parentIndex = getSourceMapNameIndex(); if (parentIndex !== -1) { - var name_20 = node.name; - if (!name_20 || name_20.kind !== 128) { + var name_21 = node.name; + if (!name_21 || name_21.kind !== 128) { scopeName = "." + scopeName; } scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; @@ -22031,9 +22049,9 @@ var ts; node.kind === 202 || node.kind === 205) { if (node.name) { - var name_21 = node.name; - scopeName = name_21.kind === 128 - ? ts.getTextOfNode(name_21) + var name_22 = node.name; + scopeName = name_22.kind === 128 + ? ts.getTextOfNode(name_22) : node.name.text; } recordScopeNameStart(scopeName); @@ -22883,7 +22901,12 @@ var ts; return result; } function parenthesizeForAccess(expr) { - if (ts.isLeftHandSideExpression(expr) && expr.kind !== 159 && expr.kind !== 7) { + while (expr.kind === 161) { + expr = expr.expression; + } + if (ts.isLeftHandSideExpression(expr) && + expr.kind !== 159 && + expr.kind !== 7) { return expr; } var node = ts.createSynthesizedNode(162); @@ -23104,7 +23127,7 @@ var ts; } } function emitParenExpression(node) { - if (!node.parent || node.parent.kind !== 164) { + if (!ts.nodeIsSynthesized(node) && node.parent.kind !== 164) { if (node.expression.kind === 161) { var operand = node.expression.expression; while (operand.kind == 161) { @@ -24060,12 +24083,12 @@ var ts; function emitParameter(node) { if (languageVersion < 2) { if (ts.isBindingPattern(node.name)) { - var name_22 = createTempVariable(0); + var name_23 = createTempVariable(0); if (!tempParameters) { tempParameters = []; } - tempParameters.push(name_22); - emit(name_22); + tempParameters.push(name_23); + emit(name_23); } else { emit(node.name); @@ -25525,8 +25548,8 @@ var ts; else { for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { var specifier = _d[_c]; - var name_23 = (specifier.propertyName || specifier.name).text; - (exportSpecifiers[name_23] || (exportSpecifiers[name_23] = [])).push(specifier); + var name_24 = (specifier.propertyName || specifier.name).text; + (exportSpecifiers[name_24] || (exportSpecifiers[name_24] = [])).push(specifier); } } break; @@ -25699,11 +25722,11 @@ var ts; var seen = {}; for (var i = 0; i < hoistedVars.length; ++i) { var local = hoistedVars[i]; - var name_24 = local.kind === 65 + var name_25 = local.kind === 65 ? local : local.name; - if (name_24) { - var text = ts.unescapeIdentifier(name_24.text); + if (name_25) { + var text = ts.unescapeIdentifier(name_25.text); if (ts.hasProperty(seen, text)) { continue; } @@ -25782,15 +25805,15 @@ var ts; } if (node.kind === 199 || node.kind === 153) { if (shouldHoistVariable(node, false)) { - var name_25 = node.name; - if (name_25.kind === 65) { + var name_26 = node.name; + if (name_26.kind === 65) { if (!hoistedVars) { hoistedVars = []; } - hoistedVars.push(name_25); + hoistedVars.push(name_26); } else { - ts.forEachChild(name_25, visit); + ts.forEachChild(name_26, visit); } } return; @@ -27499,10 +27522,10 @@ var ts; ts.forEach(program.getSourceFiles(), function (sourceFile) { cancellationToken.throwIfCancellationRequested(); var nameToDeclarations = sourceFile.getNamedDeclarations(); - for (var name_26 in nameToDeclarations) { - var declarations = ts.getProperty(nameToDeclarations, name_26); + for (var name_27 in nameToDeclarations) { + var declarations = ts.getProperty(nameToDeclarations, name_27); if (declarations) { - var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_26); + var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_27); if (!matches) { continue; } @@ -27513,14 +27536,14 @@ var ts; if (!containers) { return undefined; } - matches = patternMatcher.getMatches(containers, name_26); + matches = patternMatcher.getMatches(containers, name_27); if (!matches) { continue; } } var fileName = sourceFile.fileName; var matchKind = bestMatchKind(matches); - rawItems.push({ name: name_26, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); + rawItems.push({ name: name_27, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); } } } @@ -27850,9 +27873,9 @@ var ts; case 199: case 153: var variableDeclarationNode; - var name_27; + var name_28; if (node.kind === 153) { - name_27 = node.name; + name_28 = node.name; variableDeclarationNode = node; while (variableDeclarationNode && variableDeclarationNode.kind !== 199) { variableDeclarationNode = variableDeclarationNode.parent; @@ -27862,16 +27885,16 @@ var ts; else { ts.Debug.assert(!ts.isBindingPattern(node.name)); variableDeclarationNode = node; - name_27 = node.name; + name_28 = node.name; } if (ts.isConst(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.constElement); + return createItem(node, getTextOfNode(name_28), ts.ScriptElementKind.constElement); } else if (ts.isLet(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.letElement); + return createItem(node, getTextOfNode(name_28), ts.ScriptElementKind.letElement); } else { - return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.variableElement); + return createItem(node, getTextOfNode(name_28), ts.ScriptElementKind.variableElement); } case 136: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); @@ -29865,9 +29888,9 @@ var ts; } Rules.prototype.getRuleName = function (rule) { var o = this; - for (var name_28 in o) { - if (o[name_28] === rule) { - return name_28; + for (var name_29 in o) { + if (o[name_29] === rule) { + return name_29; } } throw new Error("Unknown rule"); @@ -33612,10 +33635,10 @@ var ts; for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { var sourceFile = _a[_i]; var nameTable = getNameTable(sourceFile); - for (var name_29 in nameTable) { - if (!allNames[name_29]) { - allNames[name_29] = name_29; - var displayName = getCompletionEntryDisplayName(name_29, target, true); + for (var name_30 in nameTable) { + if (!allNames[name_30]) { + allNames[name_30] = name_30; + var displayName = getCompletionEntryDisplayName(name_30, target, true); if (displayName) { var entry = { name: displayName, @@ -35294,17 +35317,17 @@ var ts; if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; var contextualType = typeChecker.getContextualType(objectLiteral); - var name_30 = node.text; + var name_31 = node.text; if (contextualType) { if (contextualType.flags & 16384) { - var unionProperty = contextualType.getProperty(name_30); + var unionProperty = contextualType.getProperty(name_31); if (unionProperty) { return [unionProperty]; } else { var result_4 = []; ts.forEach(contextualType.types, function (t) { - var symbol = t.getProperty(name_30); + var symbol = t.getProperty(name_31); if (symbol) { result_4.push(symbol); } @@ -35313,7 +35336,7 @@ var ts; } } else { - var symbol_1 = contextualType.getProperty(name_30); + var symbol_1 = contextualType.getProperty(name_31); if (symbol_1) { return [symbol_1]; } diff --git a/bin/typescript.d.ts b/bin/typescript.d.ts index 58b03102d38..c8e4ae8bc69 100644 --- a/bin/typescript.d.ts +++ b/bin/typescript.d.ts @@ -857,7 +857,7 @@ declare module "typescript" { getCurrentDirectory(): string; } interface ParseConfigHost { - readDirectory(rootDir: string, extension: string): string[]; + readDirectory(rootDir: string, extension: string, exclude: string[]): string[]; } interface WriteFileCallback { (fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void; @@ -1091,8 +1091,9 @@ declare module "typescript" { Tuple = 8192, Union = 16384, Anonymous = 32768, - ObjectLiteral = 131072, - ESSymbol = 1048576, + Instantiated = 65536, + ObjectLiteral = 262144, + ESSymbol = 2097152, StringLike = 258, NumberLike = 132, ObjectType = 48128, @@ -1281,7 +1282,7 @@ declare module "typescript" { createDirectory(path: string): void; getExecutingFilePath(): string; getCurrentDirectory(): string; - readDirectory(path: string, extension?: string): string[]; + readDirectory(path: string, extension?: string, exclude?: string[]): string[]; getMemoryUsage?(): number; exit(exitCode?: number): void; } diff --git a/bin/typescript.js b/bin/typescript.js index 5875495d5e6..3dd6dd919be 100644 --- a/bin/typescript.js +++ b/bin/typescript.js @@ -532,23 +532,24 @@ var ts; TypeFlags[TypeFlags["Tuple"] = 8192] = "Tuple"; TypeFlags[TypeFlags["Union"] = 16384] = "Union"; TypeFlags[TypeFlags["Anonymous"] = 32768] = "Anonymous"; + TypeFlags[TypeFlags["Instantiated"] = 65536] = "Instantiated"; /* @internal */ - TypeFlags[TypeFlags["FromSignature"] = 65536] = "FromSignature"; - TypeFlags[TypeFlags["ObjectLiteral"] = 131072] = "ObjectLiteral"; + TypeFlags[TypeFlags["FromSignature"] = 131072] = "FromSignature"; + TypeFlags[TypeFlags["ObjectLiteral"] = 262144] = "ObjectLiteral"; /* @internal */ - TypeFlags[TypeFlags["ContainsUndefinedOrNull"] = 262144] = "ContainsUndefinedOrNull"; + TypeFlags[TypeFlags["ContainsUndefinedOrNull"] = 524288] = "ContainsUndefinedOrNull"; /* @internal */ - TypeFlags[TypeFlags["ContainsObjectLiteral"] = 524288] = "ContainsObjectLiteral"; - TypeFlags[TypeFlags["ESSymbol"] = 1048576] = "ESSymbol"; + TypeFlags[TypeFlags["ContainsObjectLiteral"] = 1048576] = "ContainsObjectLiteral"; + TypeFlags[TypeFlags["ESSymbol"] = 2097152] = "ESSymbol"; /* @internal */ - TypeFlags[TypeFlags["Intrinsic"] = 1048703] = "Intrinsic"; + TypeFlags[TypeFlags["Intrinsic"] = 2097279] = "Intrinsic"; /* @internal */ - TypeFlags[TypeFlags["Primitive"] = 1049086] = "Primitive"; + TypeFlags[TypeFlags["Primitive"] = 2097662] = "Primitive"; TypeFlags[TypeFlags["StringLike"] = 258] = "StringLike"; TypeFlags[TypeFlags["NumberLike"] = 132] = "NumberLike"; TypeFlags[TypeFlags["ObjectType"] = 48128] = "ObjectType"; /* @internal */ - TypeFlags[TypeFlags["RequiresWidening"] = 786432] = "RequiresWidening"; + TypeFlags[TypeFlags["RequiresWidening"] = 1572864] = "RequiresWidening"; })(ts.TypeFlags || (ts.TypeFlags = {})); var TypeFlags = ts.TypeFlags; (function (SignatureKind) { @@ -1506,6 +1507,9 @@ var ts; fileStream.Close(); } } + function getCanonicalPath(path) { + return path.toLowerCase(); + } function getNames(collection) { var result = []; for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) { @@ -1513,23 +1517,28 @@ var ts; } return result.sort(); } - function readDirectory(path, extension) { + function readDirectory(path, extension, exclude) { var result = []; + exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); visitDirectory(path); return result; function visitDirectory(path) { var folder = fso.GetFolder(path || "."); var files = getNames(folder.files); for (var _i = 0; _i < files.length; _i++) { - var name_1 = files[_i]; - if (!extension || ts.fileExtensionIs(name_1, extension)) { - result.push(ts.combinePaths(path, name_1)); + var current = files[_i]; + var name_1 = ts.combinePaths(path, current); + if ((!extension || ts.fileExtensionIs(name_1, extension)) && !ts.contains(exclude, getCanonicalPath(name_1))) { + result.push(name_1); } } var subfolders = getNames(folder.subfolders); for (var _a = 0; _a < subfolders.length; _a++) { var current = subfolders[_a]; - visitDirectory(ts.combinePaths(path, current)); + var name_2 = ts.combinePaths(path, current); + if (!ts.contains(exclude, getCanonicalPath(name_2))) { + visitDirectory(name_2); + } } } } @@ -1614,8 +1623,12 @@ var ts; } _fs.writeFileSync(fileName, data, "utf8"); } - function readDirectory(path, extension) { + function getCanonicalPath(path) { + return useCaseSensitiveFileNames ? path.toLowerCase() : path; + } + function readDirectory(path, extension, exclude) { var result = []; + exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); visitDirectory(path); return result; function visitDirectory(path) { @@ -1624,14 +1637,16 @@ var ts; for (var _i = 0; _i < files.length; _i++) { var current = files[_i]; var name = ts.combinePaths(path, current); - var stat = _fs.statSync(name); - if (stat.isFile()) { - if (!extension || ts.fileExtensionIs(name, extension)) { - result.push(name); + if (!ts.contains(exclude, getCanonicalPath(name))) { + var stat = _fs.statSync(name); + if (stat.isFile()) { + if (!extension || ts.fileExtensionIs(name, extension)) { + result.push(name); + } + } + else if (stat.isDirectory()) { + directories.push(name); } - } - else if (stat.isDirectory()) { - directories.push(name); } } for (var _a = 0; _a < directories.length; _a++) { @@ -2239,7 +2254,7 @@ var ts; Object_literal_s_property_0_implicitly_has_an_1_type: { code: 7018, category: ts.DiagnosticCategory.Error, key: "Object literal's property '{0}' implicitly has an '{1}' type." }, Rest_parameter_0_implicitly_has_an_any_type: { code: 7019, category: ts.DiagnosticCategory.Error, key: "Rest parameter '{0}' implicitly has an 'any[]' type." }, Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: { code: 7020, category: ts.DiagnosticCategory.Error, key: "Call signature, which lacks return-type annotation, implicitly has an 'any' return type." }, - _0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer." }, + _0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer." }, _0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: ts.DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type: { code: 7025, category: ts.DiagnosticCategory.Error, key: "Generator implicitly has type '{0}' because it does not yield any values. Consider supplying a return type." }, @@ -2466,9 +2481,9 @@ var ts; } function makeReverseMap(source) { var result = []; - for (var name_2 in source) { - if (source.hasOwnProperty(name_2)) { - result[source[name_2]] = name_2; + for (var name_3 in source) { + if (source.hasOwnProperty(name_3)) { + result[source[name_3]] = name_3; } } return result; @@ -4815,11 +4830,11 @@ var ts; return; default: if (isFunctionLike(node)) { - var name_3 = node.name; - if (name_3 && name_3.kind === 128 /* ComputedPropertyName */) { + var name_4 = node.name; + if (name_4 && name_4.kind === 128 /* ComputedPropertyName */) { // Note that we will not include methods/accessors of a class because they would require // first descending into the class. This is by design. - traverse(name_3.expression); + traverse(name_4.expression); return; } } @@ -5268,8 +5283,8 @@ var ts; return ts.forEach(docComment.tags, function (t) { if (t.kind === 247 /* JSDocParameterTag */) { var parameterTag = t; - var name_4 = parameterTag.preParameterName || parameterTag.postParameterName; - if (name_4.text === parameterName) { + var name_5 = parameterTag.preParameterName || parameterTag.postParameterName; + if (name_5.text === parameterName) { return t; } } @@ -10289,8 +10304,8 @@ var ts; } if (decorators) { // treat this as a property declaration with a missing name. - var name_5 = createMissingNode(65 /* Identifier */, true, ts.Diagnostics.Declaration_expected); - return parsePropertyDeclaration(fullStart, decorators, modifiers, name_5, undefined); + var name_6 = createMissingNode(65 /* Identifier */, true, ts.Diagnostics.Declaration_expected); + return parsePropertyDeclaration(fullStart, decorators, modifiers, name_6, undefined); } // 'isClassMemberStart' should have hinted not to attempt parsing. ts.Debug.fail("Should not have attempted to parse class member declaration."); @@ -11240,13 +11255,13 @@ var ts; while (true) { skipWhitespace(); var startPos = pos; - var name_6 = scanIdentifier(); - if (!name_6) { + var name_7 = scanIdentifier(); + if (!name_7) { parseErrorAtPosition(startPos, 0, ts.Diagnostics.Identifier_expected); return undefined; } - var typeParameter = createNode(129 /* TypeParameter */, name_6.pos); - typeParameter.name = name_6; + var typeParameter = createNode(129 /* TypeParameter */, name_7.pos); + typeParameter.name = name_7; finishNode(typeParameter, pos); typeParameters.push(typeParameter); skipWhitespace(); @@ -11831,10 +11846,10 @@ var ts; var stringType = createIntrinsicType(2 /* String */, "string"); var numberType = createIntrinsicType(4 /* Number */, "number"); var booleanType = createIntrinsicType(8 /* Boolean */, "boolean"); - var esSymbolType = createIntrinsicType(1048576 /* ESSymbol */, "symbol"); + var esSymbolType = createIntrinsicType(2097152 /* ESSymbol */, "symbol"); var voidType = createIntrinsicType(16 /* Void */, "void"); - var undefinedType = createIntrinsicType(32 /* Undefined */ | 262144 /* ContainsUndefinedOrNull */, "undefined"); - var nullType = createIntrinsicType(64 /* Null */ | 262144 /* ContainsUndefinedOrNull */, "null"); + var undefinedType = createIntrinsicType(32 /* Undefined */ | 524288 /* ContainsUndefinedOrNull */, "undefined"); + var nullType = createIntrinsicType(64 /* Null */ | 524288 /* ContainsUndefinedOrNull */, "null"); var unknownType = createIntrinsicType(1 /* Any */, "unknown"); var circularType = createIntrinsicType(1 /* Any */, "__circular__"); var emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); @@ -11891,7 +11906,7 @@ var ts; }, "symbol": { type: esSymbolType, - flags: 1048576 /* ESSymbol */ + flags: 2097152 /* ESSymbol */ } }; function getEmitResolver(sourceFile) { @@ -12398,15 +12413,15 @@ var ts; var moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier); var targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier); if (targetSymbol) { - var name_7 = specifier.propertyName || specifier.name; - if (name_7.text) { - var symbolFromModule = getExportOfModule(targetSymbol, name_7.text); - var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_7.text); + var name_8 = specifier.propertyName || specifier.name; + if (name_8.text) { + var symbolFromModule = getExportOfModule(targetSymbol, name_8.text); + var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_8.text); var symbol = symbolFromModule && symbolFromVariable ? combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - error(name_7, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_7)); + error(name_8, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_8)); } return symbol; } @@ -13112,15 +13127,16 @@ var ts; } return appendParentTypeArgumentsAndSymbolName(symbol); } - function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, typeStack) { + function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, symbolStack) { var globalFlagsToPass = globalFlags & 16 /* WriteOwnNameForAnyLike */; return writeType(type, globalFlags); function writeType(type, flags) { // Write undefined/null type as any - if (type.flags & 1048703 /* Intrinsic */) { + if (type.flags & 2097279 /* Intrinsic */) { // Special handling for unknown / resolving types, they should show up as any and not unknown or __resolving - writer.writeKeyword(!(globalFlags & 16 /* WriteOwnNameForAnyLike */) && - (type.flags & 1 /* Any */) ? "any" : type.intrinsicName); + writer.writeKeyword(!(globalFlags & 16 /* WriteOwnNameForAnyLike */) && isTypeAny(type) + ? "any" + : type.intrinsicName); } else if (type.flags & 4096 /* Reference */) { writeTypeReference(type, flags); @@ -13228,47 +13244,54 @@ var ts; } } function writeAnonymousType(type, flags) { - // Always use 'typeof T' for type of class, enum, and module objects - if (type.symbol && type.symbol.flags & (32 /* Class */ | 384 /* Enum */ | 512 /* ValueModule */)) { - writeTypeofSymbol(type, flags); - } - else if (shouldWriteTypeOfFunctionSymbol()) { - writeTypeofSymbol(type, flags); - } - else if (typeStack && ts.contains(typeStack, type)) { - // If type is an anonymous type literal in a type alias declaration, use type alias name - var typeAlias = getTypeAliasForTypeLiteral(type); - if (typeAlias) { - // The specified symbol flags need to be reinterpreted as type flags - buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056 /* Type */, 0 /* None */, flags); + var symbol = type.symbol; + if (symbol) { + // Always use 'typeof T' for type of class, enum, and module objects + if (symbol.flags & (32 /* Class */ | 384 /* Enum */ | 512 /* ValueModule */)) { + writeTypeofSymbol(type, flags); + } + else if (shouldWriteTypeOfFunctionSymbol()) { + writeTypeofSymbol(type, flags); + } + else if (ts.contains(symbolStack, symbol)) { + // If type is an anonymous type literal in a type alias declaration, use type alias name + var typeAlias = getTypeAliasForTypeLiteral(type); + if (typeAlias) { + // The specified symbol flags need to be reinterpreted as type flags + buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056 /* Type */, 0 /* None */, flags); + } + else { + // Recursive usage, use any + writeKeyword(writer, 112 /* AnyKeyword */); + } } else { - // Recursive usage, use any - writeKeyword(writer, 112 /* AnyKeyword */); + // Since instantiations of the same anonymous type have the same symbol, tracking symbols instead + // of types allows us to catch circular references to instantiations of the same anonymous type + if (!symbolStack) { + symbolStack = []; + } + symbolStack.push(symbol); + writeLiteralType(type, flags); + symbolStack.pop(); } } else { - if (!typeStack) { - typeStack = []; - } - typeStack.push(type); + // Anonymous types with no symbol are never circular writeLiteralType(type, flags); - typeStack.pop(); } function shouldWriteTypeOfFunctionSymbol() { - if (type.symbol) { - var isStaticMethodSymbol = !!(type.symbol.flags & 8192 /* Method */ && - ts.forEach(type.symbol.declarations, function (declaration) { return declaration.flags & 128 /* Static */; })); - var isNonLocalFunctionSymbol = !!(type.symbol.flags & 16 /* Function */) && - (type.symbol.parent || - ts.forEach(type.symbol.declarations, function (declaration) { - return declaration.parent.kind === 228 /* SourceFile */ || declaration.parent.kind === 207 /* ModuleBlock */; - })); - if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { - // typeof is allowed only for static/non local functions - return !!(flags & 2 /* UseTypeOfFunction */) || - (typeStack && ts.contains(typeStack, type)); // it is type of the symbol uses itself recursively - } + var isStaticMethodSymbol = !!(symbol.flags & 8192 /* Method */ && + ts.forEach(symbol.declarations, function (declaration) { return declaration.flags & 128 /* Static */; })); + var isNonLocalFunctionSymbol = !!(symbol.flags & 16 /* Function */) && + (symbol.parent || + ts.forEach(symbol.declarations, function (declaration) { + return declaration.parent.kind === 228 /* SourceFile */ || declaration.parent.kind === 207 /* ModuleBlock */; + })); + if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { + // typeof is allowed only for static/non local functions + return !!(flags & 2 /* UseTypeOfFunction */) || + (ts.contains(symbolStack, symbol)); // it is type of the symbol uses itself recursively } } } @@ -13299,7 +13322,7 @@ var ts; if (flags & 64 /* InElementType */) { writePunctuation(writer, 16 /* OpenParenToken */); } - buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, typeStack); + buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, symbolStack); if (flags & 64 /* InElementType */) { writePunctuation(writer, 17 /* CloseParenToken */); } @@ -13311,7 +13334,7 @@ var ts; } writeKeyword(writer, 88 /* NewKeyword */); writeSpace(writer); - buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, typeStack); + buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, symbolStack); if (flags & 64 /* InElementType */) { writePunctuation(writer, 17 /* CloseParenToken */); } @@ -13323,7 +13346,7 @@ var ts; writer.increaseIndent(); for (var _i = 0, _a = resolved.callSignatures; _i < _a.length; _i++) { var signature = _a[_i]; - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22 /* SemicolonToken */); writer.writeLine(); } @@ -13331,7 +13354,7 @@ var ts; var signature = _c[_b]; writeKeyword(writer, 88 /* NewKeyword */); writeSpace(writer); - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22 /* SemicolonToken */); writer.writeLine(); } @@ -13374,7 +13397,7 @@ var ts; if (p.flags & 536870912 /* Optional */) { writePunctuation(writer, 50 /* QuestionToken */); } - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22 /* SemicolonToken */); writer.writeLine(); } @@ -13401,17 +13424,17 @@ var ts; buildDisplayForTypeParametersAndDelimiters(getLocalTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); } } - function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, typeStack) { + function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, symbolStack) { appendSymbolNameOnly(tp.symbol, writer); var constraint = getConstraintOfTypeParameter(tp); if (constraint) { writeSpace(writer); writeKeyword(writer, 79 /* ExtendsKeyword */); writeSpace(writer); - buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, symbolStack); } } - function buildParameterDisplay(p, writer, enclosingDeclaration, flags, typeStack) { + function buildParameterDisplay(p, writer, enclosingDeclaration, flags, symbolStack) { var parameterNode = p.valueDeclaration; if (ts.isRestParameter(parameterNode)) { writePunctuation(writer, 21 /* DotDotDotToken */); @@ -13422,9 +13445,9 @@ var ts; } writePunctuation(writer, 51 /* ColonToken */); writeSpace(writer); - buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, symbolStack); } - function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, symbolStack) { if (typeParameters && typeParameters.length) { writePunctuation(writer, 24 /* LessThanToken */); for (var i = 0; i < typeParameters.length; i++) { @@ -13432,12 +13455,12 @@ var ts; writePunctuation(writer, 23 /* CommaToken */); writeSpace(writer); } - buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, typeStack); + buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, symbolStack); } writePunctuation(writer, 25 /* GreaterThanToken */); } } - function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, symbolStack) { if (typeParameters && typeParameters.length) { writePunctuation(writer, 24 /* LessThanToken */); for (var i = 0; i < typeParameters.length; i++) { @@ -13450,18 +13473,18 @@ var ts; writePunctuation(writer, 25 /* GreaterThanToken */); } } - function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, symbolStack) { writePunctuation(writer, 16 /* OpenParenToken */); for (var i = 0; i < parameters.length; i++) { if (i > 0) { writePunctuation(writer, 23 /* CommaToken */); writeSpace(writer); } - buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, typeStack); + buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, symbolStack); } writePunctuation(writer, 17 /* CloseParenToken */); } - function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack) { if (flags & 8 /* WriteArrowStyleSignature */) { writeSpace(writer); writePunctuation(writer, 32 /* EqualsGreaterThanToken */); @@ -13470,19 +13493,19 @@ var ts; writePunctuation(writer, 51 /* ColonToken */); } writeSpace(writer); - buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, symbolStack); } - function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, symbolStack) { if (signature.target && (flags & 32 /* WriteTypeArgumentsOfSignature */)) { // Instantiated signature, write type arguments instead // This is achieved by passing in the mapper separately buildDisplayForTypeArgumentsAndDelimiters(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration); } else { - buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, typeStack); + buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, symbolStack); } - buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, typeStack); - buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack); + buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, symbolStack); + buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack); } return _displayBuilder || (_displayBuilder = { symbolToString: symbolToString, @@ -13710,6 +13733,9 @@ var ts; var prop = getPropertyOfType(type, name); return prop ? getTypeOfSymbol(prop) : undefined; } + function isTypeAny(type) { + return type && (type.flags & 1 /* Any */) !== 0; + } // Return the inferred type for a binding element function getTypeForBindingElement(declaration) { var pattern = declaration.parent; @@ -13721,7 +13747,7 @@ var ts; // If no type was specified or inferred for parent, or if the specified or inferred type is any, // infer from the initializer of the binding element if one is present. Otherwise, go with the // undefined or any type of the parent. - if (!parentType || parentType === anyType) { + if (!parentType || isTypeAny(parentType)) { if (declaration.initializer) { return checkExpressionCached(declaration.initializer); } @@ -13730,14 +13756,14 @@ var ts; var type; if (pattern.kind === 151 /* ObjectBindingPattern */) { // Use explicitly specified property name ({ p: xxx } form), or otherwise the implied name ({ p } form) - var name_8 = declaration.propertyName || declaration.name; + var name_9 = declaration.propertyName || declaration.name; // Use type of the specified property, or otherwise, for a numeric name, the type of the numeric index signature, // or otherwise the type of the string index signature. - type = getTypeOfPropertyOfType(parentType, name_8.text) || - isNumericLiteralName(name_8.text) && getIndexTypeOfType(parentType, 1 /* Number */) || + type = getTypeOfPropertyOfType(parentType, name_9.text) || + isNumericLiteralName(name_9.text) && getIndexTypeOfType(parentType, 1 /* Number */) || getIndexTypeOfType(parentType, 0 /* String */); if (!type) { - error(name_8, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_8)); + error(name_9, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_9)); return unknownType; } } @@ -13747,7 +13773,7 @@ var ts; // fact an iterable or array (depending on target language). var elementType = checkIteratedTypeOrElementType(parentType, pattern, false); if (!declaration.dotDotDotToken) { - if (elementType.flags & 1 /* Any */) { + if (isTypeAny(elementType)) { return elementType; } // Use specific property type when parent is a tuple or numeric index type when parent is an array @@ -13941,7 +13967,7 @@ var ts; // Variable has initializer that circularly references the variable itself type = anyType; if (compilerOptions.noImplicitAny) { - error(symbol.valueDeclaration, ts.Diagnostics._0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol)); + error(symbol.valueDeclaration, ts.Diagnostics._0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol)); } } } @@ -14584,7 +14610,7 @@ var ts; else if (type.flags & 8 /* Boolean */) { type = globalBooleanType; } - else if (type.flags & 1048576 /* ESSymbol */) { + else if (type.flags & 2097152 /* ESSymbol */) { type = globalESSymbolType; } return type; @@ -14859,7 +14885,7 @@ var ts; // will result in a different declaration kind. if (!signature.isolatedSignatureType) { var isConstructor = signature.declaration.kind === 136 /* Constructor */ || signature.declaration.kind === 140 /* ConstructSignature */; - var type = createObjectType(32768 /* Anonymous */ | 65536 /* FromSignature */); + var type = createObjectType(32768 /* Anonymous */ | 131072 /* FromSignature */); type.members = emptySymbols; type.properties = emptyArray; type.callSignatures = !isConstructor ? [signature] : emptyArray; @@ -14936,7 +14962,7 @@ var ts; var type = types[_i]; result |= type.flags; } - return result & 786432 /* RequiresWidening */; + return result & 1572864 /* RequiresWidening */; } function createTypeReference(target, typeArguments) { var id = getTypeListId(typeArguments); @@ -15180,10 +15206,10 @@ var ts; } } } - function containsAnyType(types) { + function containsTypeAny(types) { for (var _i = 0; _i < types.length; _i++) { var type = types[_i]; - if (type.flags & 1 /* Any */) { + if (isTypeAny(type)) { return true; } } @@ -15209,7 +15235,7 @@ var ts; var sortedTypes = []; addTypesToSortedSet(sortedTypes, types); if (noSubtypeReduction) { - if (containsAnyType(sortedTypes)) { + if (containsTypeAny(sortedTypes)) { return anyType; } removeAllButLast(sortedTypes, undefinedType); @@ -15435,19 +15461,8 @@ var ts; return result; } function instantiateAnonymousType(type, mapper) { - // If this type has already been instantiated using this mapper, returned the cached result. This guards against - // infinite instantiations of cyclic types, e.g. "var x: { a: T, b: typeof x };" - if (mapper.mappings) { - var cached = mapper.mappings[type.id]; - if (cached) { - return cached; - } - } - else { - mapper.mappings = {}; - } - // Instantiate the given type using the given mapper and cache the result - var result = createObjectType(32768 /* Anonymous */, type.symbol); + // Mark the anonymous type as instantiated such that our infinite instantiation detection logic can recognize it + var result = createObjectType(32768 /* Anonymous */ | 65536 /* Instantiated */, type.symbol); result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); result.members = createSymbolTable(result.properties); result.callSignatures = instantiateList(getSignaturesOfType(type, 0 /* Call */), mapper, instantiateSignature); @@ -15458,7 +15473,6 @@ var ts; result.stringIndexType = instantiateType(stringIndexType, mapper); if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper); - mapper.mappings[type.id] = result; return result; } function instantiateType(type, mapper) { @@ -15597,7 +15611,7 @@ var ts; if (source === target) return -1 /* True */; if (relation !== identityRelation) { - if (target.flags & 1 /* Any */) + if (isTypeAny(target)) return -1 /* True */; if (source === undefinedType) return -1 /* True */; @@ -15608,7 +15622,7 @@ var ts; if (source.flags & 256 /* StringLiteral */ && target === stringType) return -1 /* True */; if (relation === assignableRelation) { - if (source.flags & 1 /* Any */) + if (isTypeAny(source)) return -1 /* True */; if (source === numberType && target.flags & 128 /* Enum */) return -1 /* True */; @@ -15851,12 +15865,13 @@ var ts; // Effectively, we will generate a false positive when two types are structurally equal to at least 10 levels, but unequal at // some level beyond that. function isDeeplyNestedGeneric(type, stack) { - if (type.flags & 4096 /* Reference */ && depth >= 10) { - var target_1 = type.target; + // We track type references (created by createTypeReference) and instantiated types (created by instantiateType) + if (type.flags & (4096 /* Reference */ | 65536 /* Instantiated */) && depth >= 10) { + var symbol = type.symbol; var count = 0; for (var i = 0; i < depth; i++) { var t = stack[i]; - if (t.flags & 4096 /* Reference */ && t.target === target_1) { + if (t.flags & (4096 /* Reference */ | 65536 /* Instantiated */) && t.symbol === symbol) { count++; if (count >= 10) return true; @@ -15871,7 +15886,7 @@ var ts; } var result = -1 /* True */; var properties = getPropertiesOfObjectType(target); - var requireOptionalProperties = relation === subtypeRelation && !(source.flags & 131072 /* ObjectLiteral */); + var requireOptionalProperties = relation === subtypeRelation && !(source.flags & 262144 /* ObjectLiteral */); for (var _i = 0; _i < properties.length; _i++) { var targetProp = properties[_i]; var sourceProp = getPropertyOfType(source, targetProp.name); @@ -15977,11 +15992,11 @@ var ts; var saveErrorInfo = errorInfo; outer: for (var _i = 0; _i < targetSignatures.length; _i++) { var t = targetSignatures[_i]; - if (!t.hasStringLiterals || target.flags & 65536 /* FromSignature */) { + if (!t.hasStringLiterals || target.flags & 131072 /* FromSignature */) { var localErrors = reportErrors; for (var _a = 0; _a < sourceSignatures.length; _a++) { var s = sourceSignatures[_a]; - if (!s.hasStringLiterals || source.flags & 65536 /* FromSignature */) { + if (!s.hasStringLiterals || source.flags & 131072 /* FromSignature */) { var related = signatureRelatedTo(s, t, localErrors); if (related) { result &= related; @@ -16293,11 +16308,11 @@ var ts; return createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType); } function getWidenedType(type) { - if (type.flags & 786432 /* RequiresWidening */) { + if (type.flags & 1572864 /* RequiresWidening */) { if (type.flags & (32 /* Undefined */ | 64 /* Null */)) { return anyType; } - if (type.flags & 131072 /* ObjectLiteral */) { + if (type.flags & 262144 /* ObjectLiteral */) { return getWidenedTypeOfObjectLiteral(type); } if (type.flags & 16384 /* Union */) { @@ -16322,11 +16337,11 @@ var ts; if (isArrayType(type)) { return reportWideningErrorsInType(type.typeArguments[0]); } - if (type.flags & 131072 /* ObjectLiteral */) { + if (type.flags & 262144 /* ObjectLiteral */) { var errorReported = false; ts.forEach(getPropertiesOfObjectType(type), function (p) { var t = getTypeOfSymbol(p); - if (t.flags & 262144 /* ContainsUndefinedOrNull */) { + if (t.flags & 524288 /* ContainsUndefinedOrNull */) { if (!reportWideningErrorsInType(t)) { error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(getWidenedType(t))); } @@ -16369,7 +16384,7 @@ var ts; error(declaration, diagnostic, ts.declarationNameToString(declaration.name), typeAsString); } function reportErrorsFromWidening(declaration, type) { - if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 262144 /* ContainsUndefinedOrNull */) { + if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 524288 /* ContainsUndefinedOrNull */) { // Report implicit any error within type if possible, otherwise report error on declaration if (!reportWideningErrorsInType(type)) { reportImplicitAnyError(declaration, type); @@ -16431,11 +16446,11 @@ var ts; } function isWithinDepthLimit(type, stack) { if (depth >= 5) { - var target_2 = type.target; + var target_1 = type.target; var count = 0; for (var i = 0; i < depth; i++) { var t = stack[i]; - if (t.flags & 4096 /* Reference */ && t.target === target_2) { + if (t.flags & 4096 /* Reference */ && t.target === target_1) { count++; } } @@ -16778,52 +16793,54 @@ var ts; function getNarrowedTypeOfSymbol(symbol, node) { var type = getTypeOfSymbol(symbol); // Only narrow when symbol is variable of type any or an object, union, or type parameter type - if (node && symbol.flags & 3 /* Variable */ && type.flags & (1 /* Any */ | 48128 /* ObjectType */ | 16384 /* Union */ | 512 /* TypeParameter */)) { - loop: while (node.parent) { - var child = node; - node = node.parent; - var narrowedType = type; - switch (node.kind) { - case 184 /* IfStatement */: - // In a branch of an if statement, narrow based on controlling expression - if (child !== node.expression) { - narrowedType = narrowType(type, node.expression, child === node.thenStatement); - } - break; - case 171 /* ConditionalExpression */: - // In a branch of a conditional expression, narrow based on controlling condition - if (child !== node.condition) { - narrowedType = narrowType(type, node.condition, child === node.whenTrue); - } - break; - case 170 /* BinaryExpression */: - // In the right operand of an && or ||, narrow based on left operand - if (child === node.right) { - if (node.operatorToken.kind === 48 /* AmpersandAmpersandToken */) { - narrowedType = narrowType(type, node.left, true); + if (node && symbol.flags & 3 /* Variable */) { + if (isTypeAny(type) || type.flags & (48128 /* ObjectType */ | 16384 /* Union */ | 512 /* TypeParameter */)) { + loop: while (node.parent) { + var child = node; + node = node.parent; + var narrowedType = type; + switch (node.kind) { + case 184 /* IfStatement */: + // In a branch of an if statement, narrow based on controlling expression + if (child !== node.expression) { + narrowedType = narrowType(type, node.expression, child === node.thenStatement); } - else if (node.operatorToken.kind === 49 /* BarBarToken */) { - narrowedType = narrowType(type, node.left, false); + break; + case 171 /* ConditionalExpression */: + // In a branch of a conditional expression, narrow based on controlling condition + if (child !== node.condition) { + narrowedType = narrowType(type, node.condition, child === node.whenTrue); } - } - break; - case 228 /* SourceFile */: - case 206 /* ModuleDeclaration */: - case 201 /* FunctionDeclaration */: - case 135 /* MethodDeclaration */: - case 134 /* MethodSignature */: - case 137 /* GetAccessor */: - case 138 /* SetAccessor */: - case 136 /* Constructor */: - // Stop at the first containing function or module declaration - break loop; - } - // Use narrowed type if construct contains no assignments to variable - if (narrowedType !== type) { - if (isVariableAssignedWithin(symbol, node)) { - break; + break; + case 170 /* BinaryExpression */: + // In the right operand of an && or ||, narrow based on left operand + if (child === node.right) { + if (node.operatorToken.kind === 48 /* AmpersandAmpersandToken */) { + narrowedType = narrowType(type, node.left, true); + } + else if (node.operatorToken.kind === 49 /* BarBarToken */) { + narrowedType = narrowType(type, node.left, false); + } + } + break; + case 228 /* SourceFile */: + case 206 /* ModuleDeclaration */: + case 201 /* FunctionDeclaration */: + case 135 /* MethodDeclaration */: + case 134 /* MethodSignature */: + case 137 /* GetAccessor */: + case 138 /* SetAccessor */: + case 136 /* Constructor */: + // Stop at the first containing function or module declaration + break loop; + } + // Use narrowed type if construct contains no assignments to variable + if (narrowedType !== type) { + if (isVariableAssignedWithin(symbol, node)) { + break; + } + type = narrowedType; } - type = narrowedType; } } } @@ -16845,7 +16862,7 @@ var ts; if (assumeTrue) { // Assumed result is true. If check was not for a primitive type, remove all primitive types if (!typeInfo) { - return removeTypesFromUnionType(type, 258 /* StringLike */ | 132 /* NumberLike */ | 8 /* Boolean */ | 1048576 /* ESSymbol */, + return removeTypesFromUnionType(type, 258 /* StringLike */ | 132 /* NumberLike */ | 8 /* Boolean */ | 2097152 /* ESSymbol */, /*isOfTypeKind*/ true, false); } // Check was for a primitive type, return that primitive type if it is a subtype @@ -16895,7 +16912,7 @@ var ts; } function narrowTypeByInstanceof(type, expr, assumeTrue) { // Check that type is not any, assumed result is true, and we have variable symbol on the left - if (type.flags & 1 /* Any */ || !assumeTrue || expr.left.kind !== 65 /* Identifier */ || getResolvedSymbol(expr.left) !== symbol) { + if (isTypeAny(type) || !assumeTrue || expr.left.kind !== 65 /* Identifier */ || getResolvedSymbol(expr.left) !== symbol) { return type; } // Check that right operand is a function type with a prototype property @@ -16908,7 +16925,7 @@ var ts; if (prototypeProperty) { // Target type is type of the protoype property var prototypePropertyType = getTypeOfSymbol(prototypeProperty); - if (prototypePropertyType !== anyType) { + if (!isTypeAny(prototypePropertyType)) { targetType = prototypePropertyType; } } @@ -17591,7 +17608,10 @@ var ts; function isNumericComputedName(name) { // It seems odd to consider an expression of type Any to result in a numeric name, // but this behavior is consistent with checkIndexedAccess - return allConstituentTypesHaveKind(checkComputedPropertyName(name), 1 /* Any */ | 132 /* NumberLike */); + return isTypeAnyOrAllConstituentTypesHaveKind(checkComputedPropertyName(name), 132 /* NumberLike */); + } + function isTypeAnyOrAllConstituentTypesHaveKind(type, kind) { + return isTypeAny(type) || allConstituentTypesHaveKind(type, kind); } function isNumericLiteralName(name) { // The intent of numeric names is that @@ -17623,7 +17643,7 @@ var ts; links.resolvedType = checkExpression(node.expression); // This will allow types number, string, symbol or any. It will also allow enums, the unknown // type, and any union of these types (like string | number). - if (!allConstituentTypesHaveKind(links.resolvedType, 1 /* Any */ | 132 /* NumberLike */ | 258 /* StringLike */ | 1048576 /* ESSymbol */)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(links.resolvedType, 132 /* NumberLike */ | 258 /* StringLike */ | 2097152 /* ESSymbol */)) { error(node, ts.Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any); } else { @@ -17684,7 +17704,7 @@ var ts; var stringIndexType = getIndexType(0 /* String */); var numberIndexType = getIndexType(1 /* Number */); var result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType); - result.flags |= 131072 /* ObjectLiteral */ | 524288 /* ContainsObjectLiteral */ | (typeFlags & 262144 /* ContainsUndefinedOrNull */); + result.flags |= 262144 /* ObjectLiteral */ | 1048576 /* ContainsObjectLiteral */ | (typeFlags & 524288 /* ContainsUndefinedOrNull */); return result; function getIndexType(kind) { if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { @@ -17762,47 +17782,45 @@ var ts; } function checkPropertyAccessExpressionOrQualifiedName(node, left, right) { var type = checkExpressionOrQualifiedName(left); - if (type === unknownType) + if (isTypeAny(type)) { return type; - if (type !== anyType) { - var apparentType = getApparentType(getWidenedType(type)); - if (apparentType === unknownType) { - // handle cases when type is Type parameter with invalid constraint - return unknownType; - } - var prop = getPropertyOfType(apparentType, right.text); - if (!prop) { - if (right.text) { - error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type)); - } - return unknownType; - } - getNodeLinks(node).resolvedSymbol = prop; - if (prop.parent && prop.parent.flags & 32 /* Class */) { - // TS 1.0 spec (April 2014): 4.8.2 - // - In a constructor, instance member function, instance member accessor, or - // instance member variable initializer where this references a derived class instance, - // a super property access is permitted and must specify a public instance member function of the base class. - // - In a static member function or static member accessor - // where this references the constructor function object of a derived class, - // a super property access is permitted and must specify a public static member function of the base class. - if (left.kind === 91 /* SuperKeyword */ && getDeclarationKindFromSymbol(prop) !== 135 /* MethodDeclaration */) { - error(right, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); - } - else { - checkClassPropertyAccess(node, left, type, prop); - } - } - return getTypeOfSymbol(prop); } - return anyType; + var apparentType = getApparentType(getWidenedType(type)); + if (apparentType === unknownType) { + // handle cases when type is Type parameter with invalid constraint + return unknownType; + } + var prop = getPropertyOfType(apparentType, right.text); + if (!prop) { + if (right.text) { + error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type)); + } + return unknownType; + } + getNodeLinks(node).resolvedSymbol = prop; + if (prop.parent && prop.parent.flags & 32 /* Class */) { + // TS 1.0 spec (April 2014): 4.8.2 + // - In a constructor, instance member function, instance member accessor, or + // instance member variable initializer where this references a derived class instance, + // a super property access is permitted and must specify a public instance member function of the base class. + // - In a static member function or static member accessor + // where this references the constructor function object of a derived class, + // a super property access is permitted and must specify a public static member function of the base class. + if (left.kind === 91 /* SuperKeyword */ && getDeclarationKindFromSymbol(prop) !== 135 /* MethodDeclaration */) { + error(right, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); + } + else { + checkClassPropertyAccess(node, left, type, prop); + } + } + return getTypeOfSymbol(prop); } function isValidPropertyAccess(node, propertyName) { var left = node.kind === 156 /* PropertyAccessExpression */ ? node.expression : node.left; var type = checkExpressionOrQualifiedName(left); - if (type !== unknownType && type !== anyType) { + if (type !== unknownType && !isTypeAny(type)) { var prop = getPropertyOfType(getWidenedType(type), propertyName); if (prop && prop.parent && prop.parent.flags & 32 /* Class */) { if (left.kind === 91 /* SuperKeyword */ && getDeclarationKindFromSymbol(prop) !== 135 /* MethodDeclaration */) { @@ -17854,23 +17872,23 @@ var ts; // - Otherwise, if IndexExpr is of type Any, the String or Number primitive type, or an enum type, the property access is of type Any. // See if we can index as a property. if (node.argumentExpression) { - var name_9 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); - if (name_9 !== undefined) { - var prop = getPropertyOfType(objectType, name_9); + var name_10 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); + if (name_10 !== undefined) { + var prop = getPropertyOfType(objectType, name_10); if (prop) { getNodeLinks(node).resolvedSymbol = prop; return getTypeOfSymbol(prop); } else if (isConstEnum) { - error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_9, symbolToString(objectType.symbol)); + error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_10, symbolToString(objectType.symbol)); return unknownType; } } } // Check for compatible indexer types. - if (allConstituentTypesHaveKind(indexType, 1 /* Any */ | 258 /* StringLike */ | 132 /* NumberLike */ | 1048576 /* ESSymbol */)) { + if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, 258 /* StringLike */ | 132 /* NumberLike */ | 2097152 /* ESSymbol */)) { // Try to use a number indexer. - if (allConstituentTypesHaveKind(indexType, 1 /* Any */ | 132 /* NumberLike */)) { + if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, 132 /* NumberLike */)) { var numberIndexType = getIndexTypeOfType(objectType, 1 /* Number */); if (numberIndexType) { return numberIndexType; @@ -17882,7 +17900,7 @@ var ts; return stringIndexType; } // Fall back to any. - if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && objectType !== anyType) { + if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && !isTypeAny(objectType)) { error(node, ts.Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type); } return anyType; @@ -17923,7 +17941,7 @@ var ts; return false; } // Make sure the property type is the primitive symbol type - if ((expressionType.flags & 1048576 /* ESSymbol */) === 0) { + if ((expressionType.flags & 2097152 /* ESSymbol */) === 0) { if (reportError) { error(expression, ts.Diagnostics.A_computed_property_name_of_the_form_0_must_be_of_type_symbol, ts.getTextOfNode(expression)); } @@ -18461,8 +18479,10 @@ var ts; // types are provided for the argument expressions, and the result is always of type Any. // We exclude union types because we may have a union of function types that happen to have // no common signatures. - if (funcType === anyType || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384 /* Union */) && isTypeAssignableTo(funcType, globalFunctionType))) { - if (node.typeArguments) { + if (isTypeAny(funcType) || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384 /* Union */) && isTypeAssignableTo(funcType, globalFunctionType))) { + // The unknownType indicates that an error already occured (and was reported). No + // need to report another error in this case. + if (funcType !== unknownType && node.typeArguments) { error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } return resolveUntypedCall(node); @@ -18489,15 +18509,6 @@ var ts; } } var expressionType = checkExpression(node.expression); - // TS 1.0 spec: 4.11 - // If ConstructExpr is of type Any, Args can be any argument - // list and the result of the operation is of type Any. - if (expressionType === anyType) { - if (node.typeArguments) { - error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); - } - return resolveUntypedCall(node); - } // If ConstructExpr's apparent type(section 3.8.1) is an object type with one or // more construct signatures, the expression is processed in the same manner as a // function call, but using the construct signatures as the initial set of candidate @@ -18508,6 +18519,15 @@ var ts; // Another error has already been reported return resolveErrorCall(node); } + // TS 1.0 spec: 4.11 + // If ConstructExpr is of type Any, Args can be any argument + // list and the result of the operation is of type Any. + if (isTypeAny(expressionType)) { + if (node.typeArguments) { + error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); + } + return resolveUntypedCall(node); + } // Technically, this signatures list may be incomplete. We are taking the apparent type, // but we are not including construct signatures that may have been added to the Object or // Function interface, since they have none by default. This is a bit of a leap of faith @@ -18539,7 +18559,7 @@ var ts; return resolveErrorCall(node); } var callSignatures = getSignaturesOfType(apparentType, 0 /* Call */); - if (tagType === anyType || (!callSignatures.length && !(tagType.flags & 16384 /* Union */) && isTypeAssignableTo(tagType, globalFunctionType))) { + if (isTypeAny(tagType) || (!callSignatures.length && !(tagType.flags & 16384 /* Union */) && isTypeAssignableTo(tagType, globalFunctionType))) { return resolveUntypedCall(node); } if (!callSignatures.length) { @@ -18724,7 +18744,7 @@ var ts; return; } // Functions that return 'void' or 'any' don't need any return expressions. - if (returnType === voidType || returnType === anyType) { + if (returnType === voidType || isTypeAny(returnType)) { return; } // If all we have is a function signature, or an arrow function with an expression body, then there is nothing to check. @@ -18814,7 +18834,7 @@ var ts; } } function checkArithmeticOperandType(operand, type, diagnostic) { - if (!allConstituentTypesHaveKind(type, 1 /* Any */ | 132 /* NumberLike */)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(type, 132 /* NumberLike */)) { error(operand, diagnostic); return false; } @@ -18870,8 +18890,8 @@ var ts; var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 8 /* StringLiteral */) { - var name_10 = index.text; - var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_10); + var name_11 = index.text; + var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_11); return prop && (prop.flags & 3 /* Variable */) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 8192 /* Const */) !== 0; } return false; @@ -18923,7 +18943,7 @@ var ts; case 33 /* PlusToken */: case 34 /* MinusToken */: case 47 /* TildeToken */: - if (someConstituentTypeHasKind(operandType, 1048576 /* ESSymbol */)) { + if (someConstituentTypeHasKind(operandType, 2097152 /* ESSymbol */)) { error(node.operand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(node.operator)); } return numberType; @@ -19001,11 +19021,11 @@ var ts; // and the right operand to be of type Any or a subtype of the 'Function' interface type. // The result is always of the Boolean primitive type. // NOTE: do not raise error if leftType is unknown as related error was already reported - if (allConstituentTypesHaveKind(leftType, 1049086 /* Primitive */)) { + if (allConstituentTypesHaveKind(leftType, 2097662 /* Primitive */)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } // NOTE: do not raise error if right is unknown as related error was already reported - if (!(rightType.flags & 1 /* Any */ || isTypeSubtypeOf(rightType, globalFunctionType))) { + if (!(isTypeAny(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type); } return booleanType; @@ -19015,10 +19035,10 @@ var ts; // The in operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type, // and the right operand to be of type Any, an object type, or a type parameter type. // The result is always of the Boolean primitive type. - if (!allConstituentTypesHaveKind(leftType, 1 /* Any */ | 258 /* StringLike */ | 132 /* NumberLike */ | 1048576 /* ESSymbol */)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258 /* StringLike */ | 132 /* NumberLike */ | 2097152 /* ESSymbol */)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); } - if (!allConstituentTypesHaveKind(rightType, 1 /* Any */ | 48128 /* ObjectType */ | 512 /* TypeParameter */)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 48128 /* ObjectType */ | 512 /* TypeParameter */)) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; @@ -19029,16 +19049,17 @@ var ts; var p = properties[_i]; if (p.kind === 225 /* PropertyAssignment */ || p.kind === 226 /* ShorthandPropertyAssignment */) { // TODO(andersh): Computed property support - var name_11 = p.name; - var type = sourceType.flags & 1 /* Any */ ? sourceType : - getTypeOfPropertyOfType(sourceType, name_11.text) || - isNumericLiteralName(name_11.text) && getIndexTypeOfType(sourceType, 1 /* Number */) || + var name_12 = p.name; + var type = isTypeAny(sourceType) + ? sourceType + : getTypeOfPropertyOfType(sourceType, name_12.text) || + isNumericLiteralName(name_12.text) && getIndexTypeOfType(sourceType, 1 /* Number */) || getIndexTypeOfType(sourceType, 0 /* String */); if (type) { - checkDestructuringAssignment(p.initializer || name_11, type); + checkDestructuringAssignment(p.initializer || name_12, type); } else { - error(name_11, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_11)); + error(name_12, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_12)); } } else { @@ -19058,8 +19079,9 @@ var ts; if (e.kind !== 176 /* OmittedExpression */) { if (e.kind !== 174 /* SpreadElementExpression */) { var propName = "" + i; - var type = sourceType.flags & 1 /* Any */ ? sourceType : - isTupleLikeType(sourceType) + var type = isTypeAny(sourceType) + ? sourceType + : isTupleLikeType(sourceType) ? getTypeOfPropertyOfType(sourceType, propName) : elementType; if (type) { @@ -19194,10 +19216,10 @@ var ts; // If one or both operands are of the String primitive type, the result is of the String primitive type. resultType = stringType; } - else if (leftType.flags & 1 /* Any */ || rightType.flags & 1 /* Any */) { + else if (isTypeAny(leftType) || isTypeAny(rightType)) { // Otherwise, the result is of type Any. // NOTE: unknown type here denotes error type. Old compiler treated this case as any type so do we. - resultType = anyType; + resultType = leftType === unknownType || rightType === unknownType ? unknownType : anyType; } // Symbols are not allowed at all in arithmetic expressions if (resultType && !checkForDisallowedESSymbolOperand(operator)) { @@ -19244,8 +19266,8 @@ var ts; } // Return true if there was no error, false if there was an error. function checkForDisallowedESSymbolOperand(operator) { - var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 1048576 /* ESSymbol */) ? node.left : - someConstituentTypeHasKind(rightType, 1048576 /* ESSymbol */) ? node.right : + var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 2097152 /* ESSymbol */) ? node.left : + someConstituentTypeHasKind(rightType, 2097152 /* ESSymbol */) ? node.right : undefined; if (offendingSymbolOperand) { error(offendingSymbolOperand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(operator)); @@ -20161,7 +20183,7 @@ var ts; if (node && node.kind === 142 /* TypeReference */) { var type = getTypeFromTypeNode(node); var shouldCheckIfUnknownType = type === unknownType && compilerOptions.isolatedModules; - if (!type || (!shouldCheckIfUnknownType && type.flags & (1048703 /* Intrinsic */ | 132 /* NumberLike */ | 258 /* StringLike */))) { + if (!type || (!shouldCheckIfUnknownType && type.flags & (2097279 /* Intrinsic */ | 132 /* NumberLike */ | 258 /* StringLike */))) { return; } if (shouldCheckIfUnknownType || type.symbol.valueDeclaration) { @@ -20456,8 +20478,8 @@ var ts; // otherwise if variable has an initializer - show error that initialization will fail // since LHS will be block scoped name instead of function scoped if (!namesShareScope) { - var name_12 = symbolToString(localDeclarationSymbol); - error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_12, name_12); + var name_13 = symbolToString(localDeclarationSymbol); + error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_13, name_13); } } } @@ -20690,7 +20712,7 @@ var ts; if (varExpr.kind === 154 /* ArrayLiteralExpression */ || varExpr.kind === 155 /* ObjectLiteralExpression */) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); } - else if (!allConstituentTypesHaveKind(leftType, 1 /* Any */ | 258 /* StringLike */)) { + else if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258 /* StringLike */)) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any); } else { @@ -20701,7 +20723,7 @@ var ts; var rightType = checkExpression(node.expression); // unknownType is returned i.e. if node.expression is identifier whose name cannot be resolved // in this case error about missing name is already reported - do not report extra one - if (!allConstituentTypesHaveKind(rightType, 1 /* Any */ | 48128 /* ObjectType */ | 512 /* TypeParameter */)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 48128 /* ObjectType */ | 512 /* TypeParameter */)) { error(node.expression, ts.Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } checkSourceElement(node.statement); @@ -20719,7 +20741,7 @@ var ts; return checkIteratedTypeOrElementType(expressionType, rhsExpression, true); } function checkIteratedTypeOrElementType(inputType, errorNode, allowStringInput) { - if (inputType.flags & 1 /* Any */) { + if (isTypeAny(inputType)) { return inputType; } if (languageVersion >= 2 /* ES6 */) { @@ -20771,7 +20793,7 @@ var ts; * whole pattern and that T (above) is 'any'. */ function getElementTypeOfIterable(type, errorNode) { - if (type.flags & 1 /* Any */) { + if (isTypeAny(type)) { return undefined; } var typeAsIterable = type; @@ -20783,7 +20805,7 @@ var ts; } else { var iteratorFunction = getTypeOfPropertyOfType(type, ts.getPropertyNameForKnownSymbolName("iterator")); - if (iteratorFunction && iteratorFunction.flags & 1 /* Any */) { + if (isTypeAny(iteratorFunction)) { return undefined; } var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0 /* Call */) : emptyArray; @@ -20812,7 +20834,7 @@ var ts; * */ function getElementTypeOfIterator(type, errorNode) { - if (type.flags & 1 /* Any */) { + if (isTypeAny(type)) { return undefined; } var typeAsIterator = type; @@ -20824,7 +20846,7 @@ var ts; } else { var iteratorNextFunction = getTypeOfPropertyOfType(type, "next"); - if (iteratorNextFunction && iteratorNextFunction.flags & 1 /* Any */) { + if (isTypeAny(iteratorNextFunction)) { return undefined; } var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0 /* Call */) : emptyArray; @@ -20835,7 +20857,7 @@ var ts; return undefined; } var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); - if (iteratorNextResult.flags & 1 /* Any */) { + if (isTypeAny(iteratorNextResult)) { return undefined; } var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value"); @@ -20851,7 +20873,7 @@ var ts; return typeAsIterator.iteratorElementType; } function getElementTypeOfIterableIterator(type) { - if (type.flags & 1 /* Any */) { + if (isTypeAny(type)) { return undefined; } // As an optimization, if the type is instantiated directly using the globalIterableIteratorType (IterableIterator), @@ -22480,9 +22502,9 @@ var ts; function getRootSymbols(symbol) { if (symbol.flags & 268435456 /* UnionProperty */) { var symbols = []; - var name_13 = symbol.name; + var name_14 = symbol.name; ts.forEach(getSymbolLinks(symbol).unionType.types, function (t) { - symbols.push(getPropertyOfType(t, name_13)); + symbols.push(getPropertyOfType(t, name_14)); }); return symbols; } @@ -22700,7 +22722,7 @@ var ts; else if (type.flags & 8192 /* Tuple */) { return "Array"; } - else if (type.flags & 1048576 /* ESSymbol */) { + else if (type.flags & 2097152 /* ESSymbol */) { return "Symbol"; } else if (type === unknownType) { @@ -22992,20 +23014,20 @@ var ts; if (impotClause.namedBindings) { var nameBindings = impotClause.namedBindings; if (nameBindings.kind === 212 /* NamespaceImport */) { - var name_14 = nameBindings.name; - if (isReservedWordInStrictMode(name_14)) { - var nameText = ts.declarationNameToString(name_14); - return grammarErrorOnNode(name_14, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_15 = nameBindings.name; + if (isReservedWordInStrictMode(name_15)) { + var nameText = ts.declarationNameToString(name_15); + return grammarErrorOnNode(name_15, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } else if (nameBindings.kind === 213 /* NamedImports */) { var reportError = false; for (var _i = 0, _a = nameBindings.elements; _i < _a.length; _i++) { var element = _a[_i]; - var name_15 = element.name; - if (isReservedWordInStrictMode(name_15)) { - var nameText = ts.declarationNameToString(name_15); - reportError = reportError || grammarErrorOnNode(name_15, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_16 = element.name; + if (isReservedWordInStrictMode(name_16)) { + var nameText = ts.declarationNameToString(name_16); + reportError = reportError || grammarErrorOnNode(name_16, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } return reportError; @@ -23498,11 +23520,11 @@ var ts; var inStrictMode = (node.parserContextFlags & 1 /* StrictMode */) !== 0; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - var name_16 = prop.name; + var name_17 = prop.name; if (prop.kind === 176 /* OmittedExpression */ || - name_16.kind === 128 /* ComputedPropertyName */) { + name_17.kind === 128 /* ComputedPropertyName */) { // If the name is not a ComputedPropertyName, the grammar checking will skip it - checkGrammarComputedPropertyName(name_16); + checkGrammarComputedPropertyName(name_17); continue; } // ECMA-262 11.1.5 Object Initialiser @@ -23517,8 +23539,8 @@ var ts; if (prop.kind === 225 /* PropertyAssignment */ || prop.kind === 226 /* ShorthandPropertyAssignment */) { // Grammar checking for computedPropertName and shorthandPropertyAssignment checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); - if (name_16.kind === 7 /* NumericLiteral */) { - checkGrammarNumericLiteral(name_16); + if (name_17.kind === 7 /* NumericLiteral */) { + checkGrammarNumericLiteral(name_17); } currentKind = Property; } @@ -23534,26 +23556,26 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_16.text)) { - seen[name_16.text] = currentKind; + if (!ts.hasProperty(seen, name_17.text)) { + seen[name_17.text] = currentKind; } else { - var existingKind = seen[name_16.text]; + var existingKind = seen[name_17.text]; if (currentKind === Property && existingKind === Property) { if (inStrictMode) { - grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); + grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); } } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_16.text] = currentKind | existingKind; + seen[name_17.text] = currentKind | existingKind; } else { - return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + return grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); } } else { - return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + return grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); } } } @@ -24414,9 +24436,9 @@ var ts; } var count = 0; while (true) { - var name_17 = baseName + "_" + (++count); - if (!ts.hasProperty(currentSourceFile.identifiers, name_17)) { - return name_17; + var name_18 = baseName + "_" + (++count); + if (!ts.hasProperty(currentSourceFile.identifiers, name_18)) { + return name_18; } } } @@ -25625,9 +25647,9 @@ var ts; tempFlags++; // Skip over 'i' and 'n' if (count !== 8 && count !== 13) { - var name_18 = count < 26 ? "_" + String.fromCharCode(97 /* a */ + count) : "_" + (count - 26); - if (isUniqueName(name_18)) { - return name_18; + var name_19 = count < 26 ? "_" + String.fromCharCode(97 /* a */ + count) : "_" + (count - 26); + if (isUniqueName(name_19)) { + return name_19; } } } @@ -25660,9 +25682,9 @@ var ts; } function generateNameForModuleOrEnum(node) { if (node.name.kind === 65 /* Identifier */) { - var name_19 = node.name.text; + var name_20 = node.name.text; // Use module/enum name itself if it is unique, otherwise make a unique variation - assignGeneratedName(node, isUniqueLocalName(name_19, node) ? name_19 : makeUniqueName(name_19)); + assignGeneratedName(node, isUniqueLocalName(name_20, node) ? name_20 : makeUniqueName(name_20)); } } function generateNameForImportOrExportDeclaration(node) { @@ -25881,8 +25903,8 @@ var ts; // Child scopes are always shown with a dot (even if they have no name), // unless it is a computed property. Then it is shown with brackets, // but the brackets are included in the name. - var name_20 = node.name; - if (!name_20 || name_20.kind !== 128 /* ComputedPropertyName */) { + var name_21 = node.name; + if (!name_21 || name_21.kind !== 128 /* ComputedPropertyName */) { scopeName = "." + scopeName; } scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; @@ -25911,10 +25933,10 @@ var ts; node.kind === 205 /* EnumDeclaration */) { // Declaration and has associated name use it if (node.name) { - var name_21 = node.name; + var name_22 = node.name; // For computed property names, the text will include the brackets - scopeName = name_21.kind === 128 /* ComputedPropertyName */ - ? ts.getTextOfNode(name_21) + scopeName = name_22.kind === 128 /* ComputedPropertyName */ + ? ts.getTextOfNode(name_22) : node.name.text; } recordScopeNameStart(scopeName); @@ -26859,6 +26881,11 @@ var ts; return result; } function parenthesizeForAccess(expr) { + // When diagnosing whether the expression needs parentheses, the decision should be based + // on the innermost expression in a chain of nested type assertions. + while (expr.kind === 161 /* TypeAssertionExpression */) { + expr = expr.expression; + } // isLeftHandSideExpression is almost the correct criterion for when it is not necessary // to parenthesize the expression before a dot. The known exceptions are: // @@ -26867,7 +26894,9 @@ var ts; // NumberLiteral // 1.x -> not the same as (1).x // - if (ts.isLeftHandSideExpression(expr) && expr.kind !== 159 /* NewExpression */ && expr.kind !== 7 /* NumericLiteral */) { + if (ts.isLeftHandSideExpression(expr) && + expr.kind !== 159 /* NewExpression */ && + expr.kind !== 7 /* NumericLiteral */) { return expr; } var node = ts.createSynthesizedNode(162 /* ParenthesizedExpression */); @@ -27129,7 +27158,10 @@ var ts; } } function emitParenExpression(node) { - if (!node.parent || node.parent.kind !== 164 /* ArrowFunction */) { + // If the node is synthesized, it means the emitter put the parentheses there, + // not the user. If we didn't want them, the emitter would not have put them + // there. + if (!ts.nodeIsSynthesized(node) && node.parent.kind !== 164 /* ArrowFunction */) { if (node.expression.kind === 161 /* TypeAssertionExpression */) { var operand = node.expression.expression; // Make sure we consider all nested cast expressions, e.g.: @@ -28204,12 +28236,12 @@ var ts; function emitParameter(node) { if (languageVersion < 2 /* ES6 */) { if (ts.isBindingPattern(node.name)) { - var name_22 = createTempVariable(0 /* Auto */); + var name_23 = createTempVariable(0 /* Auto */); if (!tempParameters) { tempParameters = []; } - tempParameters.push(name_22); - emit(name_22); + tempParameters.push(name_23); + emit(name_23); } else { emit(node.name); @@ -29877,8 +29909,8 @@ var ts; // export { x, y } for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { var specifier = _d[_c]; - var name_23 = (specifier.propertyName || specifier.name).text; - (exportSpecifiers[name_23] || (exportSpecifiers[name_23] = [])).push(specifier); + var name_24 = (specifier.propertyName || specifier.name).text; + (exportSpecifiers[name_24] || (exportSpecifiers[name_24] = [])).push(specifier); } } break; @@ -30078,12 +30110,12 @@ var ts; var seen = {}; for (var i = 0; i < hoistedVars.length; ++i) { var local = hoistedVars[i]; - var name_24 = local.kind === 65 /* Identifier */ + var name_25 = local.kind === 65 /* Identifier */ ? local : local.name; - if (name_24) { + if (name_25) { // do not emit duplicate entries (in case of declaration merging) in the list of hoisted variables - var text = ts.unescapeIdentifier(name_24.text); + var text = ts.unescapeIdentifier(name_25.text); if (ts.hasProperty(seen, text)) { continue; } @@ -30162,15 +30194,15 @@ var ts; } if (node.kind === 199 /* VariableDeclaration */ || node.kind === 153 /* BindingElement */) { if (shouldHoistVariable(node, false)) { - var name_25 = node.name; - if (name_25.kind === 65 /* Identifier */) { + var name_26 = node.name; + if (name_26.kind === 65 /* Identifier */) { if (!hoistedVars) { hoistedVars = []; } - hoistedVars.push(name_25); + hoistedVars.push(name_26); } else { - ts.forEachChild(name_25, visit); + ts.forEachChild(name_26, visit); } } return; @@ -31863,7 +31895,7 @@ var ts; var errors = []; return { options: getCompilerOptions(), - fileNames: getFiles(), + fileNames: getFileNames(), errors: errors }; function getCompilerOptions() { @@ -31907,23 +31939,24 @@ var ts; } return options; } - function getFiles() { - var files = []; + function getFileNames() { + var fileNames = []; if (ts.hasProperty(json, "files")) { if (json["files"] instanceof Array) { - var files = ts.map(json["files"], function (s) { return ts.combinePaths(basePath, s); }); + fileNames = ts.map(json["files"], function (s) { return ts.combinePaths(basePath, s); }); } } else { - var sysFiles = host.readDirectory(basePath, ".ts"); + var exclude = json["exclude"] instanceof Array ? ts.map(json["exclude"], ts.normalizeSlashes) : undefined; + var sysFiles = host.readDirectory(basePath, ".ts", exclude); for (var i = 0; i < sysFiles.length; i++) { var name = sysFiles[i]; if (!ts.fileExtensionIs(name, ".d.ts") || !ts.contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) { - files.push(name); + fileNames.push(name); } } } - return files; + return fileNames; } } ts.parseConfigFile = parseConfigFile; @@ -32102,12 +32135,12 @@ var ts; ts.forEach(program.getSourceFiles(), function (sourceFile) { cancellationToken.throwIfCancellationRequested(); var nameToDeclarations = sourceFile.getNamedDeclarations(); - for (var name_26 in nameToDeclarations) { - var declarations = ts.getProperty(nameToDeclarations, name_26); + for (var name_27 in nameToDeclarations) { + var declarations = ts.getProperty(nameToDeclarations, name_27); if (declarations) { // First do a quick check to see if the name of the declaration matches the // last portion of the (possibly) dotted name they're searching for. - var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_26); + var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_27); if (!matches) { continue; } @@ -32120,14 +32153,14 @@ var ts; if (!containers) { return undefined; } - matches = patternMatcher.getMatches(containers, name_26); + matches = patternMatcher.getMatches(containers, name_27); if (!matches) { continue; } } var fileName = sourceFile.fileName; var matchKind = bestMatchKind(matches); - rawItems.push({ name: name_26, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); + rawItems.push({ name: name_27, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); } } } @@ -32510,9 +32543,9 @@ var ts; case 199 /* VariableDeclaration */: case 153 /* BindingElement */: var variableDeclarationNode; - var name_27; + var name_28; if (node.kind === 153 /* BindingElement */) { - name_27 = node.name; + name_28 = node.name; variableDeclarationNode = node; // binding elements are added only for variable declarations // bubble up to the containing variable declaration @@ -32524,16 +32557,16 @@ var ts; else { ts.Debug.assert(!ts.isBindingPattern(node.name)); variableDeclarationNode = node; - name_27 = node.name; + name_28 = node.name; } if (ts.isConst(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.constElement); + return createItem(node, getTextOfNode(name_28), ts.ScriptElementKind.constElement); } else if (ts.isLet(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.letElement); + return createItem(node, getTextOfNode(name_28), ts.ScriptElementKind.letElement); } else { - return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.variableElement); + return createItem(node, getTextOfNode(name_28), ts.ScriptElementKind.variableElement); } case 136 /* Constructor */: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); @@ -35122,9 +35155,9 @@ var ts; } Rules.prototype.getRuleName = function (rule) { var o = this; - for (var name_28 in o) { - if (o[name_28] === rule) { - return name_28; + for (var name_29 in o) { + if (o[name_29] === rule) { + return name_29; } } throw new Error("Unknown rule"); @@ -39458,10 +39491,10 @@ var ts; for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { var sourceFile = _a[_i]; var nameTable = getNameTable(sourceFile); - for (var name_29 in nameTable) { - if (!allNames[name_29]) { - allNames[name_29] = name_29; - var displayName = getCompletionEntryDisplayName(name_29, target, true); + for (var name_30 in nameTable) { + if (!allNames[name_30]) { + allNames[name_30] = name_30; + var displayName = getCompletionEntryDisplayName(name_30, target, true); if (displayName) { var entry = { name: displayName, @@ -41343,19 +41376,19 @@ var ts; if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; var contextualType = typeChecker.getContextualType(objectLiteral); - var name_30 = node.text; + var name_31 = node.text; if (contextualType) { if (contextualType.flags & 16384 /* Union */) { // This is a union type, first see if the property we are looking for is a union property (i.e. exists in all types) // if not, search the constituent types for the property - var unionProperty = contextualType.getProperty(name_30); + var unionProperty = contextualType.getProperty(name_31); if (unionProperty) { return [unionProperty]; } else { var result_4 = []; ts.forEach(contextualType.types, function (t) { - var symbol = t.getProperty(name_30); + var symbol = t.getProperty(name_31); if (symbol) { result_4.push(symbol); } @@ -41364,7 +41397,7 @@ var ts; } } else { - var symbol_1 = contextualType.getProperty(name_30); + var symbol_1 = contextualType.getProperty(name_31); if (symbol_1) { return [symbol_1]; } diff --git a/bin/typescriptServices.d.ts b/bin/typescriptServices.d.ts index ea7d2a352ec..9a153ade4b1 100644 --- a/bin/typescriptServices.d.ts +++ b/bin/typescriptServices.d.ts @@ -857,7 +857,7 @@ declare module ts { getCurrentDirectory(): string; } interface ParseConfigHost { - readDirectory(rootDir: string, extension: string): string[]; + readDirectory(rootDir: string, extension: string, exclude: string[]): string[]; } interface WriteFileCallback { (fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void; @@ -1091,8 +1091,9 @@ declare module ts { Tuple = 8192, Union = 16384, Anonymous = 32768, - ObjectLiteral = 131072, - ESSymbol = 1048576, + Instantiated = 65536, + ObjectLiteral = 262144, + ESSymbol = 2097152, StringLike = 258, NumberLike = 132, ObjectType = 48128, @@ -1281,7 +1282,7 @@ declare module ts { createDirectory(path: string): void; getExecutingFilePath(): string; getCurrentDirectory(): string; - readDirectory(path: string, extension?: string): string[]; + readDirectory(path: string, extension?: string, exclude?: string[]): string[]; getMemoryUsage?(): number; exit(exitCode?: number): void; } diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js index 5875495d5e6..3dd6dd919be 100644 --- a/bin/typescriptServices.js +++ b/bin/typescriptServices.js @@ -532,23 +532,24 @@ var ts; TypeFlags[TypeFlags["Tuple"] = 8192] = "Tuple"; TypeFlags[TypeFlags["Union"] = 16384] = "Union"; TypeFlags[TypeFlags["Anonymous"] = 32768] = "Anonymous"; + TypeFlags[TypeFlags["Instantiated"] = 65536] = "Instantiated"; /* @internal */ - TypeFlags[TypeFlags["FromSignature"] = 65536] = "FromSignature"; - TypeFlags[TypeFlags["ObjectLiteral"] = 131072] = "ObjectLiteral"; + TypeFlags[TypeFlags["FromSignature"] = 131072] = "FromSignature"; + TypeFlags[TypeFlags["ObjectLiteral"] = 262144] = "ObjectLiteral"; /* @internal */ - TypeFlags[TypeFlags["ContainsUndefinedOrNull"] = 262144] = "ContainsUndefinedOrNull"; + TypeFlags[TypeFlags["ContainsUndefinedOrNull"] = 524288] = "ContainsUndefinedOrNull"; /* @internal */ - TypeFlags[TypeFlags["ContainsObjectLiteral"] = 524288] = "ContainsObjectLiteral"; - TypeFlags[TypeFlags["ESSymbol"] = 1048576] = "ESSymbol"; + TypeFlags[TypeFlags["ContainsObjectLiteral"] = 1048576] = "ContainsObjectLiteral"; + TypeFlags[TypeFlags["ESSymbol"] = 2097152] = "ESSymbol"; /* @internal */ - TypeFlags[TypeFlags["Intrinsic"] = 1048703] = "Intrinsic"; + TypeFlags[TypeFlags["Intrinsic"] = 2097279] = "Intrinsic"; /* @internal */ - TypeFlags[TypeFlags["Primitive"] = 1049086] = "Primitive"; + TypeFlags[TypeFlags["Primitive"] = 2097662] = "Primitive"; TypeFlags[TypeFlags["StringLike"] = 258] = "StringLike"; TypeFlags[TypeFlags["NumberLike"] = 132] = "NumberLike"; TypeFlags[TypeFlags["ObjectType"] = 48128] = "ObjectType"; /* @internal */ - TypeFlags[TypeFlags["RequiresWidening"] = 786432] = "RequiresWidening"; + TypeFlags[TypeFlags["RequiresWidening"] = 1572864] = "RequiresWidening"; })(ts.TypeFlags || (ts.TypeFlags = {})); var TypeFlags = ts.TypeFlags; (function (SignatureKind) { @@ -1506,6 +1507,9 @@ var ts; fileStream.Close(); } } + function getCanonicalPath(path) { + return path.toLowerCase(); + } function getNames(collection) { var result = []; for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) { @@ -1513,23 +1517,28 @@ var ts; } return result.sort(); } - function readDirectory(path, extension) { + function readDirectory(path, extension, exclude) { var result = []; + exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); visitDirectory(path); return result; function visitDirectory(path) { var folder = fso.GetFolder(path || "."); var files = getNames(folder.files); for (var _i = 0; _i < files.length; _i++) { - var name_1 = files[_i]; - if (!extension || ts.fileExtensionIs(name_1, extension)) { - result.push(ts.combinePaths(path, name_1)); + var current = files[_i]; + var name_1 = ts.combinePaths(path, current); + if ((!extension || ts.fileExtensionIs(name_1, extension)) && !ts.contains(exclude, getCanonicalPath(name_1))) { + result.push(name_1); } } var subfolders = getNames(folder.subfolders); for (var _a = 0; _a < subfolders.length; _a++) { var current = subfolders[_a]; - visitDirectory(ts.combinePaths(path, current)); + var name_2 = ts.combinePaths(path, current); + if (!ts.contains(exclude, getCanonicalPath(name_2))) { + visitDirectory(name_2); + } } } } @@ -1614,8 +1623,12 @@ var ts; } _fs.writeFileSync(fileName, data, "utf8"); } - function readDirectory(path, extension) { + function getCanonicalPath(path) { + return useCaseSensitiveFileNames ? path.toLowerCase() : path; + } + function readDirectory(path, extension, exclude) { var result = []; + exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); visitDirectory(path); return result; function visitDirectory(path) { @@ -1624,14 +1637,16 @@ var ts; for (var _i = 0; _i < files.length; _i++) { var current = files[_i]; var name = ts.combinePaths(path, current); - var stat = _fs.statSync(name); - if (stat.isFile()) { - if (!extension || ts.fileExtensionIs(name, extension)) { - result.push(name); + if (!ts.contains(exclude, getCanonicalPath(name))) { + var stat = _fs.statSync(name); + if (stat.isFile()) { + if (!extension || ts.fileExtensionIs(name, extension)) { + result.push(name); + } + } + else if (stat.isDirectory()) { + directories.push(name); } - } - else if (stat.isDirectory()) { - directories.push(name); } } for (var _a = 0; _a < directories.length; _a++) { @@ -2239,7 +2254,7 @@ var ts; Object_literal_s_property_0_implicitly_has_an_1_type: { code: 7018, category: ts.DiagnosticCategory.Error, key: "Object literal's property '{0}' implicitly has an '{1}' type." }, Rest_parameter_0_implicitly_has_an_any_type: { code: 7019, category: ts.DiagnosticCategory.Error, key: "Rest parameter '{0}' implicitly has an 'any[]' type." }, Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: { code: 7020, category: ts.DiagnosticCategory.Error, key: "Call signature, which lacks return-type annotation, implicitly has an 'any' return type." }, - _0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer." }, + _0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer." }, _0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: ts.DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type: { code: 7025, category: ts.DiagnosticCategory.Error, key: "Generator implicitly has type '{0}' because it does not yield any values. Consider supplying a return type." }, @@ -2466,9 +2481,9 @@ var ts; } function makeReverseMap(source) { var result = []; - for (var name_2 in source) { - if (source.hasOwnProperty(name_2)) { - result[source[name_2]] = name_2; + for (var name_3 in source) { + if (source.hasOwnProperty(name_3)) { + result[source[name_3]] = name_3; } } return result; @@ -4815,11 +4830,11 @@ var ts; return; default: if (isFunctionLike(node)) { - var name_3 = node.name; - if (name_3 && name_3.kind === 128 /* ComputedPropertyName */) { + var name_4 = node.name; + if (name_4 && name_4.kind === 128 /* ComputedPropertyName */) { // Note that we will not include methods/accessors of a class because they would require // first descending into the class. This is by design. - traverse(name_3.expression); + traverse(name_4.expression); return; } } @@ -5268,8 +5283,8 @@ var ts; return ts.forEach(docComment.tags, function (t) { if (t.kind === 247 /* JSDocParameterTag */) { var parameterTag = t; - var name_4 = parameterTag.preParameterName || parameterTag.postParameterName; - if (name_4.text === parameterName) { + var name_5 = parameterTag.preParameterName || parameterTag.postParameterName; + if (name_5.text === parameterName) { return t; } } @@ -10289,8 +10304,8 @@ var ts; } if (decorators) { // treat this as a property declaration with a missing name. - var name_5 = createMissingNode(65 /* Identifier */, true, ts.Diagnostics.Declaration_expected); - return parsePropertyDeclaration(fullStart, decorators, modifiers, name_5, undefined); + var name_6 = createMissingNode(65 /* Identifier */, true, ts.Diagnostics.Declaration_expected); + return parsePropertyDeclaration(fullStart, decorators, modifiers, name_6, undefined); } // 'isClassMemberStart' should have hinted not to attempt parsing. ts.Debug.fail("Should not have attempted to parse class member declaration."); @@ -11240,13 +11255,13 @@ var ts; while (true) { skipWhitespace(); var startPos = pos; - var name_6 = scanIdentifier(); - if (!name_6) { + var name_7 = scanIdentifier(); + if (!name_7) { parseErrorAtPosition(startPos, 0, ts.Diagnostics.Identifier_expected); return undefined; } - var typeParameter = createNode(129 /* TypeParameter */, name_6.pos); - typeParameter.name = name_6; + var typeParameter = createNode(129 /* TypeParameter */, name_7.pos); + typeParameter.name = name_7; finishNode(typeParameter, pos); typeParameters.push(typeParameter); skipWhitespace(); @@ -11831,10 +11846,10 @@ var ts; var stringType = createIntrinsicType(2 /* String */, "string"); var numberType = createIntrinsicType(4 /* Number */, "number"); var booleanType = createIntrinsicType(8 /* Boolean */, "boolean"); - var esSymbolType = createIntrinsicType(1048576 /* ESSymbol */, "symbol"); + var esSymbolType = createIntrinsicType(2097152 /* ESSymbol */, "symbol"); var voidType = createIntrinsicType(16 /* Void */, "void"); - var undefinedType = createIntrinsicType(32 /* Undefined */ | 262144 /* ContainsUndefinedOrNull */, "undefined"); - var nullType = createIntrinsicType(64 /* Null */ | 262144 /* ContainsUndefinedOrNull */, "null"); + var undefinedType = createIntrinsicType(32 /* Undefined */ | 524288 /* ContainsUndefinedOrNull */, "undefined"); + var nullType = createIntrinsicType(64 /* Null */ | 524288 /* ContainsUndefinedOrNull */, "null"); var unknownType = createIntrinsicType(1 /* Any */, "unknown"); var circularType = createIntrinsicType(1 /* Any */, "__circular__"); var emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); @@ -11891,7 +11906,7 @@ var ts; }, "symbol": { type: esSymbolType, - flags: 1048576 /* ESSymbol */ + flags: 2097152 /* ESSymbol */ } }; function getEmitResolver(sourceFile) { @@ -12398,15 +12413,15 @@ var ts; var moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier); var targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier); if (targetSymbol) { - var name_7 = specifier.propertyName || specifier.name; - if (name_7.text) { - var symbolFromModule = getExportOfModule(targetSymbol, name_7.text); - var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_7.text); + var name_8 = specifier.propertyName || specifier.name; + if (name_8.text) { + var symbolFromModule = getExportOfModule(targetSymbol, name_8.text); + var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_8.text); var symbol = symbolFromModule && symbolFromVariable ? combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - error(name_7, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_7)); + error(name_8, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_8)); } return symbol; } @@ -13112,15 +13127,16 @@ var ts; } return appendParentTypeArgumentsAndSymbolName(symbol); } - function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, typeStack) { + function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, symbolStack) { var globalFlagsToPass = globalFlags & 16 /* WriteOwnNameForAnyLike */; return writeType(type, globalFlags); function writeType(type, flags) { // Write undefined/null type as any - if (type.flags & 1048703 /* Intrinsic */) { + if (type.flags & 2097279 /* Intrinsic */) { // Special handling for unknown / resolving types, they should show up as any and not unknown or __resolving - writer.writeKeyword(!(globalFlags & 16 /* WriteOwnNameForAnyLike */) && - (type.flags & 1 /* Any */) ? "any" : type.intrinsicName); + writer.writeKeyword(!(globalFlags & 16 /* WriteOwnNameForAnyLike */) && isTypeAny(type) + ? "any" + : type.intrinsicName); } else if (type.flags & 4096 /* Reference */) { writeTypeReference(type, flags); @@ -13228,47 +13244,54 @@ var ts; } } function writeAnonymousType(type, flags) { - // Always use 'typeof T' for type of class, enum, and module objects - if (type.symbol && type.symbol.flags & (32 /* Class */ | 384 /* Enum */ | 512 /* ValueModule */)) { - writeTypeofSymbol(type, flags); - } - else if (shouldWriteTypeOfFunctionSymbol()) { - writeTypeofSymbol(type, flags); - } - else if (typeStack && ts.contains(typeStack, type)) { - // If type is an anonymous type literal in a type alias declaration, use type alias name - var typeAlias = getTypeAliasForTypeLiteral(type); - if (typeAlias) { - // The specified symbol flags need to be reinterpreted as type flags - buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056 /* Type */, 0 /* None */, flags); + var symbol = type.symbol; + if (symbol) { + // Always use 'typeof T' for type of class, enum, and module objects + if (symbol.flags & (32 /* Class */ | 384 /* Enum */ | 512 /* ValueModule */)) { + writeTypeofSymbol(type, flags); + } + else if (shouldWriteTypeOfFunctionSymbol()) { + writeTypeofSymbol(type, flags); + } + else if (ts.contains(symbolStack, symbol)) { + // If type is an anonymous type literal in a type alias declaration, use type alias name + var typeAlias = getTypeAliasForTypeLiteral(type); + if (typeAlias) { + // The specified symbol flags need to be reinterpreted as type flags + buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056 /* Type */, 0 /* None */, flags); + } + else { + // Recursive usage, use any + writeKeyword(writer, 112 /* AnyKeyword */); + } } else { - // Recursive usage, use any - writeKeyword(writer, 112 /* AnyKeyword */); + // Since instantiations of the same anonymous type have the same symbol, tracking symbols instead + // of types allows us to catch circular references to instantiations of the same anonymous type + if (!symbolStack) { + symbolStack = []; + } + symbolStack.push(symbol); + writeLiteralType(type, flags); + symbolStack.pop(); } } else { - if (!typeStack) { - typeStack = []; - } - typeStack.push(type); + // Anonymous types with no symbol are never circular writeLiteralType(type, flags); - typeStack.pop(); } function shouldWriteTypeOfFunctionSymbol() { - if (type.symbol) { - var isStaticMethodSymbol = !!(type.symbol.flags & 8192 /* Method */ && - ts.forEach(type.symbol.declarations, function (declaration) { return declaration.flags & 128 /* Static */; })); - var isNonLocalFunctionSymbol = !!(type.symbol.flags & 16 /* Function */) && - (type.symbol.parent || - ts.forEach(type.symbol.declarations, function (declaration) { - return declaration.parent.kind === 228 /* SourceFile */ || declaration.parent.kind === 207 /* ModuleBlock */; - })); - if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { - // typeof is allowed only for static/non local functions - return !!(flags & 2 /* UseTypeOfFunction */) || - (typeStack && ts.contains(typeStack, type)); // it is type of the symbol uses itself recursively - } + var isStaticMethodSymbol = !!(symbol.flags & 8192 /* Method */ && + ts.forEach(symbol.declarations, function (declaration) { return declaration.flags & 128 /* Static */; })); + var isNonLocalFunctionSymbol = !!(symbol.flags & 16 /* Function */) && + (symbol.parent || + ts.forEach(symbol.declarations, function (declaration) { + return declaration.parent.kind === 228 /* SourceFile */ || declaration.parent.kind === 207 /* ModuleBlock */; + })); + if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { + // typeof is allowed only for static/non local functions + return !!(flags & 2 /* UseTypeOfFunction */) || + (ts.contains(symbolStack, symbol)); // it is type of the symbol uses itself recursively } } } @@ -13299,7 +13322,7 @@ var ts; if (flags & 64 /* InElementType */) { writePunctuation(writer, 16 /* OpenParenToken */); } - buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, typeStack); + buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, symbolStack); if (flags & 64 /* InElementType */) { writePunctuation(writer, 17 /* CloseParenToken */); } @@ -13311,7 +13334,7 @@ var ts; } writeKeyword(writer, 88 /* NewKeyword */); writeSpace(writer); - buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, typeStack); + buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, symbolStack); if (flags & 64 /* InElementType */) { writePunctuation(writer, 17 /* CloseParenToken */); } @@ -13323,7 +13346,7 @@ var ts; writer.increaseIndent(); for (var _i = 0, _a = resolved.callSignatures; _i < _a.length; _i++) { var signature = _a[_i]; - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22 /* SemicolonToken */); writer.writeLine(); } @@ -13331,7 +13354,7 @@ var ts; var signature = _c[_b]; writeKeyword(writer, 88 /* NewKeyword */); writeSpace(writer); - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22 /* SemicolonToken */); writer.writeLine(); } @@ -13374,7 +13397,7 @@ var ts; if (p.flags & 536870912 /* Optional */) { writePunctuation(writer, 50 /* QuestionToken */); } - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22 /* SemicolonToken */); writer.writeLine(); } @@ -13401,17 +13424,17 @@ var ts; buildDisplayForTypeParametersAndDelimiters(getLocalTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); } } - function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, typeStack) { + function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, symbolStack) { appendSymbolNameOnly(tp.symbol, writer); var constraint = getConstraintOfTypeParameter(tp); if (constraint) { writeSpace(writer); writeKeyword(writer, 79 /* ExtendsKeyword */); writeSpace(writer); - buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, symbolStack); } } - function buildParameterDisplay(p, writer, enclosingDeclaration, flags, typeStack) { + function buildParameterDisplay(p, writer, enclosingDeclaration, flags, symbolStack) { var parameterNode = p.valueDeclaration; if (ts.isRestParameter(parameterNode)) { writePunctuation(writer, 21 /* DotDotDotToken */); @@ -13422,9 +13445,9 @@ var ts; } writePunctuation(writer, 51 /* ColonToken */); writeSpace(writer); - buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, symbolStack); } - function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, symbolStack) { if (typeParameters && typeParameters.length) { writePunctuation(writer, 24 /* LessThanToken */); for (var i = 0; i < typeParameters.length; i++) { @@ -13432,12 +13455,12 @@ var ts; writePunctuation(writer, 23 /* CommaToken */); writeSpace(writer); } - buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, typeStack); + buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, symbolStack); } writePunctuation(writer, 25 /* GreaterThanToken */); } } - function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, symbolStack) { if (typeParameters && typeParameters.length) { writePunctuation(writer, 24 /* LessThanToken */); for (var i = 0; i < typeParameters.length; i++) { @@ -13450,18 +13473,18 @@ var ts; writePunctuation(writer, 25 /* GreaterThanToken */); } } - function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, symbolStack) { writePunctuation(writer, 16 /* OpenParenToken */); for (var i = 0; i < parameters.length; i++) { if (i > 0) { writePunctuation(writer, 23 /* CommaToken */); writeSpace(writer); } - buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, typeStack); + buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, symbolStack); } writePunctuation(writer, 17 /* CloseParenToken */); } - function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack) { if (flags & 8 /* WriteArrowStyleSignature */) { writeSpace(writer); writePunctuation(writer, 32 /* EqualsGreaterThanToken */); @@ -13470,19 +13493,19 @@ var ts; writePunctuation(writer, 51 /* ColonToken */); } writeSpace(writer); - buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, symbolStack); } - function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, symbolStack) { if (signature.target && (flags & 32 /* WriteTypeArgumentsOfSignature */)) { // Instantiated signature, write type arguments instead // This is achieved by passing in the mapper separately buildDisplayForTypeArgumentsAndDelimiters(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration); } else { - buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, typeStack); + buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, symbolStack); } - buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, typeStack); - buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack); + buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, symbolStack); + buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack); } return _displayBuilder || (_displayBuilder = { symbolToString: symbolToString, @@ -13710,6 +13733,9 @@ var ts; var prop = getPropertyOfType(type, name); return prop ? getTypeOfSymbol(prop) : undefined; } + function isTypeAny(type) { + return type && (type.flags & 1 /* Any */) !== 0; + } // Return the inferred type for a binding element function getTypeForBindingElement(declaration) { var pattern = declaration.parent; @@ -13721,7 +13747,7 @@ var ts; // If no type was specified or inferred for parent, or if the specified or inferred type is any, // infer from the initializer of the binding element if one is present. Otherwise, go with the // undefined or any type of the parent. - if (!parentType || parentType === anyType) { + if (!parentType || isTypeAny(parentType)) { if (declaration.initializer) { return checkExpressionCached(declaration.initializer); } @@ -13730,14 +13756,14 @@ var ts; var type; if (pattern.kind === 151 /* ObjectBindingPattern */) { // Use explicitly specified property name ({ p: xxx } form), or otherwise the implied name ({ p } form) - var name_8 = declaration.propertyName || declaration.name; + var name_9 = declaration.propertyName || declaration.name; // Use type of the specified property, or otherwise, for a numeric name, the type of the numeric index signature, // or otherwise the type of the string index signature. - type = getTypeOfPropertyOfType(parentType, name_8.text) || - isNumericLiteralName(name_8.text) && getIndexTypeOfType(parentType, 1 /* Number */) || + type = getTypeOfPropertyOfType(parentType, name_9.text) || + isNumericLiteralName(name_9.text) && getIndexTypeOfType(parentType, 1 /* Number */) || getIndexTypeOfType(parentType, 0 /* String */); if (!type) { - error(name_8, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_8)); + error(name_9, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_9)); return unknownType; } } @@ -13747,7 +13773,7 @@ var ts; // fact an iterable or array (depending on target language). var elementType = checkIteratedTypeOrElementType(parentType, pattern, false); if (!declaration.dotDotDotToken) { - if (elementType.flags & 1 /* Any */) { + if (isTypeAny(elementType)) { return elementType; } // Use specific property type when parent is a tuple or numeric index type when parent is an array @@ -13941,7 +13967,7 @@ var ts; // Variable has initializer that circularly references the variable itself type = anyType; if (compilerOptions.noImplicitAny) { - error(symbol.valueDeclaration, ts.Diagnostics._0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol)); + error(symbol.valueDeclaration, ts.Diagnostics._0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol)); } } } @@ -14584,7 +14610,7 @@ var ts; else if (type.flags & 8 /* Boolean */) { type = globalBooleanType; } - else if (type.flags & 1048576 /* ESSymbol */) { + else if (type.flags & 2097152 /* ESSymbol */) { type = globalESSymbolType; } return type; @@ -14859,7 +14885,7 @@ var ts; // will result in a different declaration kind. if (!signature.isolatedSignatureType) { var isConstructor = signature.declaration.kind === 136 /* Constructor */ || signature.declaration.kind === 140 /* ConstructSignature */; - var type = createObjectType(32768 /* Anonymous */ | 65536 /* FromSignature */); + var type = createObjectType(32768 /* Anonymous */ | 131072 /* FromSignature */); type.members = emptySymbols; type.properties = emptyArray; type.callSignatures = !isConstructor ? [signature] : emptyArray; @@ -14936,7 +14962,7 @@ var ts; var type = types[_i]; result |= type.flags; } - return result & 786432 /* RequiresWidening */; + return result & 1572864 /* RequiresWidening */; } function createTypeReference(target, typeArguments) { var id = getTypeListId(typeArguments); @@ -15180,10 +15206,10 @@ var ts; } } } - function containsAnyType(types) { + function containsTypeAny(types) { for (var _i = 0; _i < types.length; _i++) { var type = types[_i]; - if (type.flags & 1 /* Any */) { + if (isTypeAny(type)) { return true; } } @@ -15209,7 +15235,7 @@ var ts; var sortedTypes = []; addTypesToSortedSet(sortedTypes, types); if (noSubtypeReduction) { - if (containsAnyType(sortedTypes)) { + if (containsTypeAny(sortedTypes)) { return anyType; } removeAllButLast(sortedTypes, undefinedType); @@ -15435,19 +15461,8 @@ var ts; return result; } function instantiateAnonymousType(type, mapper) { - // If this type has already been instantiated using this mapper, returned the cached result. This guards against - // infinite instantiations of cyclic types, e.g. "var x: { a: T, b: typeof x };" - if (mapper.mappings) { - var cached = mapper.mappings[type.id]; - if (cached) { - return cached; - } - } - else { - mapper.mappings = {}; - } - // Instantiate the given type using the given mapper and cache the result - var result = createObjectType(32768 /* Anonymous */, type.symbol); + // Mark the anonymous type as instantiated such that our infinite instantiation detection logic can recognize it + var result = createObjectType(32768 /* Anonymous */ | 65536 /* Instantiated */, type.symbol); result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); result.members = createSymbolTable(result.properties); result.callSignatures = instantiateList(getSignaturesOfType(type, 0 /* Call */), mapper, instantiateSignature); @@ -15458,7 +15473,6 @@ var ts; result.stringIndexType = instantiateType(stringIndexType, mapper); if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper); - mapper.mappings[type.id] = result; return result; } function instantiateType(type, mapper) { @@ -15597,7 +15611,7 @@ var ts; if (source === target) return -1 /* True */; if (relation !== identityRelation) { - if (target.flags & 1 /* Any */) + if (isTypeAny(target)) return -1 /* True */; if (source === undefinedType) return -1 /* True */; @@ -15608,7 +15622,7 @@ var ts; if (source.flags & 256 /* StringLiteral */ && target === stringType) return -1 /* True */; if (relation === assignableRelation) { - if (source.flags & 1 /* Any */) + if (isTypeAny(source)) return -1 /* True */; if (source === numberType && target.flags & 128 /* Enum */) return -1 /* True */; @@ -15851,12 +15865,13 @@ var ts; // Effectively, we will generate a false positive when two types are structurally equal to at least 10 levels, but unequal at // some level beyond that. function isDeeplyNestedGeneric(type, stack) { - if (type.flags & 4096 /* Reference */ && depth >= 10) { - var target_1 = type.target; + // We track type references (created by createTypeReference) and instantiated types (created by instantiateType) + if (type.flags & (4096 /* Reference */ | 65536 /* Instantiated */) && depth >= 10) { + var symbol = type.symbol; var count = 0; for (var i = 0; i < depth; i++) { var t = stack[i]; - if (t.flags & 4096 /* Reference */ && t.target === target_1) { + if (t.flags & (4096 /* Reference */ | 65536 /* Instantiated */) && t.symbol === symbol) { count++; if (count >= 10) return true; @@ -15871,7 +15886,7 @@ var ts; } var result = -1 /* True */; var properties = getPropertiesOfObjectType(target); - var requireOptionalProperties = relation === subtypeRelation && !(source.flags & 131072 /* ObjectLiteral */); + var requireOptionalProperties = relation === subtypeRelation && !(source.flags & 262144 /* ObjectLiteral */); for (var _i = 0; _i < properties.length; _i++) { var targetProp = properties[_i]; var sourceProp = getPropertyOfType(source, targetProp.name); @@ -15977,11 +15992,11 @@ var ts; var saveErrorInfo = errorInfo; outer: for (var _i = 0; _i < targetSignatures.length; _i++) { var t = targetSignatures[_i]; - if (!t.hasStringLiterals || target.flags & 65536 /* FromSignature */) { + if (!t.hasStringLiterals || target.flags & 131072 /* FromSignature */) { var localErrors = reportErrors; for (var _a = 0; _a < sourceSignatures.length; _a++) { var s = sourceSignatures[_a]; - if (!s.hasStringLiterals || source.flags & 65536 /* FromSignature */) { + if (!s.hasStringLiterals || source.flags & 131072 /* FromSignature */) { var related = signatureRelatedTo(s, t, localErrors); if (related) { result &= related; @@ -16293,11 +16308,11 @@ var ts; return createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType); } function getWidenedType(type) { - if (type.flags & 786432 /* RequiresWidening */) { + if (type.flags & 1572864 /* RequiresWidening */) { if (type.flags & (32 /* Undefined */ | 64 /* Null */)) { return anyType; } - if (type.flags & 131072 /* ObjectLiteral */) { + if (type.flags & 262144 /* ObjectLiteral */) { return getWidenedTypeOfObjectLiteral(type); } if (type.flags & 16384 /* Union */) { @@ -16322,11 +16337,11 @@ var ts; if (isArrayType(type)) { return reportWideningErrorsInType(type.typeArguments[0]); } - if (type.flags & 131072 /* ObjectLiteral */) { + if (type.flags & 262144 /* ObjectLiteral */) { var errorReported = false; ts.forEach(getPropertiesOfObjectType(type), function (p) { var t = getTypeOfSymbol(p); - if (t.flags & 262144 /* ContainsUndefinedOrNull */) { + if (t.flags & 524288 /* ContainsUndefinedOrNull */) { if (!reportWideningErrorsInType(t)) { error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(getWidenedType(t))); } @@ -16369,7 +16384,7 @@ var ts; error(declaration, diagnostic, ts.declarationNameToString(declaration.name), typeAsString); } function reportErrorsFromWidening(declaration, type) { - if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 262144 /* ContainsUndefinedOrNull */) { + if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 524288 /* ContainsUndefinedOrNull */) { // Report implicit any error within type if possible, otherwise report error on declaration if (!reportWideningErrorsInType(type)) { reportImplicitAnyError(declaration, type); @@ -16431,11 +16446,11 @@ var ts; } function isWithinDepthLimit(type, stack) { if (depth >= 5) { - var target_2 = type.target; + var target_1 = type.target; var count = 0; for (var i = 0; i < depth; i++) { var t = stack[i]; - if (t.flags & 4096 /* Reference */ && t.target === target_2) { + if (t.flags & 4096 /* Reference */ && t.target === target_1) { count++; } } @@ -16778,52 +16793,54 @@ var ts; function getNarrowedTypeOfSymbol(symbol, node) { var type = getTypeOfSymbol(symbol); // Only narrow when symbol is variable of type any or an object, union, or type parameter type - if (node && symbol.flags & 3 /* Variable */ && type.flags & (1 /* Any */ | 48128 /* ObjectType */ | 16384 /* Union */ | 512 /* TypeParameter */)) { - loop: while (node.parent) { - var child = node; - node = node.parent; - var narrowedType = type; - switch (node.kind) { - case 184 /* IfStatement */: - // In a branch of an if statement, narrow based on controlling expression - if (child !== node.expression) { - narrowedType = narrowType(type, node.expression, child === node.thenStatement); - } - break; - case 171 /* ConditionalExpression */: - // In a branch of a conditional expression, narrow based on controlling condition - if (child !== node.condition) { - narrowedType = narrowType(type, node.condition, child === node.whenTrue); - } - break; - case 170 /* BinaryExpression */: - // In the right operand of an && or ||, narrow based on left operand - if (child === node.right) { - if (node.operatorToken.kind === 48 /* AmpersandAmpersandToken */) { - narrowedType = narrowType(type, node.left, true); + if (node && symbol.flags & 3 /* Variable */) { + if (isTypeAny(type) || type.flags & (48128 /* ObjectType */ | 16384 /* Union */ | 512 /* TypeParameter */)) { + loop: while (node.parent) { + var child = node; + node = node.parent; + var narrowedType = type; + switch (node.kind) { + case 184 /* IfStatement */: + // In a branch of an if statement, narrow based on controlling expression + if (child !== node.expression) { + narrowedType = narrowType(type, node.expression, child === node.thenStatement); } - else if (node.operatorToken.kind === 49 /* BarBarToken */) { - narrowedType = narrowType(type, node.left, false); + break; + case 171 /* ConditionalExpression */: + // In a branch of a conditional expression, narrow based on controlling condition + if (child !== node.condition) { + narrowedType = narrowType(type, node.condition, child === node.whenTrue); } - } - break; - case 228 /* SourceFile */: - case 206 /* ModuleDeclaration */: - case 201 /* FunctionDeclaration */: - case 135 /* MethodDeclaration */: - case 134 /* MethodSignature */: - case 137 /* GetAccessor */: - case 138 /* SetAccessor */: - case 136 /* Constructor */: - // Stop at the first containing function or module declaration - break loop; - } - // Use narrowed type if construct contains no assignments to variable - if (narrowedType !== type) { - if (isVariableAssignedWithin(symbol, node)) { - break; + break; + case 170 /* BinaryExpression */: + // In the right operand of an && or ||, narrow based on left operand + if (child === node.right) { + if (node.operatorToken.kind === 48 /* AmpersandAmpersandToken */) { + narrowedType = narrowType(type, node.left, true); + } + else if (node.operatorToken.kind === 49 /* BarBarToken */) { + narrowedType = narrowType(type, node.left, false); + } + } + break; + case 228 /* SourceFile */: + case 206 /* ModuleDeclaration */: + case 201 /* FunctionDeclaration */: + case 135 /* MethodDeclaration */: + case 134 /* MethodSignature */: + case 137 /* GetAccessor */: + case 138 /* SetAccessor */: + case 136 /* Constructor */: + // Stop at the first containing function or module declaration + break loop; + } + // Use narrowed type if construct contains no assignments to variable + if (narrowedType !== type) { + if (isVariableAssignedWithin(symbol, node)) { + break; + } + type = narrowedType; } - type = narrowedType; } } } @@ -16845,7 +16862,7 @@ var ts; if (assumeTrue) { // Assumed result is true. If check was not for a primitive type, remove all primitive types if (!typeInfo) { - return removeTypesFromUnionType(type, 258 /* StringLike */ | 132 /* NumberLike */ | 8 /* Boolean */ | 1048576 /* ESSymbol */, + return removeTypesFromUnionType(type, 258 /* StringLike */ | 132 /* NumberLike */ | 8 /* Boolean */ | 2097152 /* ESSymbol */, /*isOfTypeKind*/ true, false); } // Check was for a primitive type, return that primitive type if it is a subtype @@ -16895,7 +16912,7 @@ var ts; } function narrowTypeByInstanceof(type, expr, assumeTrue) { // Check that type is not any, assumed result is true, and we have variable symbol on the left - if (type.flags & 1 /* Any */ || !assumeTrue || expr.left.kind !== 65 /* Identifier */ || getResolvedSymbol(expr.left) !== symbol) { + if (isTypeAny(type) || !assumeTrue || expr.left.kind !== 65 /* Identifier */ || getResolvedSymbol(expr.left) !== symbol) { return type; } // Check that right operand is a function type with a prototype property @@ -16908,7 +16925,7 @@ var ts; if (prototypeProperty) { // Target type is type of the protoype property var prototypePropertyType = getTypeOfSymbol(prototypeProperty); - if (prototypePropertyType !== anyType) { + if (!isTypeAny(prototypePropertyType)) { targetType = prototypePropertyType; } } @@ -17591,7 +17608,10 @@ var ts; function isNumericComputedName(name) { // It seems odd to consider an expression of type Any to result in a numeric name, // but this behavior is consistent with checkIndexedAccess - return allConstituentTypesHaveKind(checkComputedPropertyName(name), 1 /* Any */ | 132 /* NumberLike */); + return isTypeAnyOrAllConstituentTypesHaveKind(checkComputedPropertyName(name), 132 /* NumberLike */); + } + function isTypeAnyOrAllConstituentTypesHaveKind(type, kind) { + return isTypeAny(type) || allConstituentTypesHaveKind(type, kind); } function isNumericLiteralName(name) { // The intent of numeric names is that @@ -17623,7 +17643,7 @@ var ts; links.resolvedType = checkExpression(node.expression); // This will allow types number, string, symbol or any. It will also allow enums, the unknown // type, and any union of these types (like string | number). - if (!allConstituentTypesHaveKind(links.resolvedType, 1 /* Any */ | 132 /* NumberLike */ | 258 /* StringLike */ | 1048576 /* ESSymbol */)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(links.resolvedType, 132 /* NumberLike */ | 258 /* StringLike */ | 2097152 /* ESSymbol */)) { error(node, ts.Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any); } else { @@ -17684,7 +17704,7 @@ var ts; var stringIndexType = getIndexType(0 /* String */); var numberIndexType = getIndexType(1 /* Number */); var result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType); - result.flags |= 131072 /* ObjectLiteral */ | 524288 /* ContainsObjectLiteral */ | (typeFlags & 262144 /* ContainsUndefinedOrNull */); + result.flags |= 262144 /* ObjectLiteral */ | 1048576 /* ContainsObjectLiteral */ | (typeFlags & 524288 /* ContainsUndefinedOrNull */); return result; function getIndexType(kind) { if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { @@ -17762,47 +17782,45 @@ var ts; } function checkPropertyAccessExpressionOrQualifiedName(node, left, right) { var type = checkExpressionOrQualifiedName(left); - if (type === unknownType) + if (isTypeAny(type)) { return type; - if (type !== anyType) { - var apparentType = getApparentType(getWidenedType(type)); - if (apparentType === unknownType) { - // handle cases when type is Type parameter with invalid constraint - return unknownType; - } - var prop = getPropertyOfType(apparentType, right.text); - if (!prop) { - if (right.text) { - error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type)); - } - return unknownType; - } - getNodeLinks(node).resolvedSymbol = prop; - if (prop.parent && prop.parent.flags & 32 /* Class */) { - // TS 1.0 spec (April 2014): 4.8.2 - // - In a constructor, instance member function, instance member accessor, or - // instance member variable initializer where this references a derived class instance, - // a super property access is permitted and must specify a public instance member function of the base class. - // - In a static member function or static member accessor - // where this references the constructor function object of a derived class, - // a super property access is permitted and must specify a public static member function of the base class. - if (left.kind === 91 /* SuperKeyword */ && getDeclarationKindFromSymbol(prop) !== 135 /* MethodDeclaration */) { - error(right, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); - } - else { - checkClassPropertyAccess(node, left, type, prop); - } - } - return getTypeOfSymbol(prop); } - return anyType; + var apparentType = getApparentType(getWidenedType(type)); + if (apparentType === unknownType) { + // handle cases when type is Type parameter with invalid constraint + return unknownType; + } + var prop = getPropertyOfType(apparentType, right.text); + if (!prop) { + if (right.text) { + error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type)); + } + return unknownType; + } + getNodeLinks(node).resolvedSymbol = prop; + if (prop.parent && prop.parent.flags & 32 /* Class */) { + // TS 1.0 spec (April 2014): 4.8.2 + // - In a constructor, instance member function, instance member accessor, or + // instance member variable initializer where this references a derived class instance, + // a super property access is permitted and must specify a public instance member function of the base class. + // - In a static member function or static member accessor + // where this references the constructor function object of a derived class, + // a super property access is permitted and must specify a public static member function of the base class. + if (left.kind === 91 /* SuperKeyword */ && getDeclarationKindFromSymbol(prop) !== 135 /* MethodDeclaration */) { + error(right, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); + } + else { + checkClassPropertyAccess(node, left, type, prop); + } + } + return getTypeOfSymbol(prop); } function isValidPropertyAccess(node, propertyName) { var left = node.kind === 156 /* PropertyAccessExpression */ ? node.expression : node.left; var type = checkExpressionOrQualifiedName(left); - if (type !== unknownType && type !== anyType) { + if (type !== unknownType && !isTypeAny(type)) { var prop = getPropertyOfType(getWidenedType(type), propertyName); if (prop && prop.parent && prop.parent.flags & 32 /* Class */) { if (left.kind === 91 /* SuperKeyword */ && getDeclarationKindFromSymbol(prop) !== 135 /* MethodDeclaration */) { @@ -17854,23 +17872,23 @@ var ts; // - Otherwise, if IndexExpr is of type Any, the String or Number primitive type, or an enum type, the property access is of type Any. // See if we can index as a property. if (node.argumentExpression) { - var name_9 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); - if (name_9 !== undefined) { - var prop = getPropertyOfType(objectType, name_9); + var name_10 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); + if (name_10 !== undefined) { + var prop = getPropertyOfType(objectType, name_10); if (prop) { getNodeLinks(node).resolvedSymbol = prop; return getTypeOfSymbol(prop); } else if (isConstEnum) { - error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_9, symbolToString(objectType.symbol)); + error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_10, symbolToString(objectType.symbol)); return unknownType; } } } // Check for compatible indexer types. - if (allConstituentTypesHaveKind(indexType, 1 /* Any */ | 258 /* StringLike */ | 132 /* NumberLike */ | 1048576 /* ESSymbol */)) { + if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, 258 /* StringLike */ | 132 /* NumberLike */ | 2097152 /* ESSymbol */)) { // Try to use a number indexer. - if (allConstituentTypesHaveKind(indexType, 1 /* Any */ | 132 /* NumberLike */)) { + if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, 132 /* NumberLike */)) { var numberIndexType = getIndexTypeOfType(objectType, 1 /* Number */); if (numberIndexType) { return numberIndexType; @@ -17882,7 +17900,7 @@ var ts; return stringIndexType; } // Fall back to any. - if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && objectType !== anyType) { + if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && !isTypeAny(objectType)) { error(node, ts.Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type); } return anyType; @@ -17923,7 +17941,7 @@ var ts; return false; } // Make sure the property type is the primitive symbol type - if ((expressionType.flags & 1048576 /* ESSymbol */) === 0) { + if ((expressionType.flags & 2097152 /* ESSymbol */) === 0) { if (reportError) { error(expression, ts.Diagnostics.A_computed_property_name_of_the_form_0_must_be_of_type_symbol, ts.getTextOfNode(expression)); } @@ -18461,8 +18479,10 @@ var ts; // types are provided for the argument expressions, and the result is always of type Any. // We exclude union types because we may have a union of function types that happen to have // no common signatures. - if (funcType === anyType || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384 /* Union */) && isTypeAssignableTo(funcType, globalFunctionType))) { - if (node.typeArguments) { + if (isTypeAny(funcType) || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384 /* Union */) && isTypeAssignableTo(funcType, globalFunctionType))) { + // The unknownType indicates that an error already occured (and was reported). No + // need to report another error in this case. + if (funcType !== unknownType && node.typeArguments) { error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } return resolveUntypedCall(node); @@ -18489,15 +18509,6 @@ var ts; } } var expressionType = checkExpression(node.expression); - // TS 1.0 spec: 4.11 - // If ConstructExpr is of type Any, Args can be any argument - // list and the result of the operation is of type Any. - if (expressionType === anyType) { - if (node.typeArguments) { - error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); - } - return resolveUntypedCall(node); - } // If ConstructExpr's apparent type(section 3.8.1) is an object type with one or // more construct signatures, the expression is processed in the same manner as a // function call, but using the construct signatures as the initial set of candidate @@ -18508,6 +18519,15 @@ var ts; // Another error has already been reported return resolveErrorCall(node); } + // TS 1.0 spec: 4.11 + // If ConstructExpr is of type Any, Args can be any argument + // list and the result of the operation is of type Any. + if (isTypeAny(expressionType)) { + if (node.typeArguments) { + error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); + } + return resolveUntypedCall(node); + } // Technically, this signatures list may be incomplete. We are taking the apparent type, // but we are not including construct signatures that may have been added to the Object or // Function interface, since they have none by default. This is a bit of a leap of faith @@ -18539,7 +18559,7 @@ var ts; return resolveErrorCall(node); } var callSignatures = getSignaturesOfType(apparentType, 0 /* Call */); - if (tagType === anyType || (!callSignatures.length && !(tagType.flags & 16384 /* Union */) && isTypeAssignableTo(tagType, globalFunctionType))) { + if (isTypeAny(tagType) || (!callSignatures.length && !(tagType.flags & 16384 /* Union */) && isTypeAssignableTo(tagType, globalFunctionType))) { return resolveUntypedCall(node); } if (!callSignatures.length) { @@ -18724,7 +18744,7 @@ var ts; return; } // Functions that return 'void' or 'any' don't need any return expressions. - if (returnType === voidType || returnType === anyType) { + if (returnType === voidType || isTypeAny(returnType)) { return; } // If all we have is a function signature, or an arrow function with an expression body, then there is nothing to check. @@ -18814,7 +18834,7 @@ var ts; } } function checkArithmeticOperandType(operand, type, diagnostic) { - if (!allConstituentTypesHaveKind(type, 1 /* Any */ | 132 /* NumberLike */)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(type, 132 /* NumberLike */)) { error(operand, diagnostic); return false; } @@ -18870,8 +18890,8 @@ var ts; var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 8 /* StringLiteral */) { - var name_10 = index.text; - var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_10); + var name_11 = index.text; + var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_11); return prop && (prop.flags & 3 /* Variable */) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 8192 /* Const */) !== 0; } return false; @@ -18923,7 +18943,7 @@ var ts; case 33 /* PlusToken */: case 34 /* MinusToken */: case 47 /* TildeToken */: - if (someConstituentTypeHasKind(operandType, 1048576 /* ESSymbol */)) { + if (someConstituentTypeHasKind(operandType, 2097152 /* ESSymbol */)) { error(node.operand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(node.operator)); } return numberType; @@ -19001,11 +19021,11 @@ var ts; // and the right operand to be of type Any or a subtype of the 'Function' interface type. // The result is always of the Boolean primitive type. // NOTE: do not raise error if leftType is unknown as related error was already reported - if (allConstituentTypesHaveKind(leftType, 1049086 /* Primitive */)) { + if (allConstituentTypesHaveKind(leftType, 2097662 /* Primitive */)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } // NOTE: do not raise error if right is unknown as related error was already reported - if (!(rightType.flags & 1 /* Any */ || isTypeSubtypeOf(rightType, globalFunctionType))) { + if (!(isTypeAny(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type); } return booleanType; @@ -19015,10 +19035,10 @@ var ts; // The in operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type, // and the right operand to be of type Any, an object type, or a type parameter type. // The result is always of the Boolean primitive type. - if (!allConstituentTypesHaveKind(leftType, 1 /* Any */ | 258 /* StringLike */ | 132 /* NumberLike */ | 1048576 /* ESSymbol */)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258 /* StringLike */ | 132 /* NumberLike */ | 2097152 /* ESSymbol */)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); } - if (!allConstituentTypesHaveKind(rightType, 1 /* Any */ | 48128 /* ObjectType */ | 512 /* TypeParameter */)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 48128 /* ObjectType */ | 512 /* TypeParameter */)) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; @@ -19029,16 +19049,17 @@ var ts; var p = properties[_i]; if (p.kind === 225 /* PropertyAssignment */ || p.kind === 226 /* ShorthandPropertyAssignment */) { // TODO(andersh): Computed property support - var name_11 = p.name; - var type = sourceType.flags & 1 /* Any */ ? sourceType : - getTypeOfPropertyOfType(sourceType, name_11.text) || - isNumericLiteralName(name_11.text) && getIndexTypeOfType(sourceType, 1 /* Number */) || + var name_12 = p.name; + var type = isTypeAny(sourceType) + ? sourceType + : getTypeOfPropertyOfType(sourceType, name_12.text) || + isNumericLiteralName(name_12.text) && getIndexTypeOfType(sourceType, 1 /* Number */) || getIndexTypeOfType(sourceType, 0 /* String */); if (type) { - checkDestructuringAssignment(p.initializer || name_11, type); + checkDestructuringAssignment(p.initializer || name_12, type); } else { - error(name_11, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_11)); + error(name_12, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_12)); } } else { @@ -19058,8 +19079,9 @@ var ts; if (e.kind !== 176 /* OmittedExpression */) { if (e.kind !== 174 /* SpreadElementExpression */) { var propName = "" + i; - var type = sourceType.flags & 1 /* Any */ ? sourceType : - isTupleLikeType(sourceType) + var type = isTypeAny(sourceType) + ? sourceType + : isTupleLikeType(sourceType) ? getTypeOfPropertyOfType(sourceType, propName) : elementType; if (type) { @@ -19194,10 +19216,10 @@ var ts; // If one or both operands are of the String primitive type, the result is of the String primitive type. resultType = stringType; } - else if (leftType.flags & 1 /* Any */ || rightType.flags & 1 /* Any */) { + else if (isTypeAny(leftType) || isTypeAny(rightType)) { // Otherwise, the result is of type Any. // NOTE: unknown type here denotes error type. Old compiler treated this case as any type so do we. - resultType = anyType; + resultType = leftType === unknownType || rightType === unknownType ? unknownType : anyType; } // Symbols are not allowed at all in arithmetic expressions if (resultType && !checkForDisallowedESSymbolOperand(operator)) { @@ -19244,8 +19266,8 @@ var ts; } // Return true if there was no error, false if there was an error. function checkForDisallowedESSymbolOperand(operator) { - var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 1048576 /* ESSymbol */) ? node.left : - someConstituentTypeHasKind(rightType, 1048576 /* ESSymbol */) ? node.right : + var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 2097152 /* ESSymbol */) ? node.left : + someConstituentTypeHasKind(rightType, 2097152 /* ESSymbol */) ? node.right : undefined; if (offendingSymbolOperand) { error(offendingSymbolOperand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(operator)); @@ -20161,7 +20183,7 @@ var ts; if (node && node.kind === 142 /* TypeReference */) { var type = getTypeFromTypeNode(node); var shouldCheckIfUnknownType = type === unknownType && compilerOptions.isolatedModules; - if (!type || (!shouldCheckIfUnknownType && type.flags & (1048703 /* Intrinsic */ | 132 /* NumberLike */ | 258 /* StringLike */))) { + if (!type || (!shouldCheckIfUnknownType && type.flags & (2097279 /* Intrinsic */ | 132 /* NumberLike */ | 258 /* StringLike */))) { return; } if (shouldCheckIfUnknownType || type.symbol.valueDeclaration) { @@ -20456,8 +20478,8 @@ var ts; // otherwise if variable has an initializer - show error that initialization will fail // since LHS will be block scoped name instead of function scoped if (!namesShareScope) { - var name_12 = symbolToString(localDeclarationSymbol); - error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_12, name_12); + var name_13 = symbolToString(localDeclarationSymbol); + error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_13, name_13); } } } @@ -20690,7 +20712,7 @@ var ts; if (varExpr.kind === 154 /* ArrayLiteralExpression */ || varExpr.kind === 155 /* ObjectLiteralExpression */) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); } - else if (!allConstituentTypesHaveKind(leftType, 1 /* Any */ | 258 /* StringLike */)) { + else if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258 /* StringLike */)) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any); } else { @@ -20701,7 +20723,7 @@ var ts; var rightType = checkExpression(node.expression); // unknownType is returned i.e. if node.expression is identifier whose name cannot be resolved // in this case error about missing name is already reported - do not report extra one - if (!allConstituentTypesHaveKind(rightType, 1 /* Any */ | 48128 /* ObjectType */ | 512 /* TypeParameter */)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 48128 /* ObjectType */ | 512 /* TypeParameter */)) { error(node.expression, ts.Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } checkSourceElement(node.statement); @@ -20719,7 +20741,7 @@ var ts; return checkIteratedTypeOrElementType(expressionType, rhsExpression, true); } function checkIteratedTypeOrElementType(inputType, errorNode, allowStringInput) { - if (inputType.flags & 1 /* Any */) { + if (isTypeAny(inputType)) { return inputType; } if (languageVersion >= 2 /* ES6 */) { @@ -20771,7 +20793,7 @@ var ts; * whole pattern and that T (above) is 'any'. */ function getElementTypeOfIterable(type, errorNode) { - if (type.flags & 1 /* Any */) { + if (isTypeAny(type)) { return undefined; } var typeAsIterable = type; @@ -20783,7 +20805,7 @@ var ts; } else { var iteratorFunction = getTypeOfPropertyOfType(type, ts.getPropertyNameForKnownSymbolName("iterator")); - if (iteratorFunction && iteratorFunction.flags & 1 /* Any */) { + if (isTypeAny(iteratorFunction)) { return undefined; } var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0 /* Call */) : emptyArray; @@ -20812,7 +20834,7 @@ var ts; * */ function getElementTypeOfIterator(type, errorNode) { - if (type.flags & 1 /* Any */) { + if (isTypeAny(type)) { return undefined; } var typeAsIterator = type; @@ -20824,7 +20846,7 @@ var ts; } else { var iteratorNextFunction = getTypeOfPropertyOfType(type, "next"); - if (iteratorNextFunction && iteratorNextFunction.flags & 1 /* Any */) { + if (isTypeAny(iteratorNextFunction)) { return undefined; } var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0 /* Call */) : emptyArray; @@ -20835,7 +20857,7 @@ var ts; return undefined; } var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); - if (iteratorNextResult.flags & 1 /* Any */) { + if (isTypeAny(iteratorNextResult)) { return undefined; } var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value"); @@ -20851,7 +20873,7 @@ var ts; return typeAsIterator.iteratorElementType; } function getElementTypeOfIterableIterator(type) { - if (type.flags & 1 /* Any */) { + if (isTypeAny(type)) { return undefined; } // As an optimization, if the type is instantiated directly using the globalIterableIteratorType (IterableIterator), @@ -22480,9 +22502,9 @@ var ts; function getRootSymbols(symbol) { if (symbol.flags & 268435456 /* UnionProperty */) { var symbols = []; - var name_13 = symbol.name; + var name_14 = symbol.name; ts.forEach(getSymbolLinks(symbol).unionType.types, function (t) { - symbols.push(getPropertyOfType(t, name_13)); + symbols.push(getPropertyOfType(t, name_14)); }); return symbols; } @@ -22700,7 +22722,7 @@ var ts; else if (type.flags & 8192 /* Tuple */) { return "Array"; } - else if (type.flags & 1048576 /* ESSymbol */) { + else if (type.flags & 2097152 /* ESSymbol */) { return "Symbol"; } else if (type === unknownType) { @@ -22992,20 +23014,20 @@ var ts; if (impotClause.namedBindings) { var nameBindings = impotClause.namedBindings; if (nameBindings.kind === 212 /* NamespaceImport */) { - var name_14 = nameBindings.name; - if (isReservedWordInStrictMode(name_14)) { - var nameText = ts.declarationNameToString(name_14); - return grammarErrorOnNode(name_14, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_15 = nameBindings.name; + if (isReservedWordInStrictMode(name_15)) { + var nameText = ts.declarationNameToString(name_15); + return grammarErrorOnNode(name_15, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } else if (nameBindings.kind === 213 /* NamedImports */) { var reportError = false; for (var _i = 0, _a = nameBindings.elements; _i < _a.length; _i++) { var element = _a[_i]; - var name_15 = element.name; - if (isReservedWordInStrictMode(name_15)) { - var nameText = ts.declarationNameToString(name_15); - reportError = reportError || grammarErrorOnNode(name_15, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_16 = element.name; + if (isReservedWordInStrictMode(name_16)) { + var nameText = ts.declarationNameToString(name_16); + reportError = reportError || grammarErrorOnNode(name_16, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } return reportError; @@ -23498,11 +23520,11 @@ var ts; var inStrictMode = (node.parserContextFlags & 1 /* StrictMode */) !== 0; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - var name_16 = prop.name; + var name_17 = prop.name; if (prop.kind === 176 /* OmittedExpression */ || - name_16.kind === 128 /* ComputedPropertyName */) { + name_17.kind === 128 /* ComputedPropertyName */) { // If the name is not a ComputedPropertyName, the grammar checking will skip it - checkGrammarComputedPropertyName(name_16); + checkGrammarComputedPropertyName(name_17); continue; } // ECMA-262 11.1.5 Object Initialiser @@ -23517,8 +23539,8 @@ var ts; if (prop.kind === 225 /* PropertyAssignment */ || prop.kind === 226 /* ShorthandPropertyAssignment */) { // Grammar checking for computedPropertName and shorthandPropertyAssignment checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); - if (name_16.kind === 7 /* NumericLiteral */) { - checkGrammarNumericLiteral(name_16); + if (name_17.kind === 7 /* NumericLiteral */) { + checkGrammarNumericLiteral(name_17); } currentKind = Property; } @@ -23534,26 +23556,26 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_16.text)) { - seen[name_16.text] = currentKind; + if (!ts.hasProperty(seen, name_17.text)) { + seen[name_17.text] = currentKind; } else { - var existingKind = seen[name_16.text]; + var existingKind = seen[name_17.text]; if (currentKind === Property && existingKind === Property) { if (inStrictMode) { - grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); + grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); } } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_16.text] = currentKind | existingKind; + seen[name_17.text] = currentKind | existingKind; } else { - return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + return grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); } } else { - return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + return grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); } } } @@ -24414,9 +24436,9 @@ var ts; } var count = 0; while (true) { - var name_17 = baseName + "_" + (++count); - if (!ts.hasProperty(currentSourceFile.identifiers, name_17)) { - return name_17; + var name_18 = baseName + "_" + (++count); + if (!ts.hasProperty(currentSourceFile.identifiers, name_18)) { + return name_18; } } } @@ -25625,9 +25647,9 @@ var ts; tempFlags++; // Skip over 'i' and 'n' if (count !== 8 && count !== 13) { - var name_18 = count < 26 ? "_" + String.fromCharCode(97 /* a */ + count) : "_" + (count - 26); - if (isUniqueName(name_18)) { - return name_18; + var name_19 = count < 26 ? "_" + String.fromCharCode(97 /* a */ + count) : "_" + (count - 26); + if (isUniqueName(name_19)) { + return name_19; } } } @@ -25660,9 +25682,9 @@ var ts; } function generateNameForModuleOrEnum(node) { if (node.name.kind === 65 /* Identifier */) { - var name_19 = node.name.text; + var name_20 = node.name.text; // Use module/enum name itself if it is unique, otherwise make a unique variation - assignGeneratedName(node, isUniqueLocalName(name_19, node) ? name_19 : makeUniqueName(name_19)); + assignGeneratedName(node, isUniqueLocalName(name_20, node) ? name_20 : makeUniqueName(name_20)); } } function generateNameForImportOrExportDeclaration(node) { @@ -25881,8 +25903,8 @@ var ts; // Child scopes are always shown with a dot (even if they have no name), // unless it is a computed property. Then it is shown with brackets, // but the brackets are included in the name. - var name_20 = node.name; - if (!name_20 || name_20.kind !== 128 /* ComputedPropertyName */) { + var name_21 = node.name; + if (!name_21 || name_21.kind !== 128 /* ComputedPropertyName */) { scopeName = "." + scopeName; } scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; @@ -25911,10 +25933,10 @@ var ts; node.kind === 205 /* EnumDeclaration */) { // Declaration and has associated name use it if (node.name) { - var name_21 = node.name; + var name_22 = node.name; // For computed property names, the text will include the brackets - scopeName = name_21.kind === 128 /* ComputedPropertyName */ - ? ts.getTextOfNode(name_21) + scopeName = name_22.kind === 128 /* ComputedPropertyName */ + ? ts.getTextOfNode(name_22) : node.name.text; } recordScopeNameStart(scopeName); @@ -26859,6 +26881,11 @@ var ts; return result; } function parenthesizeForAccess(expr) { + // When diagnosing whether the expression needs parentheses, the decision should be based + // on the innermost expression in a chain of nested type assertions. + while (expr.kind === 161 /* TypeAssertionExpression */) { + expr = expr.expression; + } // isLeftHandSideExpression is almost the correct criterion for when it is not necessary // to parenthesize the expression before a dot. The known exceptions are: // @@ -26867,7 +26894,9 @@ var ts; // NumberLiteral // 1.x -> not the same as (1).x // - if (ts.isLeftHandSideExpression(expr) && expr.kind !== 159 /* NewExpression */ && expr.kind !== 7 /* NumericLiteral */) { + if (ts.isLeftHandSideExpression(expr) && + expr.kind !== 159 /* NewExpression */ && + expr.kind !== 7 /* NumericLiteral */) { return expr; } var node = ts.createSynthesizedNode(162 /* ParenthesizedExpression */); @@ -27129,7 +27158,10 @@ var ts; } } function emitParenExpression(node) { - if (!node.parent || node.parent.kind !== 164 /* ArrowFunction */) { + // If the node is synthesized, it means the emitter put the parentheses there, + // not the user. If we didn't want them, the emitter would not have put them + // there. + if (!ts.nodeIsSynthesized(node) && node.parent.kind !== 164 /* ArrowFunction */) { if (node.expression.kind === 161 /* TypeAssertionExpression */) { var operand = node.expression.expression; // Make sure we consider all nested cast expressions, e.g.: @@ -28204,12 +28236,12 @@ var ts; function emitParameter(node) { if (languageVersion < 2 /* ES6 */) { if (ts.isBindingPattern(node.name)) { - var name_22 = createTempVariable(0 /* Auto */); + var name_23 = createTempVariable(0 /* Auto */); if (!tempParameters) { tempParameters = []; } - tempParameters.push(name_22); - emit(name_22); + tempParameters.push(name_23); + emit(name_23); } else { emit(node.name); @@ -29877,8 +29909,8 @@ var ts; // export { x, y } for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { var specifier = _d[_c]; - var name_23 = (specifier.propertyName || specifier.name).text; - (exportSpecifiers[name_23] || (exportSpecifiers[name_23] = [])).push(specifier); + var name_24 = (specifier.propertyName || specifier.name).text; + (exportSpecifiers[name_24] || (exportSpecifiers[name_24] = [])).push(specifier); } } break; @@ -30078,12 +30110,12 @@ var ts; var seen = {}; for (var i = 0; i < hoistedVars.length; ++i) { var local = hoistedVars[i]; - var name_24 = local.kind === 65 /* Identifier */ + var name_25 = local.kind === 65 /* Identifier */ ? local : local.name; - if (name_24) { + if (name_25) { // do not emit duplicate entries (in case of declaration merging) in the list of hoisted variables - var text = ts.unescapeIdentifier(name_24.text); + var text = ts.unescapeIdentifier(name_25.text); if (ts.hasProperty(seen, text)) { continue; } @@ -30162,15 +30194,15 @@ var ts; } if (node.kind === 199 /* VariableDeclaration */ || node.kind === 153 /* BindingElement */) { if (shouldHoistVariable(node, false)) { - var name_25 = node.name; - if (name_25.kind === 65 /* Identifier */) { + var name_26 = node.name; + if (name_26.kind === 65 /* Identifier */) { if (!hoistedVars) { hoistedVars = []; } - hoistedVars.push(name_25); + hoistedVars.push(name_26); } else { - ts.forEachChild(name_25, visit); + ts.forEachChild(name_26, visit); } } return; @@ -31863,7 +31895,7 @@ var ts; var errors = []; return { options: getCompilerOptions(), - fileNames: getFiles(), + fileNames: getFileNames(), errors: errors }; function getCompilerOptions() { @@ -31907,23 +31939,24 @@ var ts; } return options; } - function getFiles() { - var files = []; + function getFileNames() { + var fileNames = []; if (ts.hasProperty(json, "files")) { if (json["files"] instanceof Array) { - var files = ts.map(json["files"], function (s) { return ts.combinePaths(basePath, s); }); + fileNames = ts.map(json["files"], function (s) { return ts.combinePaths(basePath, s); }); } } else { - var sysFiles = host.readDirectory(basePath, ".ts"); + var exclude = json["exclude"] instanceof Array ? ts.map(json["exclude"], ts.normalizeSlashes) : undefined; + var sysFiles = host.readDirectory(basePath, ".ts", exclude); for (var i = 0; i < sysFiles.length; i++) { var name = sysFiles[i]; if (!ts.fileExtensionIs(name, ".d.ts") || !ts.contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) { - files.push(name); + fileNames.push(name); } } } - return files; + return fileNames; } } ts.parseConfigFile = parseConfigFile; @@ -32102,12 +32135,12 @@ var ts; ts.forEach(program.getSourceFiles(), function (sourceFile) { cancellationToken.throwIfCancellationRequested(); var nameToDeclarations = sourceFile.getNamedDeclarations(); - for (var name_26 in nameToDeclarations) { - var declarations = ts.getProperty(nameToDeclarations, name_26); + for (var name_27 in nameToDeclarations) { + var declarations = ts.getProperty(nameToDeclarations, name_27); if (declarations) { // First do a quick check to see if the name of the declaration matches the // last portion of the (possibly) dotted name they're searching for. - var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_26); + var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_27); if (!matches) { continue; } @@ -32120,14 +32153,14 @@ var ts; if (!containers) { return undefined; } - matches = patternMatcher.getMatches(containers, name_26); + matches = patternMatcher.getMatches(containers, name_27); if (!matches) { continue; } } var fileName = sourceFile.fileName; var matchKind = bestMatchKind(matches); - rawItems.push({ name: name_26, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); + rawItems.push({ name: name_27, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); } } } @@ -32510,9 +32543,9 @@ var ts; case 199 /* VariableDeclaration */: case 153 /* BindingElement */: var variableDeclarationNode; - var name_27; + var name_28; if (node.kind === 153 /* BindingElement */) { - name_27 = node.name; + name_28 = node.name; variableDeclarationNode = node; // binding elements are added only for variable declarations // bubble up to the containing variable declaration @@ -32524,16 +32557,16 @@ var ts; else { ts.Debug.assert(!ts.isBindingPattern(node.name)); variableDeclarationNode = node; - name_27 = node.name; + name_28 = node.name; } if (ts.isConst(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.constElement); + return createItem(node, getTextOfNode(name_28), ts.ScriptElementKind.constElement); } else if (ts.isLet(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.letElement); + return createItem(node, getTextOfNode(name_28), ts.ScriptElementKind.letElement); } else { - return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.variableElement); + return createItem(node, getTextOfNode(name_28), ts.ScriptElementKind.variableElement); } case 136 /* Constructor */: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); @@ -35122,9 +35155,9 @@ var ts; } Rules.prototype.getRuleName = function (rule) { var o = this; - for (var name_28 in o) { - if (o[name_28] === rule) { - return name_28; + for (var name_29 in o) { + if (o[name_29] === rule) { + return name_29; } } throw new Error("Unknown rule"); @@ -39458,10 +39491,10 @@ var ts; for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { var sourceFile = _a[_i]; var nameTable = getNameTable(sourceFile); - for (var name_29 in nameTable) { - if (!allNames[name_29]) { - allNames[name_29] = name_29; - var displayName = getCompletionEntryDisplayName(name_29, target, true); + for (var name_30 in nameTable) { + if (!allNames[name_30]) { + allNames[name_30] = name_30; + var displayName = getCompletionEntryDisplayName(name_30, target, true); if (displayName) { var entry = { name: displayName, @@ -41343,19 +41376,19 @@ var ts; if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; var contextualType = typeChecker.getContextualType(objectLiteral); - var name_30 = node.text; + var name_31 = node.text; if (contextualType) { if (contextualType.flags & 16384 /* Union */) { // This is a union type, first see if the property we are looking for is a union property (i.e. exists in all types) // if not, search the constituent types for the property - var unionProperty = contextualType.getProperty(name_30); + var unionProperty = contextualType.getProperty(name_31); if (unionProperty) { return [unionProperty]; } else { var result_4 = []; ts.forEach(contextualType.types, function (t) { - var symbol = t.getProperty(name_30); + var symbol = t.getProperty(name_31); if (symbol) { result_4.push(symbol); } @@ -41364,7 +41397,7 @@ var ts; } } else { - var symbol_1 = contextualType.getProperty(name_30); + var symbol_1 = contextualType.getProperty(name_31); if (symbol_1) { return [symbol_1]; } From b76cc375603a9d93429cfa58148affefdb4c40cd Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 4 Jun 2015 10:52:43 -0700 Subject: [PATCH 25/26] added missing semicolon after calling exporter function --- src/compiler/emitter.ts | 4 ++-- tests/baselines/reference/systemModule7.js | 2 +- .../baselines/reference/systemModuleDeclarationMerging.js | 8 ++++---- .../reference/systemModuleNonTopLevelModuleMembers.js | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index b94c452ed8a..4887e297eb0 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4503,7 +4503,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { emitDeclarationName(node); write(`", `); emitDeclarationName(node); - write(")"); + write(");"); } emitExportMemberAssignments(node.name); } @@ -4624,7 +4624,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { emitDeclarationName(node); write(`", `); emitDeclarationName(node); - write(")"); + write(");"); } emitExportMemberAssignments(node.name); } diff --git a/tests/baselines/reference/systemModule7.js b/tests/baselines/reference/systemModule7.js index 85dd42da87d..0c396ddbe55 100644 --- a/tests/baselines/reference/systemModule7.js +++ b/tests/baselines/reference/systemModule7.js @@ -20,7 +20,7 @@ System.register([], function(exports_1) { (function (M) { var x = 1; })(M = M || (M = {})); - exports_1("M", M) + exports_1("M", M); } } }); diff --git a/tests/baselines/reference/systemModuleDeclarationMerging.js b/tests/baselines/reference/systemModuleDeclarationMerging.js index b745ed04891..06577c401a0 100644 --- a/tests/baselines/reference/systemModuleDeclarationMerging.js +++ b/tests/baselines/reference/systemModuleDeclarationMerging.js @@ -20,7 +20,7 @@ System.register([], function(exports_1) { (function (F) { var x; })(F = F || (F = {})); - exports_1("F", F) + exports_1("F", F); C = (function () { function C() { } @@ -30,14 +30,14 @@ System.register([], function(exports_1) { (function (C) { var x; })(C = C || (C = {})); - exports_1("C", C) + exports_1("C", C); (function (E) { })(E || (E = {})); - exports_1("E", E) + exports_1("E", E); (function (E) { var x; })(E = E || (E = {})); - exports_1("E", E) + exports_1("E", E); } } }); diff --git a/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.js b/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.js index 87e96259bf1..39a957ed698 100644 --- a/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.js +++ b/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.js @@ -29,11 +29,11 @@ System.register([], function(exports_1) { (function (TopLevelModule) { var v; })(TopLevelModule = TopLevelModule || (TopLevelModule = {})); - exports_1("TopLevelModule", TopLevelModule) + exports_1("TopLevelModule", TopLevelModule); (function (TopLevelEnum) { TopLevelEnum[TopLevelEnum["E"] = 0] = "E"; })(TopLevelEnum || (TopLevelEnum = {})); - exports_1("TopLevelEnum", TopLevelEnum) + exports_1("TopLevelEnum", TopLevelEnum); (function (TopLevelModule2) { var NonTopLevelClass = (function () { function NonTopLevelClass() { @@ -52,7 +52,7 @@ System.register([], function(exports_1) { })(TopLevelModule2.NonTopLevelEnum || (TopLevelModule2.NonTopLevelEnum = {})); var NonTopLevelEnum = TopLevelModule2.NonTopLevelEnum; })(TopLevelModule2 = TopLevelModule2 || (TopLevelModule2 = {})); - exports_1("TopLevelModule2", TopLevelModule2) + exports_1("TopLevelModule2", TopLevelModule2); } } }); From 495d7266255514c00b94de4bbd756176a3ddb91b Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 4 Jun 2015 11:18:05 -0700 Subject: [PATCH 26/26] rename 'FileMap.delete' to 'FileMap.remove' --- src/compiler/core.ts | 4 ++-- src/compiler/types.ts | 2 +- src/services/services.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index ed9647970c0..dde1e3d6b57 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -21,7 +21,7 @@ module ts { get, set, contains, - delete: deleteItem, + remove, forEachValue: forEachValueInMap } @@ -37,7 +37,7 @@ module ts { return hasProperty(files, normalizeKey(fileName)); } - function deleteItem (fileName: string) { + function remove (fileName: string) { let key = normalizeKey(fileName); delete files[key]; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d4e1378772b..d03df1c188f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -7,7 +7,7 @@ module ts { get(fileName: string): T; set(fileName: string, value: T): void; contains(fileName: string): boolean; - delete(fileName: string): void; + remove(fileName: string): void; forEachValue(f: (v: T) => void): void; } diff --git a/src/services/services.ts b/src/services/services.ts index f579dcca4a5..f03dc10007c 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1990,7 +1990,7 @@ module ts { Debug.assert(entry.languageServiceRefCount >= 0); if (entry.languageServiceRefCount === 0) { - bucket.delete(fileName); + bucket.remove(fileName); } }