From 70d2938f4fe210616c7320b2afadd73da55943f7 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 16 May 2015 11:38:28 -0700 Subject: [PATCH 01/73] Support "exclude" property in tsconfig.json --- src/compiler/commandLineParser.ts | 15 +++++----- src/compiler/sys.ts | 46 +++++++++++++++++++++---------- src/compiler/types.ts | 2 +- 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 7a589fe61cb..1de9188aed7 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -343,7 +343,7 @@ module ts { return { options: getCompilerOptions(), - fileNames: getFiles(), + fileNames: getFileNames(), errors }; @@ -389,23 +389,24 @@ module ts { return options; } - function getFiles(): string[] { - var files: string[] = []; + function getFileNames(): string[] { + var fileNames: string[] = []; if (hasProperty(json, "files")) { if (json["files"] instanceof Array) { - var files = map(json["files"], s => combinePaths(basePath, s)); + fileNames = map(json["files"], s => combinePaths(basePath, s)); } } else { - var sysFiles = host.readDirectory(basePath, ".ts"); + var exclude = json["exclude"] instanceof Array ? map(json["exclude"], normalizeSlashes) : undefined; + var sysFiles = host.readDirectory(basePath, ".ts", exclude); for (var i = 0; i < sysFiles.length; i++) { var name = sysFiles[i]; if (!fileExtensionIs(name, ".d.ts") || !contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) { - files.push(name); + fileNames.push(name); } } } - return files; + return fileNames; } } } diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index f9daf52c5f2..8f246540c61 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -15,7 +15,7 @@ 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; } @@ -109,7 +109,11 @@ module ts { } } - function getNames(collection: any): string[] { + function getCanonicalPath(path: string): string { + return path.toLowerCase(); + } + + function getNames(collection: any): string[]{ var result: string[] = []; for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) { result.push(e.item().Name); @@ -117,21 +121,26 @@ module ts { return result.sort(); } - function readDirectory(path: string, extension?: string): string[] { + function readDirectory(path: string, extension?: string, exclude?: string[]): string[] { var result: string[] = []; + exclude = map(exclude, s => getCanonicalPath(combinePaths(path, s))); visitDirectory(path); return result; function visitDirectory(path: string) { var folder = fso.GetFolder(path || "."); var files = getNames(folder.files); - for (let name of files) { - if (!extension || fileExtensionIs(name, extension)) { - result.push(combinePaths(path, name)); + for (let current of files) { + let name = combinePaths(path, current); + if ((!extension || fileExtensionIs(name, extension)) && !contains(exclude, getCanonicalPath(name))) { + result.push(name); } } var subfolders = getNames(folder.subfolders); for (let current of subfolders) { - visitDirectory(combinePaths(path, current)); + let name = combinePaths(path, current); + if (!contains(exclude, getCanonicalPath(name))) { + visitDirectory(name); + } } } } @@ -222,8 +231,13 @@ module ts { _fs.writeFileSync(fileName, data, "utf8"); } - function readDirectory(path: string, extension?: string): string[] { + function getCanonicalPath(path: string): string { + return useCaseSensitiveFileNames ? path.toLowerCase() : path; + } + + function readDirectory(path: string, extension?: string, exclude?: string[]): string[] { var result: string[] = []; + exclude = map(exclude, s => getCanonicalPath(combinePaths(path, s))); visitDirectory(path); return result; function visitDirectory(path: string) { @@ -231,14 +245,16 @@ module ts { var directories: string[] = []; for (let current of files) { var name = combinePaths(path, current); - var stat = _fs.lstatSync(name); - if (stat.isFile()) { - if (!extension || fileExtensionIs(name, extension)) { - result.push(name); + if (!contains(exclude, getCanonicalPath(name))) { + var stat = _fs.lstatSync(name); + if (stat.isFile()) { + if (!extension || fileExtensionIs(name, extension)) { + result.push(name); + } + } + else if (stat.isDirectory()) { + directories.push(name); } - } - else if (stat.isDirectory()) { - directories.push(name); } } for (let current of directories) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 86e680ca8b0..831cc26eedf 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1035,7 +1035,7 @@ module ts { } export interface ParseConfigHost { - readDirectory(rootDir: string, extension: string): string[]; + readDirectory(rootDir: string, extension: string, exclude: string[]): string[]; } export interface WriteFileCallback { From e7eef830e13509baa479eabe0e75aaa4992927c1 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 26 May 2015 20:18:13 -0700 Subject: [PATCH 02/73] 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 03/73] 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 04/73] 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 05/73] 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 06/73] 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 07/73] 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 08/73] 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 09/73] 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 10/73] 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 413176b2a1a54babdd94d8baa51d996d62cee1a7 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 30 May 2015 16:37:03 -0700 Subject: [PATCH 11/73] Use symbols instead of types in infinite instantiation detection --- src/compiler/checker.ts | 123 +++++++++++++++++++++------------------- src/compiler/types.ts | 11 ++-- 2 files changed, 70 insertions(+), 64 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 76ec977491e..7c640598e69 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1472,7 +1472,7 @@ module ts { return appendParentTypeArgumentsAndSymbolName(symbol); } - function buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, globalFlags?: TypeFormatFlags, typeStack?: Type[]) { + function buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, globalFlags?: TypeFormatFlags, symbolStack?: Symbol[]) { let globalFlagsToPass = globalFlags & TypeFormatFlags.WriteOwnNameForAnyLike; return writeType(type, globalFlags); @@ -1557,49 +1557,54 @@ module ts { } function writeAnonymousType(type: ObjectType, flags: TypeFormatFlags) { - // Always use 'typeof T' for type of class, enum, and module objects - if (type.symbol && type.symbol.flags & (SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.ValueModule)) { - writeTypeofSymbol(type, flags); - } - // Use 'typeof T' for types of functions and methods that circularly reference themselves - else if (shouldWriteTypeOfFunctionSymbol()) { - writeTypeofSymbol(type, flags); - } - else if (typeStack && contains(typeStack, type)) { - // If type is an anonymous type literal in a type alias declaration, use type alias name - let typeAlias = getTypeAliasForTypeLiteral(type); - if (typeAlias) { - // The specified symbol flags need to be reinterpreted as type flags - buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, flags); + let symbol = type.symbol; + if (symbol) { + // Always use 'typeof T' for type of class, enum, and module objects + if (symbol.flags & (SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.ValueModule)) { + writeTypeofSymbol(type, flags); + } + else if (shouldWriteTypeOfFunctionSymbol()) { + writeTypeofSymbol(type, flags); + } + else if (contains(symbolStack, symbol)) { + // If type is an anonymous type literal in a type alias declaration, use type alias name + let typeAlias = getTypeAliasForTypeLiteral(type); + if (typeAlias) { + // The specified symbol flags need to be reinterpreted as type flags + buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, flags); + } + else { + // Recursive usage, use any + writeKeyword(writer, SyntaxKind.AnyKeyword); + } } else { - // Recursive usage, use any - writeKeyword(writer, SyntaxKind.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) { - let isStaticMethodSymbol = !!(type.symbol.flags & SymbolFlags.Method && // typeof static method - ts.forEach(type.symbol.declarations, declaration => declaration.flags & NodeFlags.Static)); - let isNonLocalFunctionSymbol = !!(type.symbol.flags & SymbolFlags.Function) && - (type.symbol.parent || // is exported function symbol - ts.forEach(type.symbol.declarations, declaration => - declaration.parent.kind === SyntaxKind.SourceFile || declaration.parent.kind === SyntaxKind.ModuleBlock)); - - if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { - // typeof is allowed only for static/non local functions - return !!(flags & TypeFormatFlags.UseTypeOfFunction) || // use typeof if format flags specify it - (typeStack && contains(typeStack, type)); // it is type of the symbol uses itself recursively - } + let isStaticMethodSymbol = !!(symbol.flags & SymbolFlags.Method && // typeof static method + forEach(symbol.declarations, declaration => declaration.flags & NodeFlags.Static)); + let isNonLocalFunctionSymbol = !!(symbol.flags & SymbolFlags.Function) && + (symbol.parent || // is exported function symbol + forEach(symbol.declarations, declaration => + declaration.parent.kind === SyntaxKind.SourceFile || declaration.parent.kind === SyntaxKind.ModuleBlock)); + if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { + // typeof is allowed only for static/non local functions + return !!(flags & TypeFormatFlags.UseTypeOfFunction) || // use typeof if format flags specify it + (contains(symbolStack, symbol)); // it is type of the symbol uses itself recursively } } } @@ -1634,7 +1639,7 @@ module ts { if (flags & TypeFormatFlags.InElementType) { writePunctuation(writer, SyntaxKind.OpenParenToken); } - buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | TypeFormatFlags.WriteArrowStyleSignature, typeStack); + buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | TypeFormatFlags.WriteArrowStyleSignature, symbolStack); if (flags & TypeFormatFlags.InElementType) { writePunctuation(writer, SyntaxKind.CloseParenToken); } @@ -1646,7 +1651,7 @@ module ts { } writeKeyword(writer, SyntaxKind.NewKeyword); writeSpace(writer); - buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | TypeFormatFlags.WriteArrowStyleSignature, typeStack); + buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | TypeFormatFlags.WriteArrowStyleSignature, symbolStack); if (flags & TypeFormatFlags.InElementType) { writePunctuation(writer, SyntaxKind.CloseParenToken); } @@ -1658,7 +1663,7 @@ module ts { writer.writeLine(); writer.increaseIndent(); for (let signature of resolved.callSignatures) { - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, SyntaxKind.SemicolonToken); writer.writeLine(); } @@ -1666,7 +1671,7 @@ module ts { writeKeyword(writer, SyntaxKind.NewKeyword); writeSpace(writer); - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, SyntaxKind.SemicolonToken); writer.writeLine(); } @@ -1707,7 +1712,7 @@ module ts { if (p.flags & SymbolFlags.Optional) { writePunctuation(writer, SyntaxKind.QuestionToken); } - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, SyntaxKind.SemicolonToken); writer.writeLine(); } @@ -1736,18 +1741,18 @@ module ts { } } - function buildTypeParameterDisplay(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + function buildTypeParameterDisplay(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { appendSymbolNameOnly(tp.symbol, writer); let constraint = getConstraintOfTypeParameter(tp); if (constraint) { writeSpace(writer); writeKeyword(writer, SyntaxKind.ExtendsKeyword); writeSpace(writer); - buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, symbolStack); } } - function buildParameterDisplay(p: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + function buildParameterDisplay(p: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { if (hasDotDotDotToken(p.valueDeclaration)) { writePunctuation(writer, SyntaxKind.DotDotDotToken); } @@ -1758,10 +1763,10 @@ module ts { writePunctuation(writer, SyntaxKind.ColonToken); writeSpace(writer); - buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, symbolStack); } - function buildDisplayForTypeParametersAndDelimiters(typeParameters: TypeParameter[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + function buildDisplayForTypeParametersAndDelimiters(typeParameters: TypeParameter[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { if (typeParameters && typeParameters.length) { writePunctuation(writer, SyntaxKind.LessThanToken); for (let i = 0; i < typeParameters.length; i++) { @@ -1769,13 +1774,13 @@ module ts { writePunctuation(writer, SyntaxKind.CommaToken); writeSpace(writer); } - buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, typeStack); + buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, symbolStack); } writePunctuation(writer, SyntaxKind.GreaterThanToken); } } - function buildDisplayForTypeArgumentsAndDelimiters(typeParameters: TypeParameter[], mapper: TypeMapper, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + function buildDisplayForTypeArgumentsAndDelimiters(typeParameters: TypeParameter[], mapper: TypeMapper, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { if (typeParameters && typeParameters.length) { writePunctuation(writer, SyntaxKind.LessThanToken); for (let i = 0; i < typeParameters.length; i++) { @@ -1789,19 +1794,19 @@ module ts { } } - function buildDisplayForParametersAndDelimiters(parameters: Symbol[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + function buildDisplayForParametersAndDelimiters(parameters: Symbol[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { writePunctuation(writer, SyntaxKind.OpenParenToken); for (let i = 0; i < parameters.length; i++) { if (i > 0) { writePunctuation(writer, SyntaxKind.CommaToken); writeSpace(writer); } - buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, typeStack); + buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, symbolStack); } writePunctuation(writer, SyntaxKind.CloseParenToken); } - function buildReturnTypeDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + function buildReturnTypeDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { if (flags & TypeFormatFlags.WriteArrowStyleSignature) { writeSpace(writer); writePunctuation(writer, SyntaxKind.EqualsGreaterThanToken); @@ -1810,21 +1815,21 @@ module ts { writePunctuation(writer, SyntaxKind.ColonToken); } writeSpace(writer); - buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, symbolStack); } - function buildSignatureDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + function buildSignatureDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { if (signature.target && (flags & TypeFormatFlags.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 = { @@ -3889,7 +3894,7 @@ module ts { mapper.mappings = {}; } // Instantiate the given type using the given mapper and cache the result - let result = createObjectType(TypeFlags.Anonymous, type.symbol); + let result = createObjectType(TypeFlags.Anonymous | TypeFlags.Instantiated, type.symbol); result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); result.members = createSymbolTable(result.properties); result.callSignatures = instantiateList(getSignaturesOfType(type, SignatureKind.Call), mapper, instantiateSignature); @@ -4313,12 +4318,12 @@ module 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: ObjectType, stack: ObjectType[]): boolean { - if (type.flags & TypeFlags.Reference && depth >= 10) { - let target = (type).target; + if (type.flags & (TypeFlags.Reference | TypeFlags.Instantiated) && depth >= 10) { + let symbol = type.symbol; let count = 0; for (let i = 0; i < depth; i++) { let t = stack[i]; - if (t.flags & TypeFlags.Reference && (t).target === target) { + if (t.flags & (TypeFlags.Reference | TypeFlags.Instantiated) && t.symbol === symbol) { count++; if (count >= 10) return true; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 3d52d096b03..a6ab19d4296 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1582,14 +1582,15 @@ module ts { Tuple = 0x00002000, // Tuple Union = 0x00004000, // Union Anonymous = 0x00008000, // Anonymous + Instantiated = 0x00010000, // Instantiated anonymous type /* @internal */ - FromSignature = 0x00010000, // Created for signature assignment check - ObjectLiteral = 0x00020000, // Originates in an object literal + FromSignature = 0x00020000, // Created for signature assignment check + ObjectLiteral = 0x00040000, // Originates in an object literal /* @internal */ - ContainsUndefinedOrNull = 0x00040000, // Type is or contains Undefined or Null type + ContainsUndefinedOrNull = 0x00080000, // Type is or contains Undefined or Null type /* @internal */ - ContainsObjectLiteral = 0x00080000, // Type is or contains object literal type - ESSymbol = 0x00100000, // Type of symbol primitive introduced in ES6 + ContainsObjectLiteral = 0x00100000, // Type is or contains object literal type + ESSymbol = 0x00200000, // Type of symbol primitive introduced in ES6 /* @internal */ Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null, From 46e0ba82cec8e97e1e0be137e94d1d2fcef31381 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 30 May 2015 17:25:44 -0700 Subject: [PATCH 12/73] Remove old (and insufficient) instantiation caching --- src/compiler/checker.ts | 14 +------------- src/compiler/types.ts | 1 - 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7c640598e69..c180d8425f2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3882,18 +3882,7 @@ module ts { } function instantiateAnonymousType(type: ObjectType, mapper: TypeMapper): ObjectType { - // 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) { - let cached = mapper.mappings[type.id]; - if (cached) { - return cached; - } - } - else { - mapper.mappings = {}; - } - // Instantiate the given type using the given mapper and cache the result + // Mark the anonymous type as instantiated such that our infinite instantiation detection logic can recognize it let result = createObjectType(TypeFlags.Anonymous | TypeFlags.Instantiated, type.symbol); result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); result.members = createSymbolTable(result.properties); @@ -3903,7 +3892,6 @@ module ts { let numberIndexType = getIndexTypeOfType(type, IndexKind.Number); if (stringIndexType) result.stringIndexType = instantiateType(stringIndexType, mapper); if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper); - mapper.mappings[type.id] = result; return result; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index a6ab19d4296..2d1175df080 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1730,7 +1730,6 @@ module ts { /* @internal */ export interface TypeMapper { (t: TypeParameter): Type; - mappings?: Map; // Type mapping cache } /* @internal */ From e336e3ad0aa6e983d380dcd9bbd107b157a5bfba Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 30 May 2015 18:09:13 -0700 Subject: [PATCH 13/73] Adding regression test --- .../cyclicGenericTypeInstantiation.js | 37 ++++++++++++ .../cyclicGenericTypeInstantiation.symbols | 55 +++++++++++++++++ .../cyclicGenericTypeInstantiation.types | 60 +++++++++++++++++++ .../cyclicGenericTypeInstantiation.ts | 20 +++++++ 4 files changed, 172 insertions(+) create mode 100644 tests/baselines/reference/cyclicGenericTypeInstantiation.js create mode 100644 tests/baselines/reference/cyclicGenericTypeInstantiation.symbols create mode 100644 tests/baselines/reference/cyclicGenericTypeInstantiation.types create mode 100644 tests/cases/compiler/cyclicGenericTypeInstantiation.ts diff --git a/tests/baselines/reference/cyclicGenericTypeInstantiation.js b/tests/baselines/reference/cyclicGenericTypeInstantiation.js new file mode 100644 index 00000000000..10f52e10d89 --- /dev/null +++ b/tests/baselines/reference/cyclicGenericTypeInstantiation.js @@ -0,0 +1,37 @@ +//// [cyclicGenericTypeInstantiation.ts] +function foo() { + var z = foo(); + var y: { + y2: typeof z + }; + return y; +} + + +function bar() { + var z = bar(); + var y: { + y2: typeof z; + } + return y; +} + +var a = foo(); +var b = bar(); +a = b; + + +//// [cyclicGenericTypeInstantiation.js] +function foo() { + var z = foo(); + var y; + return y; +} +function bar() { + var z = bar(); + var y; + return y; +} +var a = foo(); +var b = bar(); +a = b; diff --git a/tests/baselines/reference/cyclicGenericTypeInstantiation.symbols b/tests/baselines/reference/cyclicGenericTypeInstantiation.symbols new file mode 100644 index 00000000000..a6566b86839 --- /dev/null +++ b/tests/baselines/reference/cyclicGenericTypeInstantiation.symbols @@ -0,0 +1,55 @@ +=== tests/cases/compiler/cyclicGenericTypeInstantiation.ts === +function foo() { +>foo : Symbol(foo, Decl(cyclicGenericTypeInstantiation.ts, 0, 0)) +>T : Symbol(T, Decl(cyclicGenericTypeInstantiation.ts, 0, 13)) + + var z = foo(); +>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 1, 7)) +>foo : Symbol(foo, Decl(cyclicGenericTypeInstantiation.ts, 0, 0)) +>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 2, 7)) + + var y: { +>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 2, 7)) + + y2: typeof z +>y2 : Symbol(y2, Decl(cyclicGenericTypeInstantiation.ts, 2, 12)) +>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 1, 7)) + + }; + return y; +>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 2, 7)) +} + + +function bar() { +>bar : Symbol(bar, Decl(cyclicGenericTypeInstantiation.ts, 6, 1)) +>T : Symbol(T, Decl(cyclicGenericTypeInstantiation.ts, 9, 13)) + + var z = bar(); +>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 10, 7)) +>bar : Symbol(bar, Decl(cyclicGenericTypeInstantiation.ts, 6, 1)) +>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 11, 7)) + + var y: { +>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 11, 7)) + + y2: typeof z; +>y2 : Symbol(y2, Decl(cyclicGenericTypeInstantiation.ts, 11, 12)) +>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 10, 7)) + } + return y; +>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 11, 7)) +} + +var a = foo(); +>a : Symbol(a, Decl(cyclicGenericTypeInstantiation.ts, 17, 3)) +>foo : Symbol(foo, Decl(cyclicGenericTypeInstantiation.ts, 0, 0)) + +var b = bar(); +>b : Symbol(b, Decl(cyclicGenericTypeInstantiation.ts, 18, 3)) +>bar : Symbol(bar, Decl(cyclicGenericTypeInstantiation.ts, 6, 1)) + +a = b; +>a : Symbol(a, Decl(cyclicGenericTypeInstantiation.ts, 17, 3)) +>b : Symbol(b, Decl(cyclicGenericTypeInstantiation.ts, 18, 3)) + diff --git a/tests/baselines/reference/cyclicGenericTypeInstantiation.types b/tests/baselines/reference/cyclicGenericTypeInstantiation.types new file mode 100644 index 00000000000..69b0955b22f --- /dev/null +++ b/tests/baselines/reference/cyclicGenericTypeInstantiation.types @@ -0,0 +1,60 @@ +=== tests/cases/compiler/cyclicGenericTypeInstantiation.ts === +function foo() { +>foo : () => { y2: any; } +>T : T + + var z = foo(); +>z : { y2: any; } +>foo() : { y2: any; } +>foo : () => { y2: any; } +>y : { y2: any; } + + var y: { +>y : { y2: any; } + + y2: typeof z +>y2 : { y2: any; } +>z : { y2: any; } + + }; + return y; +>y : { y2: any; } +} + + +function bar() { +>bar : () => { y2: any; } +>T : T + + var z = bar(); +>z : { y2: any; } +>bar() : { y2: any; } +>bar : () => { y2: any; } +>y : { y2: any; } + + var y: { +>y : { y2: any; } + + y2: typeof z; +>y2 : { y2: any; } +>z : { y2: any; } + } + return y; +>y : { y2: any; } +} + +var a = foo(); +>a : { y2: any; } +>foo() : { y2: any; } +>foo : () => { y2: any; } + +var b = bar(); +>b : { y2: any; } +>bar() : { y2: any; } +>bar : () => { y2: any; } + +a = b; +>a = b : { y2: any; } +>a : { y2: any; } +>b : { y2: any; } + diff --git a/tests/cases/compiler/cyclicGenericTypeInstantiation.ts b/tests/cases/compiler/cyclicGenericTypeInstantiation.ts new file mode 100644 index 00000000000..070cc44a63a --- /dev/null +++ b/tests/cases/compiler/cyclicGenericTypeInstantiation.ts @@ -0,0 +1,20 @@ +function foo() { + var z = foo(); + var y: { + y2: typeof z + }; + return y; +} + + +function bar() { + var z = bar(); + var y: { + y2: typeof z; + } + return y; +} + +var a = foo(); +var b = bar(); +a = b; From e93b7a75ce38177c57ee0df1684fdc94d01f418e Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 2 Jun 2015 14:59:46 -0700 Subject: [PATCH 14/73] Added tests. --- .../asiPreventsParsingAsAmbientExternalModule01.ts | 8 ++++++++ .../asiPreventsParsingAsAmbientExternalModule02.ts | 10 ++++++++++ .../asiPreventsParsingAsNamespace01.ts | 7 +++++++ .../asiPreventsParsingAsNamespace02.ts | 7 +++++++ .../asiPreventsParsingAsNamespace03.ts | 9 +++++++++ .../typeAliases/asiPreventsParsingAsTypeAlias01.ts | 7 +++++++ .../typeAliases/asiPreventsParsingAsTypeAlias02.ts | 9 +++++++++ 7 files changed, 57 insertions(+) create mode 100644 tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule01.ts create mode 100644 tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule02.ts create mode 100644 tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace01.ts create mode 100644 tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace02.ts create mode 100644 tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace03.ts create mode 100644 tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias01.ts create mode 100644 tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias02.ts diff --git a/tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule01.ts b/tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule01.ts new file mode 100644 index 00000000000..73dcd821f65 --- /dev/null +++ b/tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule01.ts @@ -0,0 +1,8 @@ + +var declare: number; +var module: string; + +declare // this is the identifier 'declare' +module // this is the identifier 'module' +"my external module" // this is just a string +{ } // this is a block body \ No newline at end of file diff --git a/tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule02.ts b/tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule02.ts new file mode 100644 index 00000000000..ba0b2d48d62 --- /dev/null +++ b/tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule02.ts @@ -0,0 +1,10 @@ + +var declare: number; +var module: string; + +module container { + declare // this is the identifier 'declare' + module // this is the identifier 'module' + "my external module" // this is just a string + { } // this is a block body +} \ No newline at end of file diff --git a/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace01.ts b/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace01.ts new file mode 100644 index 00000000000..f3bced2be48 --- /dev/null +++ b/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace01.ts @@ -0,0 +1,7 @@ + +var namespace: number; +var n: string; + +namespace // this is the identifier 'namespace' +n // this is the identifier 'n' +{ } // this is a block body \ No newline at end of file diff --git a/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace02.ts b/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace02.ts new file mode 100644 index 00000000000..63004ef3b62 --- /dev/null +++ b/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace02.ts @@ -0,0 +1,7 @@ + +var module: number; +var m: string; + +module // this is the identifier 'namespace' +m // this is the identifier 'm' +{ } // this is a block body \ No newline at end of file diff --git a/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace03.ts b/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace03.ts new file mode 100644 index 00000000000..de560b7fff4 --- /dev/null +++ b/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace03.ts @@ -0,0 +1,9 @@ + +var namespace: number; +var n: string; + +namespace container { + namespace // this is the identifier 'namespace' + n // this is the identifier 'n' + { } // this is a block body +} \ No newline at end of file diff --git a/tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias01.ts b/tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias01.ts new file mode 100644 index 00000000000..8c4bc6e5420 --- /dev/null +++ b/tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias01.ts @@ -0,0 +1,7 @@ + +var type; +var string; +var Foo; + +type +Foo = string; \ No newline at end of file diff --git a/tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias02.ts b/tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias02.ts new file mode 100644 index 00000000000..9357dbbfe09 --- /dev/null +++ b/tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias02.ts @@ -0,0 +1,9 @@ + +var type; +var string; +var Foo; + +namespace container { + type + Foo = string; +} \ No newline at end of file From 448e8bf0c7d5adae72cfb0e12bfdae1e2a01bc4d Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 2 Jun 2015 15:47:23 -0700 Subject: [PATCH 15/73] Added baselines. --- ...PreventsParsingAsAmbientExternalModule01.js | 13 +++++++++++++ ...ntsParsingAsAmbientExternalModule01.symbols | 12 ++++++++++++ ...ventsParsingAsAmbientExternalModule01.types | 12 ++++++++++++ ...ParsingAsAmbientExternalModule02.errors.txt | 16 ++++++++++++++++ ...PreventsParsingAsAmbientExternalModule02.js | 15 +++++++++++++++ .../asiPreventsParsingAsNamespace01.js | 12 ++++++++++++ .../asiPreventsParsingAsNamespace01.symbols | 13 +++++++++++++ .../asiPreventsParsingAsNamespace01.types | 13 +++++++++++++ .../asiPreventsParsingAsNamespace02.js | 12 ++++++++++++ .../asiPreventsParsingAsNamespace02.symbols | 13 +++++++++++++ .../asiPreventsParsingAsNamespace02.types | 13 +++++++++++++ .../asiPreventsParsingAsNamespace03.js | 14 ++++++++++++++ .../asiPreventsParsingAsNamespace03.symbols | 17 +++++++++++++++++ .../asiPreventsParsingAsNamespace03.types | 17 +++++++++++++++++ .../asiPreventsParsingAsTypeAlias01.js | 13 +++++++++++++ .../asiPreventsParsingAsTypeAlias01.symbols | 15 +++++++++++++++ .../asiPreventsParsingAsTypeAlias01.types | 15 +++++++++++++++ .../asiPreventsParsingAsTypeAlias02.js | 15 +++++++++++++++ .../asiPreventsParsingAsTypeAlias02.symbols | 18 ++++++++++++++++++ .../asiPreventsParsingAsTypeAlias02.types | 18 ++++++++++++++++++ 20 files changed, 286 insertions(+) create mode 100644 tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.js create mode 100644 tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.symbols create mode 100644 tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.types create mode 100644 tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.errors.txt create mode 100644 tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.js create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace01.js create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace01.symbols create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace01.types create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace02.js create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace02.symbols create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace02.types create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace03.js create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace03.symbols create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace03.types create mode 100644 tests/baselines/reference/asiPreventsParsingAsTypeAlias01.js create mode 100644 tests/baselines/reference/asiPreventsParsingAsTypeAlias01.symbols create mode 100644 tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types create mode 100644 tests/baselines/reference/asiPreventsParsingAsTypeAlias02.js create mode 100644 tests/baselines/reference/asiPreventsParsingAsTypeAlias02.symbols create mode 100644 tests/baselines/reference/asiPreventsParsingAsTypeAlias02.types diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.js b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.js new file mode 100644 index 00000000000..efd82f27d1f --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.js @@ -0,0 +1,13 @@ +//// [asiPreventsParsingAsAmbientExternalModule01.ts] + +var declare: number; +var module: string; + +declare // this is the identifier 'declare' +module // this is the identifier 'module' +"my external module" // this is just a string +{ } // this is a block body + +//// [asiPreventsParsingAsAmbientExternalModule01.js] +var declare; +var module; diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.symbols b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.symbols new file mode 100644 index 00000000000..87eb8daf7e2 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule01.ts === + +var declare: number; +>declare : Symbol(declare, Decl(asiPreventsParsingAsAmbientExternalModule01.ts, 1, 3)) + +var module: string; +>module : Symbol(module, Decl(asiPreventsParsingAsAmbientExternalModule01.ts, 2, 3)) + +declare // this is the identifier 'declare' +module // this is the identifier 'module' +"my external module" // this is just a string +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.types b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.types new file mode 100644 index 00000000000..94a2cc8d6a1 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule01.ts === + +var declare: number; +>declare : number + +var module: string; +>module : string + +declare // this is the identifier 'declare' +module // this is the identifier 'module' +"my external module" // this is just a string +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.errors.txt b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.errors.txt new file mode 100644 index 00000000000..3064b137a19 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule02.ts(8,5): error TS2435: Ambient modules cannot be nested in other modules. + + +==== tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule02.ts (1 errors) ==== + + var declare: number; + var module: string; + + module container { + declare // this is the identifier 'declare' + module // this is the identifier 'module' + "my external module" // this is just a string + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2435: Ambient modules cannot be nested in other modules. + { } // this is a block body + } \ No newline at end of file diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.js b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.js new file mode 100644 index 00000000000..444b4b392c9 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.js @@ -0,0 +1,15 @@ +//// [asiPreventsParsingAsAmbientExternalModule02.ts] + +var declare: number; +var module: string; + +module container { + declare // this is the identifier 'declare' + module // this is the identifier 'module' + "my external module" // this is just a string + { } // this is a block body +} + +//// [asiPreventsParsingAsAmbientExternalModule02.js] +var declare; +var module; diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace01.js b/tests/baselines/reference/asiPreventsParsingAsNamespace01.js new file mode 100644 index 00000000000..eed9769da69 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace01.js @@ -0,0 +1,12 @@ +//// [asiPreventsParsingAsNamespace01.ts] + +var namespace: number; +var n: string; + +namespace // this is the identifier 'namespace' +n // this is the identifier 'n' +{ } // this is a block body + +//// [asiPreventsParsingAsNamespace01.js] +var namespace; +var n; diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace01.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace01.symbols new file mode 100644 index 00000000000..a2494904bed --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace01.symbols @@ -0,0 +1,13 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace01.ts === + +var namespace: number; +>namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace01.ts, 1, 3)) + +var n: string; +>n : Symbol(n, Decl(asiPreventsParsingAsNamespace01.ts, 2, 3), Decl(asiPreventsParsingAsNamespace01.ts, 2, 14)) + +namespace // this is the identifier 'namespace' +n // this is the identifier 'n' +>n : Symbol(n, Decl(asiPreventsParsingAsNamespace01.ts, 2, 3), Decl(asiPreventsParsingAsNamespace01.ts, 2, 14)) + +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace01.types b/tests/baselines/reference/asiPreventsParsingAsNamespace01.types new file mode 100644 index 00000000000..87044c58066 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace01.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace01.ts === + +var namespace: number; +>namespace : number + +var n: string; +>n : string + +namespace // this is the identifier 'namespace' +n // this is the identifier 'n' +>n : string + +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace02.js b/tests/baselines/reference/asiPreventsParsingAsNamespace02.js new file mode 100644 index 00000000000..de2bdfa8a9e --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace02.js @@ -0,0 +1,12 @@ +//// [asiPreventsParsingAsNamespace02.ts] + +var module: number; +var m: string; + +module // this is the identifier 'namespace' +m // this is the identifier 'm' +{ } // this is a block body + +//// [asiPreventsParsingAsNamespace02.js] +var module; +var m; diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace02.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace02.symbols new file mode 100644 index 00000000000..70024a8de62 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace02.symbols @@ -0,0 +1,13 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace02.ts === + +var module: number; +>module : Symbol(module, Decl(asiPreventsParsingAsNamespace02.ts, 1, 3)) + +var m: string; +>m : Symbol(m, Decl(asiPreventsParsingAsNamespace02.ts, 2, 3), Decl(asiPreventsParsingAsNamespace02.ts, 2, 14)) + +module // this is the identifier 'namespace' +m // this is the identifier 'm' +>m : Symbol(m, Decl(asiPreventsParsingAsNamespace02.ts, 2, 3), Decl(asiPreventsParsingAsNamespace02.ts, 2, 14)) + +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace02.types b/tests/baselines/reference/asiPreventsParsingAsNamespace02.types new file mode 100644 index 00000000000..8f6dec87a00 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace02.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace02.ts === + +var module: number; +>module : number + +var m: string; +>m : string + +module // this is the identifier 'namespace' +m // this is the identifier 'm' +>m : string + +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace03.js b/tests/baselines/reference/asiPreventsParsingAsNamespace03.js new file mode 100644 index 00000000000..6d8b8970977 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace03.js @@ -0,0 +1,14 @@ +//// [asiPreventsParsingAsNamespace03.ts] + +var namespace: number; +var n: string; + +namespace container { + namespace // this is the identifier 'namespace' + n // this is the identifier 'n' + { } // this is a block body +} + +//// [asiPreventsParsingAsNamespace03.js] +var namespace; +var n; diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace03.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace03.symbols new file mode 100644 index 00000000000..8dfa30c17a4 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace03.symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace03.ts === + +var namespace: number; +>namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace03.ts, 1, 3)) + +var n: string; +>n : Symbol(n, Decl(asiPreventsParsingAsNamespace03.ts, 2, 3)) + +namespace container { +>container : Symbol(container, Decl(asiPreventsParsingAsNamespace03.ts, 2, 14)) + + namespace // this is the identifier 'namespace' + n // this is the identifier 'n' +>n : Symbol(n, Decl(asiPreventsParsingAsNamespace03.ts, 4, 21)) + + { } // this is a block body +} diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace03.types b/tests/baselines/reference/asiPreventsParsingAsNamespace03.types new file mode 100644 index 00000000000..37423757159 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace03.types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace03.ts === + +var namespace: number; +>namespace : number + +var n: string; +>n : string + +namespace container { +>container : any + + namespace // this is the identifier 'namespace' + n // this is the identifier 'n' +>n : any + + { } // this is a block body +} diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.js b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.js new file mode 100644 index 00000000000..33e3895fab4 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.js @@ -0,0 +1,13 @@ +//// [asiPreventsParsingAsTypeAlias01.ts] + +var type; +var string; +var Foo; + +type +Foo = string; + +//// [asiPreventsParsingAsTypeAlias01.js] +var type; +var string; +var Foo; diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.symbols b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.symbols new file mode 100644 index 00000000000..d11c9ff5c13 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.symbols @@ -0,0 +1,15 @@ +=== tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias01.ts === + +var type; +>type : Symbol(type, Decl(asiPreventsParsingAsTypeAlias01.ts, 1, 3)) + +var string; +>string : Symbol(string, Decl(asiPreventsParsingAsTypeAlias01.ts, 2, 3)) + +var Foo; +>Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias01.ts, 3, 3), Decl(asiPreventsParsingAsTypeAlias01.ts, 3, 8)) + +type +Foo = string; +>Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias01.ts, 3, 3), Decl(asiPreventsParsingAsTypeAlias01.ts, 3, 8)) + diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types new file mode 100644 index 00000000000..d112022afa4 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias01.ts === + +var type; +>type : any + +var string; +>string : any + +var Foo; +>Foo : any + +type +Foo = string; +>Foo : string + diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.js b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.js new file mode 100644 index 00000000000..4a8298b2bdf --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.js @@ -0,0 +1,15 @@ +//// [asiPreventsParsingAsTypeAlias02.ts] + +var type; +var string; +var Foo; + +namespace container { + type + Foo = string; +} + +//// [asiPreventsParsingAsTypeAlias02.js] +var type; +var string; +var Foo; diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.symbols b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.symbols new file mode 100644 index 00000000000..0da88560109 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.symbols @@ -0,0 +1,18 @@ +=== tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias02.ts === + +var type; +>type : Symbol(type, Decl(asiPreventsParsingAsTypeAlias02.ts, 1, 3)) + +var string; +>string : Symbol(string, Decl(asiPreventsParsingAsTypeAlias02.ts, 2, 3)) + +var Foo; +>Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias02.ts, 3, 3)) + +namespace container { +>container : Symbol(container, Decl(asiPreventsParsingAsTypeAlias02.ts, 3, 8)) + + type + Foo = string; +>Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias02.ts, 5, 21)) +} diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.types b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.types new file mode 100644 index 00000000000..4af0721ec24 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.types @@ -0,0 +1,18 @@ +=== tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias02.ts === + +var type; +>type : any + +var string; +>string : any + +var Foo; +>Foo : any + +namespace container { +>container : any + + type + Foo = string; +>Foo : string +} From a10cd1e8226d97c904b35dffcd5d7890f4cbb062 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 2 Jun 2015 15:48:59 -0700 Subject: [PATCH 16/73] 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 77306a3ea6192c7eb56cd57371001ddcb156c71f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 2 Jun 2015 17:08:51 -0700 Subject: [PATCH 17/73] Added more tests. --- .../asiPreventsParsingAsNamespace04.ts | 3 +++ .../asiPreventsParsingAsNamespace05.ts | 10 ++++++++++ 2 files changed, 13 insertions(+) create mode 100644 tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts create mode 100644 tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05.ts diff --git a/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts b/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts new file mode 100644 index 00000000000..03021576ea5 --- /dev/null +++ b/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts @@ -0,0 +1,3 @@ + +let module = 10; +module in {} \ No newline at end of file diff --git a/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05.ts b/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05.ts new file mode 100644 index 00000000000..a821dbc363c --- /dev/null +++ b/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05.ts @@ -0,0 +1,10 @@ + +let namespace = 10; +namespace a.b { + export let c = 20; +} + +namespace +a.b.c +{ +} \ No newline at end of file From 70f74ad640a2f029b3df749273e58bcaa216b4f0 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 2 Jun 2015 17:31:20 -0700 Subject: [PATCH 18/73] Accepted more baselines. --- .../asiPreventsParsingAsNamespace04.errors.txt | 9 +++++++++ .../reference/asiPreventsParsingAsNamespace04.js | 8 ++++++++ .../reference/asiPreventsParsingAsNamespace05.js | 11 +++++++++++ .../asiPreventsParsingAsNamespace05.symbols | 12 ++++++++++++ .../reference/asiPreventsParsingAsNamespace05.types | 13 +++++++++++++ 5 files changed, 53 insertions(+) create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace04.errors.txt create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace04.js create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace05.js create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace05.symbols create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace05.types diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace04.errors.txt b/tests/baselines/reference/asiPreventsParsingAsNamespace04.errors.txt new file mode 100644 index 00000000000..d0a6be446aa --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace04.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts(3,8): error TS1003: Identifier expected. + + +==== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts (1 errors) ==== + + let module = 10; + module in {} + ~~ +!!! error TS1003: Identifier expected. \ No newline at end of file diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace04.js b/tests/baselines/reference/asiPreventsParsingAsNamespace04.js new file mode 100644 index 00000000000..bcd8975d46d --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace04.js @@ -0,0 +1,8 @@ +//// [asiPreventsParsingAsNamespace04.ts] + +let module = 10; +module in {} + +//// [asiPreventsParsingAsNamespace04.js] +var module = 10; + in {}; diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace05.js b/tests/baselines/reference/asiPreventsParsingAsNamespace05.js new file mode 100644 index 00000000000..0a525179d2d --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace05.js @@ -0,0 +1,11 @@ +//// [asiPreventsParsingAsNamespace05.ts] + +let namespace = 10; + +namespace +a.b.c +{ +} + +//// [asiPreventsParsingAsNamespace05.js] +var namespace = 10; diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace05.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace05.symbols new file mode 100644 index 00000000000..65125806b61 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace05.symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05.ts === + +let namespace = 10; +>namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace05.ts, 1, 3)) + +namespace +a.b.c +>a : Symbol(a, Decl(asiPreventsParsingAsNamespace05.ts, 1, 19)) +>b : Symbol(b, Decl(asiPreventsParsingAsNamespace05.ts, 4, 2)) +>c : Symbol(c, Decl(asiPreventsParsingAsNamespace05.ts, 4, 4)) +{ +} diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace05.types b/tests/baselines/reference/asiPreventsParsingAsNamespace05.types new file mode 100644 index 00000000000..f17ad1f2a1e --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace05.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05.ts === + +let namespace = 10; +>namespace : number +>10 : number + +namespace +a.b.c +>a : any +>b : any +>c : any +{ +} From 1bd7f5274a370061fb22871abca0e0eac94ccc68 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Tue, 2 Jun 2015 17:33:57 -0700 Subject: [PATCH 19/73] 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 fad7293412e..4023a4412de 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7657,6 +7657,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 155d7f48fff84f93b1c1c8399486ed53aacb3a3e Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Tue, 2 Jun 2015 17:54:08 -0700 Subject: [PATCH 20/73] 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 4023a4412de..543ab532624 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7658,6 +7658,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 6902b050ca9cb94ba494d0900ad48a0780850ef4 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 2 Jun 2015 18:04:05 -0700 Subject: [PATCH 21/73] 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 eb7290eb7008fa1a1ade9d3928c286616ccaa795 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Tue, 2 Jun 2015 18:06:05 -0700 Subject: [PATCH 22/73] 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 f66b9c5d77a4d427af50b34ad7081ef854d05aba Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Tue, 2 Jun 2015 18:13:39 -0700 Subject: [PATCH 23/73] Fix error message typo --- src/compiler/checker.ts | 2 +- src/compiler/diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- tests/baselines/reference/for-of32.errors.txt | 4 ++-- tests/baselines/reference/for-of33.errors.txt | 4 ++-- tests/baselines/reference/for-of34.errors.txt | 4 ++-- tests/baselines/reference/for-of35.errors.txt | 4 ++-- .../reference/implicitAnyFromCircularInference.errors.txt | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fad7293412e..2eedf6fb190 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2373,7 +2373,7 @@ module ts { // Variable has initializer that circularly references the variable itself type = anyType; if (compilerOptions.noImplicitAny) { - error(symbol.valueDeclaration, 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, + error(symbol.valueDeclaration, 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)); } } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 8ccc9d890e2..f0b46b26dc8 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -529,7 +529,7 @@ module ts { Object_literal_s_property_0_implicitly_has_an_1_type: { code: 7018, category: DiagnosticCategory.Error, key: "Object literal's property '{0}' implicitly has an '{1}' type." }, Rest_parameter_0_implicitly_has_an_any_type: { code: 7019, category: 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: 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: 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: 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: 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: 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: DiagnosticCategory.Error, key: "Generator implicitly has type '{0}' because it does not yield any values. Consider supplying a return type." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index fb246955f73..4e322725946 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2107,7 +2107,7 @@ "category": "Error", "code": 7020 }, - "'{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.": { "category": "Error", "code": 7022 }, diff --git a/tests/baselines/reference/for-of32.errors.txt b/tests/baselines/reference/for-of32.errors.txt index 4b139d386c0..f382ea40984 100644 --- a/tests/baselines/reference/for-of32.errors.txt +++ b/tests/baselines/reference/for-of32.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/es6/for-ofStatements/for-of32.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +tests/cases/conformance/es6/for-ofStatements/for-of32.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. ==== tests/cases/conformance/es6/for-ofStatements/for-of32.ts (1 errors) ==== for (var v of v) { } ~ -!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. \ No newline at end of file +!!! error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. \ No newline at end of file diff --git a/tests/baselines/reference/for-of33.errors.txt b/tests/baselines/reference/for-of33.errors.txt index cd2d48566ab..ff1feacd7b3 100644 --- a/tests/baselines/reference/for-of33.errors.txt +++ b/tests/baselines/reference/for-of33.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/es6/for-ofStatements/for-of33.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +tests/cases/conformance/es6/for-ofStatements/for-of33.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. tests/cases/conformance/es6/for-ofStatements/for-of33.ts(4,5): error TS7023: '[Symbol.iterator]' 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. ==== tests/cases/conformance/es6/for-ofStatements/for-of33.ts (2 errors) ==== for (var v of new StringIterator) { } ~ -!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +!!! error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. class StringIterator { [Symbol.iterator]() { diff --git a/tests/baselines/reference/for-of34.errors.txt b/tests/baselines/reference/for-of34.errors.txt index a4f55ed29ba..c378a8f5bb8 100644 --- a/tests/baselines/reference/for-of34.errors.txt +++ b/tests/baselines/reference/for-of34.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/es6/for-ofStatements/for-of34.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +tests/cases/conformance/es6/for-ofStatements/for-of34.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. tests/cases/conformance/es6/for-ofStatements/for-of34.ts(4,5): error TS7023: 'next' 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. ==== tests/cases/conformance/es6/for-ofStatements/for-of34.ts (2 errors) ==== for (var v of new StringIterator) { } ~ -!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +!!! error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. class StringIterator { next() { diff --git a/tests/baselines/reference/for-of35.errors.txt b/tests/baselines/reference/for-of35.errors.txt index 65529752b9b..58fb5056fd7 100644 --- a/tests/baselines/reference/for-of35.errors.txt +++ b/tests/baselines/reference/for-of35.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/es6/for-ofStatements/for-of35.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +tests/cases/conformance/es6/for-ofStatements/for-of35.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. tests/cases/conformance/es6/for-ofStatements/for-of35.ts(4,5): error TS7023: 'next' 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. ==== tests/cases/conformance/es6/for-ofStatements/for-of35.ts (2 errors) ==== for (var v of new StringIterator) { } ~ -!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +!!! error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. class StringIterator { next() { diff --git a/tests/baselines/reference/implicitAnyFromCircularInference.errors.txt b/tests/baselines/reference/implicitAnyFromCircularInference.errors.txt index 8d0aaf04c03..36538aef4f3 100644 --- a/tests/baselines/reference/implicitAnyFromCircularInference.errors.txt +++ b/tests/baselines/reference/implicitAnyFromCircularInference.errors.txt @@ -7,7 +7,7 @@ tests/cases/compiler/implicitAnyFromCircularInference.ts(18,10): error TS7024: F tests/cases/compiler/implicitAnyFromCircularInference.ts(23,10): error TS7024: 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. tests/cases/compiler/implicitAnyFromCircularInference.ts(26,10): error TS7023: 'h' 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. tests/cases/compiler/implicitAnyFromCircularInference.ts(28,14): error TS7023: 'foo' 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. -tests/cases/compiler/implicitAnyFromCircularInference.ts(41,5): error TS7022: 's' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +tests/cases/compiler/implicitAnyFromCircularInference.ts(41,5): error TS7022: 's' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. tests/cases/compiler/implicitAnyFromCircularInference.ts(46,5): error TS7023: 'x' 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. @@ -72,7 +72,7 @@ tests/cases/compiler/implicitAnyFromCircularInference.ts(46,5): error TS7023: 'x // Error expected s = foo(this); ~~~~~~~~~~~~~~ -!!! error TS7022: 's' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +!!! error TS7022: 's' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. } class D { From f390133a126b5dd7232bb8d11aded3291fd5c201 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Tue, 2 Jun 2015 18:21:39 -0700 Subject: [PATCH 24/73] 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 8b62a326d4fbf06c69777984256f2b8df48d1709 Mon Sep 17 00:00:00 2001 From: Zhengbo Li Date: Tue, 2 Jun 2015 19:22:03 -0700 Subject: [PATCH 25/73] Dom lib file bug fix Fix #3344; removed duplicated overloads for ``createEvent`` and some minor fixes. --- src/lib/dom.generated.d.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/lib/dom.generated.d.ts b/src/lib/dom.generated.d.ts index 5a4151c0c1c..d9daefa1aeb 100644 --- a/src/lib/dom.generated.d.ts +++ b/src/lib/dom.generated.d.ts @@ -7677,10 +7677,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; } @@ -8409,7 +8409,7 @@ declare var PopStateEvent: { interface Position { coords: Coordinates; - timestamp: Date; + timestamp: number; } declare var Position: { @@ -11090,6 +11090,7 @@ 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, pixels: ImageData): void; texParameterf(target: number, pname: number, param: number): void; texParameteri(target: number, pname: number, param: number): void; @@ -12332,12 +12333,14 @@ 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:"DocumentEvent"): DocumentEvent; createEvent(eventInterface:"DragEvent"): DragEvent; createEvent(eventInterface:"ErrorEvent"): ErrorEvent; createEvent(eventInterface:"Event"): Event; @@ -12358,8 +12361,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; @@ -12971,4 +12972,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; From e6ced33c1389633de8a335183f6057476f1f2e7c Mon Sep 17 00:00:00 2001 From: jbondc Date: Wed, 3 Jun 2015 11:56:30 -0400 Subject: [PATCH 26/73] Make index types optional in ResolvedType --- src/compiler/types.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 0fcf0e1f67a..296e75c4b76 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1588,7 +1588,7 @@ module ts { /* @internal */ ContainsUndefinedOrNull = 0x00040000, // Type is or contains Undefined or Null type /* @internal */ - ContainsObjectLiteral = 0x00080000, // Type is or contains object literal type + ContainsObjectLiteral = 0x00080000, // Type is or contains object literal type ESSymbol = 0x00100000, // Type of symbol primitive introduced in ES6 /* @internal */ @@ -1674,8 +1674,8 @@ module ts { properties: Symbol[]; // Properties callSignatures: Signature[]; // Call signatures of type constructSignatures: Signature[]; // Construct signatures of type - stringIndexType: Type; // String index type - numberIndexType: Type; // Numeric index type + stringIndexType?: Type; // String index type + numberIndexType?: Type; // Numeric index type } // Just a place to cache element types of iterables and iterators From 86d9398a929de9c5816e664a271ff392687107d2 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 1 Jun 2015 16:08:58 -0700 Subject: [PATCH 27/73] 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 3cac56af1ab7bb7c51a192a4f8ff8d4e9dbc06e6 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 3 Jun 2015 12:05:12 -0700 Subject: [PATCH 28/73] Fixed case for the 'declare' keyword. --- src/compiler/parser.ts | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 4a46e375f87..72cd3bb620d 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1818,7 +1818,7 @@ module ts { if (matchesPattern) { // Report that we need an identifier. However, report it right after the dot, // and not on the next token. This is because the next token might actually - // be an identifier and the error woudl be quite confusing. + // be an identifier and the error would be quite confusing. return createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentToken*/ true, Diagnostics.Identifier_expected); } } @@ -3981,19 +3981,31 @@ module ts { return parseDebuggerStatement(); case SyntaxKind.AtToken: return parseDeclaration(); - case SyntaxKind.ConstKeyword: case SyntaxKind.DeclareKeyword: + if (lookAhead(isFollowedByIdentifierOrKeywordOnSameLine) && getDeclarationFlags() & flags) { + return parseDeclaration(); + } + break; + case SyntaxKind.ModuleKeyword: + if (lookAhead(isFollowedByIdentifierOrStringOnSameLine) && getDeclarationFlags() & flags) { + return parseDeclaration(); + } + break; + case SyntaxKind.NamespaceKeyword: + case SyntaxKind.TypeKeyword: + if (lookAhead(isFollowedByIdentifierOnSameLine) && getDeclarationFlags() & flags) { + return parseDeclaration(); + } + break; + case SyntaxKind.ConstKeyword: case SyntaxKind.EnumKeyword: case SyntaxKind.ExportKeyword: case SyntaxKind.ImportKeyword: case SyntaxKind.InterfaceKeyword: - case SyntaxKind.ModuleKeyword: - case SyntaxKind.NamespaceKeyword: case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: case SyntaxKind.PublicKeyword: case SyntaxKind.StaticKeyword: - case SyntaxKind.TypeKeyword: if (getDeclarationFlags() & flags) { return parseDeclaration(); } @@ -4044,6 +4056,21 @@ module ts { } } + function isFollowedByIdentifierOrKeywordOnSameLine() { + nextToken(); + return !scanner.hasPrecedingLineBreak() && isIdentifierOrKeyword(); + } + + function isFollowedByIdentifierOrStringOnSameLine() { + nextToken(); + return !scanner.hasPrecedingLineBreak() && (isIdentifier() || token === SyntaxKind.StringLiteral); + } + + function isFollowedByIdentifierOnSameLine() { + nextToken(); + return !scanner.hasPrecedingLineBreak() && isIdentifier(); + } + function parseFunctionBlockOrSemicolon(isGenerator: boolean, diagnosticMessage?: DiagnosticMessage): Block { if (token !== SyntaxKind.OpenBraceToken && canParseSemicolon()) { parseSemicolon(); From 3cd480ddb6e5aae35d7504de9de5fb8ee4ea8b1d Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 3 Jun 2015 12:05:53 -0700 Subject: [PATCH 29/73] Accepted baselines. --- ...reventsParsingAsAmbientExternalModule01.js | 4 ++++ ...tsParsingAsAmbientExternalModule01.symbols | 4 ++++ ...entsParsingAsAmbientExternalModule01.types | 6 +++++ ...arsingAsAmbientExternalModule02.errors.txt | 16 -------------- ...reventsParsingAsAmbientExternalModule02.js | 7 ++++++ ...tsParsingAsAmbientExternalModule02.symbols | 20 +++++++++++++++++ ...entsParsingAsAmbientExternalModule02.types | 22 +++++++++++++++++++ .../asiPreventsParsingAsNamespace01.js | 3 +++ .../asiPreventsParsingAsNamespace01.symbols | 6 +++-- .../asiPreventsParsingAsNamespace01.types | 2 ++ .../asiPreventsParsingAsNamespace02.js | 3 +++ .../asiPreventsParsingAsNamespace02.symbols | 6 +++-- .../asiPreventsParsingAsNamespace02.types | 2 ++ .../asiPreventsParsingAsNamespace03.js | 6 +++++ .../asiPreventsParsingAsNamespace03.symbols | 4 +++- .../asiPreventsParsingAsNamespace03.types | 6 +++-- ...asiPreventsParsingAsNamespace04.errors.txt | 9 -------- .../asiPreventsParsingAsNamespace04.js | 2 +- .../asiPreventsParsingAsNamespace04.symbols | 8 +++++++ .../asiPreventsParsingAsNamespace04.types | 11 ++++++++++ .../asiPreventsParsingAsNamespace05.js | 14 ++++++++++++ .../asiPreventsParsingAsNamespace05.symbols | 20 +++++++++++++---- .../asiPreventsParsingAsNamespace05.types | 19 +++++++++++++--- .../asiPreventsParsingAsTypeAlias01.js | 2 ++ .../asiPreventsParsingAsTypeAlias01.symbols | 9 +++++--- .../asiPreventsParsingAsTypeAlias01.types | 8 +++++-- .../asiPreventsParsingAsTypeAlias02.js | 5 +++++ .../asiPreventsParsingAsTypeAlias02.symbols | 5 ++++- .../asiPreventsParsingAsTypeAlias02.types | 8 +++++-- .../reservedNamesInAliases.errors.txt | 13 ++++++----- .../reference/reservedNamesInAliases.js | 2 ++ .../reference/reservedWords2.errors.txt | 10 ++++----- tests/baselines/reference/reservedWords2.js | 1 + 33 files changed, 205 insertions(+), 58 deletions(-) delete mode 100644 tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.errors.txt create mode 100644 tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.symbols create mode 100644 tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.types delete mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace04.errors.txt create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace04.symbols create mode 100644 tests/baselines/reference/asiPreventsParsingAsNamespace04.types diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.js b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.js index efd82f27d1f..caf90acae5f 100644 --- a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.js +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.js @@ -11,3 +11,7 @@ module // this is the identifier 'module' //// [asiPreventsParsingAsAmbientExternalModule01.js] var declare; var module; +declare; // this is the identifier 'declare' +module; // this is the identifier 'module' +"my external module"; // this is just a string +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.symbols b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.symbols index 87eb8daf7e2..c35432b7ece 100644 --- a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.symbols +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.symbols @@ -7,6 +7,10 @@ var module: string; >module : Symbol(module, Decl(asiPreventsParsingAsAmbientExternalModule01.ts, 2, 3)) declare // this is the identifier 'declare' +>declare : Symbol(declare, Decl(asiPreventsParsingAsAmbientExternalModule01.ts, 1, 3)) + module // this is the identifier 'module' +>module : Symbol(module, Decl(asiPreventsParsingAsAmbientExternalModule01.ts, 2, 3)) + "my external module" // this is just a string { } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.types b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.types index 94a2cc8d6a1..3e6aade9a21 100644 --- a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.types +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.types @@ -7,6 +7,12 @@ var module: string; >module : string declare // this is the identifier 'declare' +>declare : number + module // this is the identifier 'module' +>module : string + "my external module" // this is just a string +>"my external module" : string + { } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.errors.txt b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.errors.txt deleted file mode 100644 index 3064b137a19..00000000000 --- a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.errors.txt +++ /dev/null @@ -1,16 +0,0 @@ -tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule02.ts(8,5): error TS2435: Ambient modules cannot be nested in other modules. - - -==== tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule02.ts (1 errors) ==== - - var declare: number; - var module: string; - - module container { - declare // this is the identifier 'declare' - module // this is the identifier 'module' - "my external module" // this is just a string - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2435: Ambient modules cannot be nested in other modules. - { } // this is a block body - } \ No newline at end of file diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.js b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.js index 444b4b392c9..20e2693ba7f 100644 --- a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.js +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.js @@ -13,3 +13,10 @@ module container { //// [asiPreventsParsingAsAmbientExternalModule02.js] var declare; var module; +var container; +(function (container) { + declare; // this is the identifier 'declare' + module; // this is the identifier 'module' + "my external module"; // this is just a string + { } // this is a block body +})(container || (container = {})); diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.symbols b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.symbols new file mode 100644 index 00000000000..ed97f39fc11 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.symbols @@ -0,0 +1,20 @@ +=== tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule02.ts === + +var declare: number; +>declare : Symbol(declare, Decl(asiPreventsParsingAsAmbientExternalModule02.ts, 1, 3)) + +var module: string; +>module : Symbol(module, Decl(asiPreventsParsingAsAmbientExternalModule02.ts, 2, 3)) + +module container { +>container : Symbol(container, Decl(asiPreventsParsingAsAmbientExternalModule02.ts, 2, 19)) + + declare // this is the identifier 'declare' +>declare : Symbol(declare, Decl(asiPreventsParsingAsAmbientExternalModule02.ts, 1, 3)) + + module // this is the identifier 'module' +>module : Symbol(module, Decl(asiPreventsParsingAsAmbientExternalModule02.ts, 2, 3)) + + "my external module" // this is just a string + { } // this is a block body +} diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.types b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.types new file mode 100644 index 00000000000..67671853993 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule02.ts === + +var declare: number; +>declare : number + +var module: string; +>module : string + +module container { +>container : typeof container + + declare // this is the identifier 'declare' +>declare : number + + module // this is the identifier 'module' +>module : string + + "my external module" // this is just a string +>"my external module" : string + + { } // this is a block body +} diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace01.js b/tests/baselines/reference/asiPreventsParsingAsNamespace01.js index eed9769da69..282d9dd1c7c 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace01.js +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace01.js @@ -10,3 +10,6 @@ n // this is the identifier 'n' //// [asiPreventsParsingAsNamespace01.js] var namespace; var n; +namespace; // this is the identifier 'namespace' +n; // this is the identifier 'n' +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace01.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace01.symbols index a2494904bed..b196d733352 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace01.symbols +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace01.symbols @@ -4,10 +4,12 @@ var namespace: number; >namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace01.ts, 1, 3)) var n: string; ->n : Symbol(n, Decl(asiPreventsParsingAsNamespace01.ts, 2, 3), Decl(asiPreventsParsingAsNamespace01.ts, 2, 14)) +>n : Symbol(n, Decl(asiPreventsParsingAsNamespace01.ts, 2, 3)) namespace // this is the identifier 'namespace' +>namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace01.ts, 1, 3)) + n // this is the identifier 'n' ->n : Symbol(n, Decl(asiPreventsParsingAsNamespace01.ts, 2, 3), Decl(asiPreventsParsingAsNamespace01.ts, 2, 14)) +>n : Symbol(n, Decl(asiPreventsParsingAsNamespace01.ts, 2, 3)) { } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace01.types b/tests/baselines/reference/asiPreventsParsingAsNamespace01.types index 87044c58066..417a96dbed4 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace01.types +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace01.types @@ -7,6 +7,8 @@ var n: string; >n : string namespace // this is the identifier 'namespace' +>namespace : number + n // this is the identifier 'n' >n : string diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace02.js b/tests/baselines/reference/asiPreventsParsingAsNamespace02.js index de2bdfa8a9e..514a026dc78 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace02.js +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace02.js @@ -10,3 +10,6 @@ m // this is the identifier 'm' //// [asiPreventsParsingAsNamespace02.js] var module; var m; +module; // this is the identifier 'namespace' +m; // this is the identifier 'm' +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace02.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace02.symbols index 70024a8de62..a3bb37c73bc 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace02.symbols +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace02.symbols @@ -4,10 +4,12 @@ var module: number; >module : Symbol(module, Decl(asiPreventsParsingAsNamespace02.ts, 1, 3)) var m: string; ->m : Symbol(m, Decl(asiPreventsParsingAsNamespace02.ts, 2, 3), Decl(asiPreventsParsingAsNamespace02.ts, 2, 14)) +>m : Symbol(m, Decl(asiPreventsParsingAsNamespace02.ts, 2, 3)) module // this is the identifier 'namespace' +>module : Symbol(module, Decl(asiPreventsParsingAsNamespace02.ts, 1, 3)) + m // this is the identifier 'm' ->m : Symbol(m, Decl(asiPreventsParsingAsNamespace02.ts, 2, 3), Decl(asiPreventsParsingAsNamespace02.ts, 2, 14)) +>m : Symbol(m, Decl(asiPreventsParsingAsNamespace02.ts, 2, 3)) { } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace02.types b/tests/baselines/reference/asiPreventsParsingAsNamespace02.types index 8f6dec87a00..e9e1433be7a 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace02.types +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace02.types @@ -7,6 +7,8 @@ var m: string; >m : string module // this is the identifier 'namespace' +>module : number + m // this is the identifier 'm' >m : string diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace03.js b/tests/baselines/reference/asiPreventsParsingAsNamespace03.js index 6d8b8970977..3c27694f5ce 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace03.js +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace03.js @@ -12,3 +12,9 @@ namespace container { //// [asiPreventsParsingAsNamespace03.js] var namespace; var n; +var container; +(function (container) { + namespace; // this is the identifier 'namespace' + n; // this is the identifier 'n' + { } // this is a block body +})(container || (container = {})); diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace03.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace03.symbols index 8dfa30c17a4..e77d012a1bf 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace03.symbols +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace03.symbols @@ -10,8 +10,10 @@ namespace container { >container : Symbol(container, Decl(asiPreventsParsingAsNamespace03.ts, 2, 14)) namespace // this is the identifier 'namespace' +>namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace03.ts, 1, 3)) + n // this is the identifier 'n' ->n : Symbol(n, Decl(asiPreventsParsingAsNamespace03.ts, 4, 21)) +>n : Symbol(n, Decl(asiPreventsParsingAsNamespace03.ts, 2, 3)) { } // this is a block body } diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace03.types b/tests/baselines/reference/asiPreventsParsingAsNamespace03.types index 37423757159..f119a789e11 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace03.types +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace03.types @@ -7,11 +7,13 @@ var n: string; >n : string namespace container { ->container : any +>container : typeof container namespace // this is the identifier 'namespace' +>namespace : number + n // this is the identifier 'n' ->n : any +>n : string { } // this is a block body } diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace04.errors.txt b/tests/baselines/reference/asiPreventsParsingAsNamespace04.errors.txt deleted file mode 100644 index d0a6be446aa..00000000000 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace04.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts(3,8): error TS1003: Identifier expected. - - -==== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts (1 errors) ==== - - let module = 10; - module in {} - ~~ -!!! error TS1003: Identifier expected. \ No newline at end of file diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace04.js b/tests/baselines/reference/asiPreventsParsingAsNamespace04.js index bcd8975d46d..704c8893e76 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace04.js +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace04.js @@ -5,4 +5,4 @@ module in {} //// [asiPreventsParsingAsNamespace04.js] var module = 10; - in {}; +module in {}; diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace04.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace04.symbols new file mode 100644 index 00000000000..60d1f8fcc48 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace04.symbols @@ -0,0 +1,8 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts === + +let module = 10; +>module : Symbol(module, Decl(asiPreventsParsingAsNamespace04.ts, 1, 3)) + +module in {} +>module : Symbol(module, Decl(asiPreventsParsingAsNamespace04.ts, 1, 3)) + diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace04.types b/tests/baselines/reference/asiPreventsParsingAsNamespace04.types new file mode 100644 index 00000000000..3fa2a448cf9 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace04.types @@ -0,0 +1,11 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts === + +let module = 10; +>module : number +>10 : number + +module in {} +>module in {} : boolean +>module : number +>{} : {} + diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace05.js b/tests/baselines/reference/asiPreventsParsingAsNamespace05.js index 0a525179d2d..35f557328c0 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace05.js +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace05.js @@ -1,6 +1,9 @@ //// [asiPreventsParsingAsNamespace05.ts] let namespace = 10; +namespace a.b { + export let c = 20; +} namespace a.b.c @@ -9,3 +12,14 @@ a.b.c //// [asiPreventsParsingAsNamespace05.js] var namespace = 10; +var a; +(function (a) { + var b; + (function (b) { + b.c = 20; + })(b = a.b || (a.b = {})); +})(a || (a = {})); +namespace; +a.b.c; +{ +} diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace05.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace05.symbols index 65125806b61..47f05862b0a 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace05.symbols +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace05.symbols @@ -3,10 +3,22 @@ let namespace = 10; >namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace05.ts, 1, 3)) -namespace -a.b.c +namespace a.b { >a : Symbol(a, Decl(asiPreventsParsingAsNamespace05.ts, 1, 19)) ->b : Symbol(b, Decl(asiPreventsParsingAsNamespace05.ts, 4, 2)) ->c : Symbol(c, Decl(asiPreventsParsingAsNamespace05.ts, 4, 4)) +>b : Symbol(b, Decl(asiPreventsParsingAsNamespace05.ts, 2, 12)) + + export let c = 20; +>c : Symbol(c, Decl(asiPreventsParsingAsNamespace05.ts, 3, 14)) +} + +namespace +>namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace05.ts, 1, 3)) + +a.b.c +>a.b.c : Symbol(a.b.c, Decl(asiPreventsParsingAsNamespace05.ts, 3, 14)) +>a.b : Symbol(a.b, Decl(asiPreventsParsingAsNamespace05.ts, 2, 12)) +>a : Symbol(a, Decl(asiPreventsParsingAsNamespace05.ts, 1, 19)) +>b : Symbol(a.b, Decl(asiPreventsParsingAsNamespace05.ts, 2, 12)) +>c : Symbol(a.b.c, Decl(asiPreventsParsingAsNamespace05.ts, 3, 14)) { } diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace05.types b/tests/baselines/reference/asiPreventsParsingAsNamespace05.types index f17ad1f2a1e..515147c1096 100644 --- a/tests/baselines/reference/asiPreventsParsingAsNamespace05.types +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace05.types @@ -4,10 +4,23 @@ let namespace = 10; >namespace : number >10 : number +namespace a.b { +>a : typeof a +>b : typeof b + + export let c = 20; +>c : number +>20 : number +} + namespace +>namespace : number + a.b.c ->a : any ->b : any ->c : any +>a.b.c : number +>a.b : typeof a.b +>a : typeof a +>b : typeof a.b +>c : number { } diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.js b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.js index 33e3895fab4..b05988290cb 100644 --- a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.js +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.js @@ -11,3 +11,5 @@ Foo = string; var type; var string; var Foo; +type; +Foo = string; diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.symbols b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.symbols index d11c9ff5c13..fa82d53ac70 100644 --- a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.symbols +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.symbols @@ -7,9 +7,12 @@ var string; >string : Symbol(string, Decl(asiPreventsParsingAsTypeAlias01.ts, 2, 3)) var Foo; ->Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias01.ts, 3, 3), Decl(asiPreventsParsingAsTypeAlias01.ts, 3, 8)) +>Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias01.ts, 3, 3)) type -Foo = string; ->Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias01.ts, 3, 3), Decl(asiPreventsParsingAsTypeAlias01.ts, 3, 8)) +>type : Symbol(type, Decl(asiPreventsParsingAsTypeAlias01.ts, 1, 3)) + +Foo = string; +>Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias01.ts, 3, 3)) +>string : Symbol(string, Decl(asiPreventsParsingAsTypeAlias01.ts, 2, 3)) diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types index d112022afa4..7492a698e3a 100644 --- a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types @@ -10,6 +10,10 @@ var Foo; >Foo : any type -Foo = string; ->Foo : string +>type : any + +Foo = string; +>Foo = string : any +>Foo : any +>string : any diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.js b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.js index 4a8298b2bdf..eae9898c8d4 100644 --- a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.js +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.js @@ -13,3 +13,8 @@ namespace container { var type; var string; var Foo; +var container; +(function (container) { + type; + Foo = string; +})(container || (container = {})); diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.symbols b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.symbols index 0da88560109..4b83dba4c5d 100644 --- a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.symbols +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.symbols @@ -13,6 +13,9 @@ namespace container { >container : Symbol(container, Decl(asiPreventsParsingAsTypeAlias02.ts, 3, 8)) type +>type : Symbol(type, Decl(asiPreventsParsingAsTypeAlias02.ts, 1, 3)) + Foo = string; ->Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias02.ts, 5, 21)) +>Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias02.ts, 3, 3)) +>string : Symbol(string, Decl(asiPreventsParsingAsTypeAlias02.ts, 2, 3)) } diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.types b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.types index 4af0721ec24..1e6c7a8caf1 100644 --- a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.types +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.types @@ -10,9 +10,13 @@ var Foo; >Foo : any namespace container { ->container : any +>container : typeof container type +>type : any + Foo = string; ->Foo : string +>Foo = string : any +>Foo : any +>string : any } diff --git a/tests/baselines/reference/reservedNamesInAliases.errors.txt b/tests/baselines/reference/reservedNamesInAliases.errors.txt index 277e06111c4..5c17158053e 100644 --- a/tests/baselines/reference/reservedNamesInAliases.errors.txt +++ b/tests/baselines/reference/reservedNamesInAliases.errors.txt @@ -2,12 +2,13 @@ tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(2,6): error tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(3,6): error TS2457: Type alias name cannot be 'number' tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(4,6): error TS2457: Type alias name cannot be 'boolean' tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(5,6): error TS2457: Type alias name cannot be 'string' -tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,6): error TS1003: Identifier expected. -tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,11): error TS1005: ';' expected. +tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,1): error TS2304: Cannot find name 'type'. +tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,6): error TS1005: ';' expected. +tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,11): error TS1109: Expression expected. tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,13): error TS2304: Cannot find name 'I'. -==== tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts (7 errors) ==== +==== tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts (8 errors) ==== interface I {} type any = I; ~~~ @@ -22,9 +23,11 @@ tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,13): error ~~~~~~ !!! error TS2457: Type alias name cannot be 'string' type void = I; + ~~~~ +!!! error TS2304: Cannot find name 'type'. ~~~~ -!!! error TS1003: Identifier expected. - ~ !!! error TS1005: ';' expected. + ~ +!!! error TS1109: Expression expected. ~ !!! error TS2304: Cannot find name 'I'. \ No newline at end of file diff --git a/tests/baselines/reference/reservedNamesInAliases.js b/tests/baselines/reference/reservedNamesInAliases.js index 773cc3ca84a..4ebc3bdb95f 100644 --- a/tests/baselines/reference/reservedNamesInAliases.js +++ b/tests/baselines/reference/reservedNamesInAliases.js @@ -7,4 +7,6 @@ type string = I; type void = I; //// [reservedNamesInAliases.js] +type; +void ; I; diff --git a/tests/baselines/reference/reservedWords2.errors.txt b/tests/baselines/reference/reservedWords2.errors.txt index 471eef4710a..090b2d0d43e 100644 --- a/tests/baselines/reference/reservedWords2.errors.txt +++ b/tests/baselines/reference/reservedWords2.errors.txt @@ -13,8 +13,8 @@ tests/cases/compiler/reservedWords2.ts(4,12): error TS1109: Expression expected. tests/cases/compiler/reservedWords2.ts(5,9): error TS2300: Duplicate identifier '(Missing)'. tests/cases/compiler/reservedWords2.ts(5,10): error TS1003: Identifier expected. tests/cases/compiler/reservedWords2.ts(5,18): error TS1005: '=>' expected. -tests/cases/compiler/reservedWords2.ts(6,7): error TS2300: Duplicate identifier '(Missing)'. -tests/cases/compiler/reservedWords2.ts(6,8): error TS1003: Identifier expected. +tests/cases/compiler/reservedWords2.ts(6,1): error TS2304: Cannot find name 'module'. +tests/cases/compiler/reservedWords2.ts(6,8): error TS1005: ';' expected. tests/cases/compiler/reservedWords2.ts(7,11): error TS2300: Duplicate identifier '(Missing)'. tests/cases/compiler/reservedWords2.ts(7,11): error TS1005: ':' expected. tests/cases/compiler/reservedWords2.ts(7,19): error TS2300: Duplicate identifier '(Missing)'. @@ -68,10 +68,10 @@ tests/cases/compiler/reservedWords2.ts(10,6): error TS1003: Identifier expected. ~ !!! error TS1005: '=>' expected. module void {} - -!!! error TS2300: Duplicate identifier '(Missing)'. + ~~~~~~ +!!! error TS2304: Cannot find name 'module'. ~~~~ -!!! error TS1003: Identifier expected. +!!! error TS1005: ';' expected. var {while, return} = { while: 1, return: 2 }; !!! error TS2300: Duplicate identifier '(Missing)'. diff --git a/tests/baselines/reference/reservedWords2.js b/tests/baselines/reference/reservedWords2.js index 6d5a5f530c5..fb90a718ec3 100644 --- a/tests/baselines/reference/reservedWords2.js +++ b/tests/baselines/reference/reservedWords2.js @@ -23,6 +23,7 @@ var ; typeof ; 10; throw function () { }; +module; void {}; var _a = { while: 1, return: 2 }, = _a.while, = _a.return; var _b = { this: 1, switch: { continue: 2 } }, = _b.this, = _b.switch.continue; From 46da6678ad082b53de4698740fa751bba7c8c29a Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Tue, 2 Jun 2015 17:33:57 -0700 Subject: [PATCH 30/73] 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 31/73] 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 32/73] 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 33/73] 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 34/73] 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 c7b2fe016d06fd4c9da9b4b44a61ea1288fd5b07 Mon Sep 17 00:00:00 2001 From: Zhengbo Li Date: Wed, 3 Jun 2015 13:40:36 -0700 Subject: [PATCH 35/73] Remove the DocumentEvent itself from createEvent overload. --- src/lib/dom.generated.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/dom.generated.d.ts b/src/lib/dom.generated.d.ts index d9daefa1aeb..31bf794d8fd 100644 --- a/src/lib/dom.generated.d.ts +++ b/src/lib/dom.generated.d.ts @@ -12340,7 +12340,6 @@ interface DocumentEvent { createEvent(eventInterface:"CustomEvent"): CustomEvent; createEvent(eventInterface:"DeviceMotionEvent"): DeviceMotionEvent; createEvent(eventInterface:"DeviceOrientationEvent"): DeviceOrientationEvent; - createEvent(eventInterface:"DocumentEvent"): DocumentEvent; createEvent(eventInterface:"DragEvent"): DragEvent; createEvent(eventInterface:"ErrorEvent"): ErrorEvent; createEvent(eventInterface:"Event"): Event; From 3fe308d2a6b642704942cb4b1ee8fe8438d22e3f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 3 Jun 2015 13:46:13 -0700 Subject: [PATCH 36/73] Added an explanation for the lookahead. --- src/compiler/parser.ts | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 72cd3bb620d..914952d5169 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3973,7 +3973,7 @@ module ts { case SyntaxKind.ThrowKeyword: return parseThrowStatement(); case SyntaxKind.TryKeyword: - // Include the next two for error recovery. + // Include 'catch' and 'finally' for error recovery. case SyntaxKind.CatchKeyword: case SyntaxKind.FinallyKeyword: return parseTryStatement(); @@ -3981,6 +3981,33 @@ module ts { return parseDebuggerStatement(); case SyntaxKind.AtToken: return parseDeclaration(); + + case SyntaxKind.ConstKeyword: + case SyntaxKind.EnumKeyword: + case SyntaxKind.ExportKeyword: + case SyntaxKind.ImportKeyword: + case SyntaxKind.InterfaceKeyword: + case SyntaxKind.PrivateKeyword: + case SyntaxKind.ProtectedKeyword: + case SyntaxKind.PublicKeyword: + case SyntaxKind.StaticKeyword: + if (getDeclarationFlags() & flags) { + return parseDeclaration(); + } + break; + + // 'declare', 'module', 'namespace', and 'type' are all legal JavaScript identifiers when ASI + // takes effect. In such cases, we cannot parse out the "expected" declarations. For instance, while + // + // namespace n + // + // can be none other than the beginning of a namespace declaration, JavaScript sees + // + // namespace + // n + // + // as the identifier 'namespace' on one line followed by the identifier 'n' on another. + // We need to look one token ahead to see if it permissible to try parsing a declaration. case SyntaxKind.DeclareKeyword: if (lookAhead(isFollowedByIdentifierOrKeywordOnSameLine) && getDeclarationFlags() & flags) { return parseDeclaration(); @@ -3997,19 +4024,6 @@ module ts { return parseDeclaration(); } break; - case SyntaxKind.ConstKeyword: - case SyntaxKind.EnumKeyword: - case SyntaxKind.ExportKeyword: - case SyntaxKind.ImportKeyword: - case SyntaxKind.InterfaceKeyword: - case SyntaxKind.PrivateKeyword: - case SyntaxKind.ProtectedKeyword: - case SyntaxKind.PublicKeyword: - case SyntaxKind.StaticKeyword: - if (getDeclarationFlags() & flags) { - return parseDeclaration(); - } - break; } return parseExpressionOrLabeledStatement(); } From 269ae3ab995847d0e0db00d546486cfbfbf24ff7 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 3 Jun 2015 13:48:34 -0700 Subject: [PATCH 37/73] 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 64a31e2e51e7911db411a6f22fa46896f23d7121 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 3 Jun 2015 13:51:53 -0700 Subject: [PATCH 38/73] Renamed functions, removed the duplicates found from renaming. --- src/compiler/parser.ts | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 914952d5169..b430a27e2b4 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2688,7 +2688,7 @@ module ts { function nextTokenIsIdentifierOnSameLine() { nextToken(); - return !scanner.hasPrecedingLineBreak() && isIdentifier() + return !scanner.hasPrecedingLineBreak() && isIdentifier(); } function parseYieldExpression(): YieldExpression { @@ -4009,18 +4009,18 @@ module ts { // as the identifier 'namespace' on one line followed by the identifier 'n' on another. // We need to look one token ahead to see if it permissible to try parsing a declaration. case SyntaxKind.DeclareKeyword: - if (lookAhead(isFollowedByIdentifierOrKeywordOnSameLine) && getDeclarationFlags() & flags) { + if (lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine) && getDeclarationFlags() & flags) { return parseDeclaration(); } break; case SyntaxKind.ModuleKeyword: - if (lookAhead(isFollowedByIdentifierOrStringOnSameLine) && getDeclarationFlags() & flags) { + if (lookAhead(nextTokenIsIdentifierOrStringLiteralOnSameLine) && getDeclarationFlags() & flags) { return parseDeclaration(); } break; case SyntaxKind.NamespaceKeyword: case SyntaxKind.TypeKeyword: - if (lookAhead(isFollowedByIdentifierOnSameLine) && getDeclarationFlags() & flags) { + if (lookAhead(nextTokenIsIdentifierOnSameLine) && getDeclarationFlags() & flags) { return parseDeclaration(); } break; @@ -4070,21 +4070,11 @@ module ts { } } - function isFollowedByIdentifierOrKeywordOnSameLine() { - nextToken(); - return !scanner.hasPrecedingLineBreak() && isIdentifierOrKeyword(); - } - - function isFollowedByIdentifierOrStringOnSameLine() { + function nextTokenIsIdentifierOrStringLiteralOnSameLine() { nextToken(); return !scanner.hasPrecedingLineBreak() && (isIdentifier() || token === SyntaxKind.StringLiteral); } - function isFollowedByIdentifierOnSameLine() { - nextToken(); - return !scanner.hasPrecedingLineBreak() && isIdentifier(); - } - function parseFunctionBlockOrSemicolon(isGenerator: boolean, diagnosticMessage?: DiagnosticMessage): Block { if (token !== SyntaxKind.OpenBraceToken && canParseSemicolon()) { parseSemicolon(); From cdb6d5bca5cafb37bc5efc0ab24e018d200d1c97 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 3 Jun 2015 13:56:55 -0700 Subject: [PATCH 39/73] Don't access the anyType directly. Encapsulate all access to it behind a helper. --- src/compiler/checker.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index aa2207d5431..903d5964a44 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2131,6 +2131,10 @@ module ts { return prop ? getTypeOfSymbol(prop) : undefined; } + function isTheAnyType(type: Type) { + return type === anyType; + } + // Return the inferred type for a binding element function getTypeForBindingElement(declaration: BindingElement): Type { let pattern = declaration.parent; @@ -2142,7 +2146,7 @@ module 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 || isTheAnyType(parentType)) { if (declaration.initializer) { return checkExpressionCached(declaration.initializer); } @@ -5547,7 +5551,7 @@ module ts { if (prototypeProperty) { // Target type is type of the protoype property let prototypePropertyType = getTypeOfSymbol(prototypeProperty); - if (prototypePropertyType !== anyType) { + if (!isTheAnyType(prototypePropertyType)) { targetType = prototypePropertyType; } } @@ -6496,7 +6500,7 @@ module ts { function checkPropertyAccessExpressionOrQualifiedName(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, right: Identifier) { let type = checkExpressionOrQualifiedName(left); if (type === unknownType) return type; - if (type !== anyType) { + if (!isTheAnyType(type)) { let apparentType = getApparentType(getWidenedType(type)); if (apparentType === unknownType) { // handle cases when type is Type parameter with invalid constraint @@ -6536,7 +6540,7 @@ module ts { : (node).left; let type = checkExpressionOrQualifiedName(left); - if (type !== unknownType && type !== anyType) { + if (type !== unknownType && !isTheAnyType(type)) { let prop = getPropertyOfType(getWidenedType(type), propertyName); if (prop && prop.parent && prop.parent.flags & SymbolFlags.Class) { if (left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.MethodDeclaration) { @@ -6626,7 +6630,7 @@ module ts { } // Fall back to any. - if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && objectType !== anyType) { + if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && !isTheAnyType(objectType)) { error(node, Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type); } @@ -7276,7 +7280,7 @@ module 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 & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) { + if (isTheAnyType(funcType) || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) { if (node.typeArguments) { error(node, Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } @@ -7309,7 +7313,7 @@ module ts { // 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 (isTheAnyType(expressionType)) { if (node.typeArguments) { error(node, Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } @@ -7364,7 +7368,7 @@ module ts { let callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call); - if (tagType === anyType || (!callSignatures.length && !(tagType.flags & TypeFlags.Union) && isTypeAssignableTo(tagType, globalFunctionType))) { + if (isTheAnyType(tagType) || (!callSignatures.length && !(tagType.flags & TypeFlags.Union) && isTypeAssignableTo(tagType, globalFunctionType))) { return resolveUntypedCall(node); } @@ -7576,7 +7580,7 @@ module ts { } // Functions that return 'void' or 'any' don't need any return expressions. - if (returnType === voidType || returnType === anyType) { + if (returnType === voidType || isTheAnyType(returnType)) { return; } From dd8f3c41ad9eb06ddfd40b5d76a2cd4d2155b1db Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 3 Jun 2015 14:08:37 -0700 Subject: [PATCH 40/73] Addressing CR feedback --- src/compiler/checker.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c180d8425f2..45a40135be8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4306,6 +4306,7 @@ module 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: ObjectType, stack: ObjectType[]): boolean { + // We track type references (created by createTypeReference) and instantiated types (created by instantiateType) if (type.flags & (TypeFlags.Reference | TypeFlags.Instantiated) && depth >= 10) { let symbol = type.symbol; let count = 0; From 7e3a3f45e15cc8cd9f13106f8c3140cb5a63eaf9 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 3 Jun 2015 14:55:42 -0700 Subject: [PATCH 41/73] emit module name for system modules, add moduleName argument to 'transpile' function --- src/compiler/emitter.ts | 10 +++++++--- src/compiler/parser.ts | 2 +- src/compiler/types.ts | 2 +- src/services/services.ts | 7 +++++-- .../baselines/reference/systemModule12.errors.txt | 10 ++++++++++ tests/baselines/reference/systemModule12.js | 14 ++++++++++++++ tests/cases/compiler/systemModule12.ts | 5 +++++ 7 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 tests/baselines/reference/systemModule12.errors.txt create mode 100644 tests/baselines/reference/systemModule12.js create mode 100644 tests/cases/compiler/systemModule12.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index d0d65aec2fb..794d0d59382 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5527,7 +5527,11 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { Debug.assert(!exportFunctionForFile); // make sure that name of 'exports' function does not conflict with existing identifiers exportFunctionForFile = makeUniqueName("exports"); - write("System.register(["); + write("System.register("); + if (node.moduleName) { + write(`"${node.moduleName}", `); + } + write("[") for (let i = 0; i < externalImports.length; ++i) { let text = getExternalModuleNameText(externalImports[i]); if (i !== 0) { @@ -5613,8 +5617,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { writeLine(); write("define("); - if (node.amdModuleName) { - write("\"" + node.amdModuleName + "\", "); + if (node.moduleName) { + write("\"" + node.moduleName + "\", "); } emitAMDDependencies(node, /*includeNonAmdDependencies*/ true); write(") {"); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 80c70a250fb..9129a606f89 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4895,7 +4895,7 @@ module ts { sourceFile.referencedFiles = referencedFiles; sourceFile.amdDependencies = amdDependencies; - sourceFile.amdModuleName = amdModuleName; + sourceFile.moduleName = amdModuleName; } function setExternalModuleIndicator(sourceFile: SourceFile) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 0fcf0e1f67a..a10c1c52c37 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1134,7 +1134,7 @@ module ts { text: string; amdDependencies: {path: string; name: string}[]; - amdModuleName: string; + moduleName: string; referencedFiles: FileReference[]; hasNoDefaultLib: boolean; diff --git a/src/services/services.ts b/src/services/services.ts index 400bf754a00..f56a41178a4 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -735,7 +735,7 @@ module ts { public endOfFileToken: Node; public amdDependencies: { name: string; path: string }[]; - public amdModuleName: string; + public moduleName: string; public referencedFiles: FileReference[]; public syntacticDiagnostics: Diagnostic[]; @@ -1766,7 +1766,7 @@ module ts { * - isolatedModules = true * - allowNonTsExtensions = true */ - export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string { + export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[], moduleName?: string): string { let options = compilerOptions ? clone(compilerOptions) : getDefaultCompilerOptions(); options.isolatedModules = true; @@ -1777,6 +1777,9 @@ module ts { // Parse var inputFileName = fileName || "module.ts"; var sourceFile = createSourceFile(inputFileName, input, options.target); + if (moduleName) { + sourceFile.moduleName = moduleName; + } // Store syntactic diagnostics if (diagnostics && sourceFile.parseDiagnostics) { diff --git a/tests/baselines/reference/systemModule12.errors.txt b/tests/baselines/reference/systemModule12.errors.txt new file mode 100644 index 00000000000..5c89e2e65d6 --- /dev/null +++ b/tests/baselines/reference/systemModule12.errors.txt @@ -0,0 +1,10 @@ +tests/cases/compiler/systemModule12.ts(3,15): error TS2307: Cannot find module 'file1'. + + +==== tests/cases/compiler/systemModule12.ts (1 errors) ==== + + /// + import n from 'file1' + ~~~~~~~ +!!! error TS2307: Cannot find module 'file1'. + \ No newline at end of file diff --git a/tests/baselines/reference/systemModule12.js b/tests/baselines/reference/systemModule12.js new file mode 100644 index 00000000000..0b5f5a3e850 --- /dev/null +++ b/tests/baselines/reference/systemModule12.js @@ -0,0 +1,14 @@ +//// [systemModule12.ts] + +/// +import n from 'file1' + + +//// [systemModule12.js] +System.register("NamedModule", [], function(exports_1) { + return { + setters:[], + execute: function() { + } + } +}); diff --git a/tests/cases/compiler/systemModule12.ts b/tests/cases/compiler/systemModule12.ts new file mode 100644 index 00000000000..690fabc0a28 --- /dev/null +++ b/tests/cases/compiler/systemModule12.ts @@ -0,0 +1,5 @@ +// @module: system +// @isolatedModules: true + +/// +import n from 'file1' From 7ca13ee945ddf019bed048ab8cd81687e4746d74 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 3 Jun 2015 15:06:58 -0700 Subject: [PATCH 42/73] Check for 'any' only by using the flag, not by checking for instance equality. --- src/compiler/checker.ts | 158 +++++++++--------- .../reference/ArrowFunction3.errors.txt | 5 +- ...rsiveImplicitConstructorErrors3.errors.txt | 5 +- .../parserGenericsInTypeContexts1.errors.txt | 5 +- .../parserGenericsInTypeContexts2.errors.txt | 5 +- .../parserX_ArrowFunction3.errors.txt | 5 +- ...rUsedAsTypeParameterConstraint4.errors.txt | 14 +- .../reference/unknownSymbols1.errors.txt | 5 +- 8 files changed, 89 insertions(+), 113 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 903d5964a44..03a029d4b84 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1493,8 +1493,9 @@ module ts { // Write undefined/null type as any if (type.flags & TypeFlags.Intrinsic) { // Special handling for unknown / resolving types, they should show up as any and not unknown or __resolving - writer.writeKeyword(!(globalFlags & TypeFormatFlags.WriteOwnNameForAnyLike) && - (type.flags & TypeFlags.Any) ? "any" : (type).intrinsicName); + writer.writeKeyword(!(globalFlags & TypeFormatFlags.WriteOwnNameForAnyLike) && isTypeAny(type) + ? "any" + : (type).intrinsicName); } else if (type.flags & TypeFlags.Reference) { writeTypeReference(type, flags); @@ -2131,8 +2132,8 @@ module ts { return prop ? getTypeOfSymbol(prop) : undefined; } - function isTheAnyType(type: Type) { - return type === anyType; + function isTypeAny(type: Type) { + return type && type.flags & TypeFlags.Any; } // Return the inferred type for a binding element @@ -2146,7 +2147,7 @@ module 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 || isTheAnyType(parentType)) { + if (!parentType || isTypeAny(parentType)) { if (declaration.initializer) { return checkExpressionCached(declaration.initializer); } @@ -2173,7 +2174,7 @@ module ts { // fact an iterable or array (depending on target language). let elementType = checkIteratedTypeOrElementType(parentType, pattern, /*allowStringInput*/ false); if (!declaration.dotDotDotToken) { - if (elementType.flags & TypeFlags.Any) { + if (isTypeAny(elementType)) { return elementType; } @@ -3720,9 +3721,9 @@ module ts { } } - function containsAnyType(types: Type[]) { + function containsTypeAny(types: Type[]) { for (let type of types) { - if (type.flags & TypeFlags.Any) { + if (isTypeAny(type)) { return true; } } @@ -3750,7 +3751,7 @@ module ts { let sortedTypes: Type[] = []; addTypesToSortedSet(sortedTypes, types); if (noSubtypeReduction) { - if (containsAnyType(sortedTypes)) { + if (containsTypeAny(sortedTypes)) { return anyType; } removeAllButLast(sortedTypes, undefinedType); @@ -4186,13 +4187,13 @@ module ts { // both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases if (source === target) return Ternary.True; if (relation !== identityRelation) { - if (target.flags & TypeFlags.Any) return Ternary.True; + if (isTypeAny(target)) return Ternary.True; if (source === undefinedType) return Ternary.True; if (source === nullType && target !== undefinedType) return Ternary.True; if (source.flags & TypeFlags.Enum && target === numberType) return Ternary.True; if (source.flags & TypeFlags.StringLiteral && target === stringType) return Ternary.True; if (relation === assignableRelation) { - if (source.flags & TypeFlags.Any) return Ternary.True; + if (isTypeAny(source)) return Ternary.True; if (source === numberType && target.flags & TypeFlags.Enum) return Ternary.True; } } @@ -5537,7 +5538,7 @@ module ts { function narrowTypeByInstanceof(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { // Check that type is not any, assumed result is true, and we have variable symbol on the left - if (type.flags & TypeFlags.Any || !assumeTrue || expr.left.kind !== SyntaxKind.Identifier || getResolvedSymbol(expr.left) !== symbol) { + if (isTypeAny(type) || !assumeTrue || expr.left.kind !== SyntaxKind.Identifier || getResolvedSymbol(expr.left) !== symbol) { return type; } // Check that right operand is a function type with a prototype property @@ -5551,7 +5552,7 @@ module ts { if (prototypeProperty) { // Target type is type of the protoype property let prototypePropertyType = getTypeOfSymbol(prototypeProperty); - if (!isTheAnyType(prototypePropertyType)) { + if (!isTypeAny(prototypePropertyType)) { targetType = prototypePropertyType; } } @@ -6499,39 +6500,39 @@ module ts { function checkPropertyAccessExpressionOrQualifiedName(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, right: Identifier) { let type = checkExpressionOrQualifiedName(left); - if (type === unknownType) return type; - if (!isTheAnyType(type)) { - let apparentType = getApparentType(getWidenedType(type)); - if (apparentType === unknownType) { - // handle cases when type is Type parameter with invalid constraint - return unknownType; - } - let prop = getPropertyOfType(apparentType, right.text); - if (!prop) { - if (right.text) { - error(right, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(right), typeToString(type)); - } - return unknownType; - } - getNodeLinks(node).resolvedSymbol = prop; - if (prop.parent && prop.parent.flags & SymbolFlags.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 === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.MethodDeclaration) { - error(right, 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); + if (isTypeAny(type)) { + return type; } - return anyType; + + let apparentType = getApparentType(getWidenedType(type)); + if (apparentType === unknownType) { + // handle cases when type is Type parameter with invalid constraint + return unknownType; + } + let prop = getPropertyOfType(apparentType, right.text); + if (!prop) { + if (right.text) { + error(right, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(right), typeToString(type)); + } + return unknownType; + } + getNodeLinks(node).resolvedSymbol = prop; + if (prop.parent && prop.parent.flags & SymbolFlags.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 === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.MethodDeclaration) { + error(right, 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: PropertyAccessExpression | QualifiedName, propertyName: string): boolean { @@ -6540,7 +6541,7 @@ module ts { : (node).left; let type = checkExpressionOrQualifiedName(left); - if (type !== unknownType && !isTheAnyType(type)) { + if (type !== unknownType && !isTypeAny(type)) { let prop = getPropertyOfType(getWidenedType(type), propertyName); if (prop && prop.parent && prop.parent.flags & SymbolFlags.Class) { if (left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.MethodDeclaration) { @@ -6630,7 +6631,7 @@ module ts { } // Fall back to any. - if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && !isTheAnyType(objectType)) { + if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && !isTypeAny(objectType)) { error(node, Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type); } @@ -7280,8 +7281,10 @@ module 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 (isTheAnyType(funcType) || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) { - if (node.typeArguments) { + if (isTypeAny(funcType) || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & TypeFlags.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, Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } return resolveUntypedCall(node); @@ -7310,15 +7313,6 @@ module ts { } let 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 (isTheAnyType(expressionType)) { - if (node.typeArguments) { - error(node, 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 @@ -7331,6 +7325,16 @@ module ts { 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, 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 @@ -7368,7 +7372,7 @@ module ts { let callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call); - if (isTheAnyType(tagType) || (!callSignatures.length && !(tagType.flags & TypeFlags.Union) && isTypeAssignableTo(tagType, globalFunctionType))) { + if (isTypeAny(tagType) || (!callSignatures.length && !(tagType.flags & TypeFlags.Union) && isTypeAssignableTo(tagType, globalFunctionType))) { return resolveUntypedCall(node); } @@ -7580,7 +7584,7 @@ module ts { } // Functions that return 'void' or 'any' don't need any return expressions. - if (returnType === voidType || isTheAnyType(returnType)) { + if (returnType === voidType || isTypeAny(returnType)) { return; } @@ -7896,7 +7900,7 @@ module ts { error(node.left, 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 & TypeFlags.Any || isTypeSubtypeOf(rightType, globalFunctionType))) { + if (!(isTypeAny(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) { error(node.right, 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; @@ -7922,10 +7926,11 @@ module ts { if (p.kind === SyntaxKind.PropertyAssignment || p.kind === SyntaxKind.ShorthandPropertyAssignment) { // TODO(andersh): Computed property support let name = (p).name; - let type = sourceType.flags & TypeFlags.Any ? sourceType : - getTypeOfPropertyOfType(sourceType, name.text) || - isNumericLiteralName(name.text) && getIndexTypeOfType(sourceType, IndexKind.Number) || - getIndexTypeOfType(sourceType, IndexKind.String); + let type = isTypeAny(sourceType) + ? sourceType + : getTypeOfPropertyOfType(sourceType, name.text) || + isNumericLiteralName(name.text) && getIndexTypeOfType(sourceType, IndexKind.Number) || + getIndexTypeOfType(sourceType, IndexKind.String); if (type) { checkDestructuringAssignment((p).initializer || name, type); } @@ -7951,8 +7956,9 @@ module ts { if (e.kind !== SyntaxKind.OmittedExpression) { if (e.kind !== SyntaxKind.SpreadElementExpression) { let propName = "" + i; - let type = sourceType.flags & TypeFlags.Any ? sourceType : - isTupleLikeType(sourceType) + let type = isTypeAny(sourceType) + ? sourceType + : isTupleLikeType(sourceType) ? getTypeOfPropertyOfType(sourceType, propName) : elementType; if (type) { @@ -8091,10 +8097,10 @@ module 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 & TypeFlags.Any || rightType.flags & TypeFlags.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 @@ -9824,7 +9830,7 @@ module ts { } function checkIteratedTypeOrElementType(inputType: Type, errorNode: Node, allowStringInput: boolean): Type { - if (inputType.flags & TypeFlags.Any) { + if (isTypeAny(inputType)) { return inputType; } @@ -9883,7 +9889,7 @@ module ts { * whole pattern and that T (above) is 'any'. */ function getElementTypeOfIterable(type: Type, errorNode: Node): Type { - if (type.flags & TypeFlags.Any) { + if (isTypeAny(type)) { return undefined; } @@ -9896,7 +9902,7 @@ module ts { } else { let iteratorFunction = getTypeOfPropertyOfType(type, getPropertyNameForKnownSymbolName("iterator")); - if (iteratorFunction && iteratorFunction.flags & TypeFlags.Any) { + if (isTypeAny(iteratorFunction)) { return undefined; } @@ -9929,7 +9935,7 @@ module ts { * */ function getElementTypeOfIterator(type: Type, errorNode: Node): Type { - if (type.flags & TypeFlags.Any) { + if (isTypeAny(type)) { return undefined; } @@ -9942,7 +9948,7 @@ module ts { } else { let iteratorNextFunction = getTypeOfPropertyOfType(type, "next"); - if (iteratorNextFunction && iteratorNextFunction.flags & TypeFlags.Any) { + if (isTypeAny(iteratorNextFunction)) { return undefined; } @@ -9955,7 +9961,7 @@ module ts { } let iteratorNextResult = getUnionType(map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); - if (iteratorNextResult.flags & TypeFlags.Any) { + if (isTypeAny(iteratorNextResult)) { return undefined; } @@ -9975,7 +9981,7 @@ module ts { } function getElementTypeOfIterableIterator(type: Type): Type { - if (type.flags & TypeFlags.Any) { + if (isTypeAny(type)) { return undefined; } diff --git a/tests/baselines/reference/ArrowFunction3.errors.txt b/tests/baselines/reference/ArrowFunction3.errors.txt index b931fcb1cd8..aa5d1bfb725 100644 --- a/tests/baselines/reference/ArrowFunction3.errors.txt +++ b/tests/baselines/reference/ArrowFunction3.errors.txt @@ -1,11 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/ArrowFunction3.ts(1,13): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/ArrowFunction3.ts(1,14): error TS1110: Type expected. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/ArrowFunction3.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/ArrowFunction3.ts (1 errors) ==== var v = (a): => { - -!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. ~~ !!! error TS1110: Type expected. diff --git a/tests/baselines/reference/genericRecursiveImplicitConstructorErrors3.errors.txt b/tests/baselines/reference/genericRecursiveImplicitConstructorErrors3.errors.txt index 760d1561113..1a04e356296 100644 --- a/tests/baselines/reference/genericRecursiveImplicitConstructorErrors3.errors.txt +++ b/tests/baselines/reference/genericRecursiveImplicitConstructorErrors3.errors.txt @@ -1,5 +1,4 @@ tests/cases/compiler/genericRecursiveImplicitConstructorErrors3.ts(3,66): error TS2314: Generic type 'MemberName' requires 3 type argument(s). -tests/cases/compiler/genericRecursiveImplicitConstructorErrors3.ts(3,66): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. tests/cases/compiler/genericRecursiveImplicitConstructorErrors3.ts(10,22): error TS2314: Generic type 'PullTypeSymbol' requires 3 type argument(s). tests/cases/compiler/genericRecursiveImplicitConstructorErrors3.ts(12,48): error TS2314: Generic type 'PullSymbol' requires 3 type argument(s). tests/cases/compiler/genericRecursiveImplicitConstructorErrors3.ts(13,31): error TS2314: Generic type 'PullTypeSymbol' requires 3 type argument(s). @@ -8,14 +7,12 @@ tests/cases/compiler/genericRecursiveImplicitConstructorErrors3.ts(18,53): error tests/cases/compiler/genericRecursiveImplicitConstructorErrors3.ts(19,22): error TS2339: Property 'isArray' does not exist on type 'PullTypeSymbol'. -==== tests/cases/compiler/genericRecursiveImplicitConstructorErrors3.ts (8 errors) ==== +==== tests/cases/compiler/genericRecursiveImplicitConstructorErrors3.ts (7 errors) ==== module TypeScript { export class MemberName { static create(arg1: any, arg2?: any, arg3?: any): MemberName { ~~~~~~~~~~ !!! error TS2314: Generic type 'MemberName' requires 3 type argument(s). - ~~~~~~~~~~ -!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. } } } diff --git a/tests/baselines/reference/parserGenericsInTypeContexts1.errors.txt b/tests/baselines/reference/parserGenericsInTypeContexts1.errors.txt index 75652c829ee..477cc3edcdc 100644 --- a/tests/baselines/reference/parserGenericsInTypeContexts1.errors.txt +++ b/tests/baselines/reference/parserGenericsInTypeContexts1.errors.txt @@ -7,10 +7,9 @@ tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts1.ts(8,9): error TS2304: Cannot find name 'K'. tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts1.ts(11,16): error TS2304: Cannot find name 'E'. tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts1.ts(14,16): error TS2304: Cannot find name 'F'. -tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts1.ts(14,16): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. -==== tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts1.ts (10 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts1.ts (9 errors) ==== class C extends A implements B { ~ !!! error TS2304: Cannot find name 'A'. @@ -43,8 +42,6 @@ tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts function f2(): F { ~ !!! error TS2304: Cannot find name 'F'. - ~~~~ -!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. } \ No newline at end of file diff --git a/tests/baselines/reference/parserGenericsInTypeContexts2.errors.txt b/tests/baselines/reference/parserGenericsInTypeContexts2.errors.txt index c365f461b7c..f686b56bf89 100644 --- a/tests/baselines/reference/parserGenericsInTypeContexts2.errors.txt +++ b/tests/baselines/reference/parserGenericsInTypeContexts2.errors.txt @@ -7,10 +7,9 @@ tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts2.ts(8,9): error TS2304: Cannot find name 'K'. tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts2.ts(11,16): error TS2304: Cannot find name 'E'. tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts2.ts(14,16): error TS2304: Cannot find name 'F'. -tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts2.ts(14,16): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. -==== tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts2.ts (10 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts2.ts (9 errors) ==== class C extends A, Y>> implements B, Y>> { ~ !!! error TS2304: Cannot find name 'A'. @@ -43,8 +42,6 @@ tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts function f2(): F, Y>> { ~ !!! error TS2304: Cannot find name 'F'. - ~~~~~~~~~~~~~~~~ -!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. } \ No newline at end of file diff --git a/tests/baselines/reference/parserX_ArrowFunction3.errors.txt b/tests/baselines/reference/parserX_ArrowFunction3.errors.txt index 4ef812dc797..aa4a4c55a9f 100644 --- a/tests/baselines/reference/parserX_ArrowFunction3.errors.txt +++ b/tests/baselines/reference/parserX_ArrowFunction3.errors.txt @@ -1,11 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/parserX_ArrowFunction3.ts(1,13): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/parserX_ArrowFunction3.ts(1,14): error TS1110: Type expected. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/parserX_ArrowFunction3.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/parserX_ArrowFunction3.ts (1 errors) ==== var v = (a): => { - -!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. ~~ !!! error TS1110: Type expected. diff --git a/tests/baselines/reference/typeParameterUsedAsTypeParameterConstraint4.errors.txt b/tests/baselines/reference/typeParameterUsedAsTypeParameterConstraint4.errors.txt index 983f2798554..d86b63d2ce3 100644 --- a/tests/baselines/reference/typeParameterUsedAsTypeParameterConstraint4.errors.txt +++ b/tests/baselines/reference/typeParameterUsedAsTypeParameterConstraint4.errors.txt @@ -7,16 +7,12 @@ tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsed tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts(15,8): error TS2304: Cannot find name 'W'. tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts(19,17): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts(19,43): error TS2304: Cannot find name 'V'. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts(19,43): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts(20,47): error TS2304: Cannot find name 'X'. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts(20,47): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts(22,13): error TS2322: Type 'U' is not assignable to type 'T'. tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts(23,20): error TS2322: Type 'U' is not assignable to type 'T'. tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts(28,15): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts(28,44): error TS2304: Cannot find name 'W'. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts(28,44): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts(29,47): error TS2304: Cannot find name 'Y'. -tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts(29,47): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts(31,13): error TS2322: Type 'U' is not assignable to type 'T'. tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts(32,20): error TS2322: Type 'U' is not assignable to type 'T'. tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts(37,14): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. @@ -29,7 +25,7 @@ tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsed tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts(46,36): error TS2304: Cannot find name 'X'. -==== tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts (29 errors) ==== +==== tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts (25 errors) ==== // Type parameters are in scope in their own and other type parameter lists // Some negative cases @@ -67,13 +63,9 @@ tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsed !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. ~ !!! error TS2304: Cannot find name 'V'. - ~ -!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. function bar(): X { // error ~ !!! error TS2304: Cannot find name 'X'. - ~ -!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. function baz(a: X, b: Y): T { x = y; ~ @@ -90,13 +82,9 @@ tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsed !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. ~ !!! error TS2304: Cannot find name 'W'. - ~ -!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. function bar(): Y { // error ~ !!! error TS2304: Cannot find name 'Y'. - ~ -!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. function baz(a: X, b: Y): T { x = y; ~ diff --git a/tests/baselines/reference/unknownSymbols1.errors.txt b/tests/baselines/reference/unknownSymbols1.errors.txt index dcf6894f324..a757ab9613b 100644 --- a/tests/baselines/reference/unknownSymbols1.errors.txt +++ b/tests/baselines/reference/unknownSymbols1.errors.txt @@ -2,7 +2,6 @@ tests/cases/compiler/unknownSymbols1.ts(1,9): error TS2304: Cannot find name 'as tests/cases/compiler/unknownSymbols1.ts(2,8): error TS2304: Cannot find name 'asdf'. tests/cases/compiler/unknownSymbols1.ts(4,17): error TS2304: Cannot find name 'asdf'. tests/cases/compiler/unknownSymbols1.ts(4,35): error TS2304: Cannot find name 'asdf'. -tests/cases/compiler/unknownSymbols1.ts(4,35): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. tests/cases/compiler/unknownSymbols1.ts(6,12): error TS2304: Cannot find name 'asdf'. tests/cases/compiler/unknownSymbols1.ts(9,10): error TS2304: Cannot find name 'asdf'. tests/cases/compiler/unknownSymbols1.ts(12,10): error TS2304: Cannot find name 'asdf'. @@ -14,7 +13,7 @@ tests/cases/compiler/unknownSymbols1.ts(30,14): error TS2339: Property 'asdf' do tests/cases/compiler/unknownSymbols1.ts(30,21): error TS2304: Cannot find name 'asdf'. -==== tests/cases/compiler/unknownSymbols1.ts (14 errors) ==== +==== tests/cases/compiler/unknownSymbols1.ts (13 errors) ==== var x = asdf; ~~~~ !!! error TS2304: Cannot find name 'asdf'. @@ -27,8 +26,6 @@ tests/cases/compiler/unknownSymbols1.ts(30,21): error TS2304: Cannot find name ' !!! error TS2304: Cannot find name 'asdf'. ~~~~ !!! error TS2304: Cannot find name 'asdf'. - ~~~~ -!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. function foo2() { return asdf; ~~~~ From 7b17f6ec8c2a1a6a2a0bc1144318d714d814de9b Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 3 Jun 2015 15:16:16 -0700 Subject: [PATCH 43/73] Don't check if *all* constituent types are 'any'. Instead check if *any* of hte constituent types are 'any', or if *all* if the constituent types have some other flag. --- src/compiler/checker.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 03a029d4b84..389881f1b5e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2133,7 +2133,7 @@ module ts { } function isTypeAny(type: Type) { - return type && type.flags & TypeFlags.Any; + return type && (type.flags & TypeFlags.Any) !== 0; } // Return the inferred type for a binding element @@ -6313,7 +6313,11 @@ module ts { function isNumericComputedName(name: ComputedPropertyName): boolean { // 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), TypeFlags.Any | TypeFlags.NumberLike); + return isTypeAnyOrAllConstituentTypesHaveKind(checkComputedPropertyName(name), TypeFlags.NumberLike); + } + + function isTypeAnyOrAllConstituentTypesHaveKind(type: Type, kind: TypeFlags): boolean { + return isTypeAny(type) || allConstituentTypesHaveKind(type, kind); } function isNumericLiteralName(name: string) { @@ -6348,7 +6352,7 @@ module ts { // 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, TypeFlags.Any | TypeFlags.NumberLike | TypeFlags.StringLike | TypeFlags.ESSymbol)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(links.resolvedType, TypeFlags.NumberLike | TypeFlags.StringLike | TypeFlags.ESSymbol)) { error(node, Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any); } else { @@ -6614,10 +6618,10 @@ module ts { } // Check for compatible indexer types. - if (allConstituentTypesHaveKind(indexType, TypeFlags.Any | TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) { + if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) { // Try to use a number indexer. - if (allConstituentTypesHaveKind(indexType, TypeFlags.Any | TypeFlags.NumberLike)) { + if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.NumberLike)) { let numberIndexType = getIndexTypeOfType(objectType, IndexKind.Number); if (numberIndexType) { return numberIndexType; @@ -7688,7 +7692,7 @@ module ts { } function checkArithmeticOperandType(operand: Node, type: Type, diagnostic: DiagnosticMessage): boolean { - if (!allConstituentTypesHaveKind(type, TypeFlags.Any | TypeFlags.NumberLike)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(type, TypeFlags.NumberLike)) { error(operand, diagnostic); return false; } @@ -7911,10 +7915,10 @@ module 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, TypeFlags.Any | TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) { error(node.left, Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); } - if (!allConstituentTypesHaveKind(rightType, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, TypeFlags.ObjectType | TypeFlags.TypeParameter)) { error(node.right, Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; @@ -9796,7 +9800,7 @@ module ts { if (varExpr.kind === SyntaxKind.ArrayLiteralExpression || varExpr.kind === SyntaxKind.ObjectLiteralExpression) { error(varExpr, Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); } - else if (!allConstituentTypesHaveKind(leftType, TypeFlags.Any | TypeFlags.StringLike)) { + else if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, TypeFlags.StringLike)) { error(varExpr, Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any); } else { @@ -9808,7 +9812,7 @@ module ts { let 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, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, TypeFlags.ObjectType | TypeFlags.TypeParameter)) { error(node.expression, Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } From ef54047a65c963201d972bccec5d5e08d53f6091 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 3 Jun 2015 15:22:17 -0700 Subject: [PATCH 44/73] 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 12bea33fe37652b570ec9f245b7a019f88003370 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 3 Jun 2015 15:37:09 -0700 Subject: [PATCH 45/73] Remove last read reference of TypeFlags.Any --- src/compiler/checker.ts | 89 +++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 43 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 389881f1b5e..82c70861101 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5417,55 +5417,58 @@ module ts { function getNarrowedTypeOfSymbol(symbol: Symbol, node: Node) { let type = getTypeOfSymbol(symbol); // Only narrow when symbol is variable of type any or an object, union, or type parameter type - if (node && symbol.flags & SymbolFlags.Variable && type.flags & (TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.Union | TypeFlags.TypeParameter)) { - loop: while (node.parent) { - let child = node; - node = node.parent; - let narrowedType = type; - switch (node.kind) { - case SyntaxKind.IfStatement: - // In a branch of an if statement, narrow based on controlling expression - if (child !== (node).expression) { - narrowedType = narrowType(type, (node).expression, /*assumeTrue*/ child === (node).thenStatement); - } - break; - case SyntaxKind.ConditionalExpression: - // In a branch of a conditional expression, narrow based on controlling condition - if (child !== (node).condition) { - narrowedType = narrowType(type, (node).condition, /*assumeTrue*/ child === (node).whenTrue); - } - break; - case SyntaxKind.BinaryExpression: - // In the right operand of an && or ||, narrow based on left operand - if (child === (node).right) { - if ((node).operatorToken.kind === SyntaxKind.AmpersandAmpersandToken) { - narrowedType = narrowType(type, (node).left, /*assumeTrue*/ true); + if (node && symbol.flags & SymbolFlags.Variable) { + if (isTypeAny(type) || type.flags & (TypeFlags.ObjectType | TypeFlags.Union | TypeFlags.TypeParameter)) { + loop: while (node.parent) { + let child = node; + node = node.parent; + let narrowedType = type; + switch (node.kind) { + case SyntaxKind.IfStatement: + // In a branch of an if statement, narrow based on controlling expression + if (child !== (node).expression) { + narrowedType = narrowType(type, (node).expression, /*assumeTrue*/ child === (node).thenStatement); } - else if ((node).operatorToken.kind === SyntaxKind.BarBarToken) { - narrowedType = narrowType(type, (node).left, /*assumeTrue*/ false); + break; + case SyntaxKind.ConditionalExpression: + // In a branch of a conditional expression, narrow based on controlling condition + if (child !== (node).condition) { + narrowedType = narrowType(type, (node).condition, /*assumeTrue*/ child === (node).whenTrue); } - } - break; - case SyntaxKind.SourceFile: - case SyntaxKind.ModuleDeclaration: - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - case SyntaxKind.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 SyntaxKind.BinaryExpression: + // In the right operand of an && or ||, narrow based on left operand + if (child === (node).right) { + if ((node).operatorToken.kind === SyntaxKind.AmpersandAmpersandToken) { + narrowedType = narrowType(type, (node).left, /*assumeTrue*/ true); + } + else if ((node).operatorToken.kind === SyntaxKind.BarBarToken) { + narrowedType = narrowType(type, (node).left, /*assumeTrue*/ false); + } + } + break; + case SyntaxKind.SourceFile: + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.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; } } } + return type; function narrowTypeByEquality(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { From b5077bf3729c8d65c9f559c813860298899d82a2 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 3 Jun 2015 16:28:14 -0700 Subject: [PATCH 46/73] Remove HarnessDiagnostics. Just use the normal ts Diagnostic instead. --- src/harness/harness.ts | 99 +++++-------------- src/harness/projectsRunner.ts | 3 +- .../reference/contextualTyping.errors.txt | 10 +- .../reference/inlineSourceMap2.errors.txt | 8 +- .../reference/noDefaultLib.errors.txt | 4 +- .../reference/parser509698.errors.txt | 28 +++--- .../amd/invalidRootFile.errors.txt | 6 +- .../node/invalidRootFile.errors.txt | 6 +- ...SourceRootWithNoSourceMapOption.errors.txt | 4 +- ...SourceRootWithNoSourceMapOption.errors.txt | 4 +- .../noDefaultLib/amd/noDefaultLib.errors.txt | 28 +++--- .../noDefaultLib/node/noDefaultLib.errors.txt | 28 +++--- .../typeCheckTypeArgument.errors.txt | 20 ++-- tests/cases/compiler/contextualTyping.ts | 1 - 14 files changed, 103 insertions(+), 146 deletions(-) diff --git a/src/harness/harness.ts b/src/harness/harness.ts index b3791283a63..86cc255b063 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -899,7 +899,7 @@ module Harness { private compileOptions: ts.CompilerOptions; private settings: Harness.TestCaseParser.CompilerSetting[] = []; - private lastErrors: HarnessDiagnostic[]; + private lastErrors: ts.Diagnostic[]; public reset() { this.inputFiles = []; @@ -1078,10 +1078,6 @@ module Harness { } break; - case 'normalizenewline': - newLine = setting.value; - break; - case 'comments': options.removeComments = setting.value === 'false'; break; @@ -1144,11 +1140,7 @@ module Harness { var emitResult = program.emit(); - var errors: HarnessDiagnostic[] = []; - ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics).forEach(err => { - // TODO: new compiler formats errors after this point to add . and newlines so we'll just do it manually for now - errors.push(getMinimalDiagnostic(err)); - }); + var errors = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); this.lastErrors = errors; var result = new CompilerResult(fileOutputs, errors, program, ts.sys.getCurrentDirectory(), emitResult.sourceMaps); @@ -1235,70 +1227,50 @@ module Harness { return normalized; } - export function getMinimalDiagnostic(err: ts.Diagnostic): HarnessDiagnostic { - var errorLineInfo = err.file ? err.file.getLineAndCharacterOfPosition(err.start) : { line: -1, character: -1 }; - return { - fileName: err.file && err.file.fileName, - start: err.start, - end: err.start + err.length, - line: errorLineInfo.line + 1, - character: errorLineInfo.character + 1, - message: ts.flattenDiagnosticMessageText(err.messageText, ts.sys.newLine), - category: ts.DiagnosticCategory[err.category].toLowerCase(), - code: err.code - }; - } - - export function minimalDiagnosticsToString(diagnostics: HarnessDiagnostic[]) { + export function minimalDiagnosticsToString(diagnostics: ts.Diagnostic[]) { // This is basically copied from tsc.ts's reportError to replicate what tsc does var errorOutput = ""; - ts.forEach(diagnostics, diagnotic => { - if (diagnotic.fileName) { - errorOutput += diagnotic.fileName + "(" + diagnotic.line + "," + diagnotic.character + "): "; + ts.forEach(diagnostics, diagnostic => { + if (diagnostic.file) { + var lineAndCharacter = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); + errorOutput += diagnostic.file.fileName + "(" + (lineAndCharacter.line + 1) + "," + (lineAndCharacter.character + 1) + "): "; } - errorOutput += diagnotic.category + " TS" + diagnotic.code + ": " + diagnotic.message + ts.sys.newLine; + errorOutput += ts.DiagnosticCategory[diagnostic.category].toLowerCase() + " TS" + diagnostic.code + ": " + ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine) + ts.sys.newLine; }); return errorOutput; } - function compareDiagnostics(d1: HarnessDiagnostic, d2: HarnessDiagnostic) { - return ts.compareValues(d1.fileName, d2.fileName) || - ts.compareValues(d1.start, d2.start) || - ts.compareValues(d1.end, d2.end) || - ts.compareValues(d1.code, d2.code) || - ts.compareValues(d1.message, d2.message) || - 0; - } - - export function getErrorBaseline(inputFiles: { unitName: string; content: string }[], diagnostics: HarnessDiagnostic[]) { - diagnostics.sort(compareDiagnostics); + export function getErrorBaseline(inputFiles: { unitName: string; content: string }[], diagnostics: ts.Diagnostic[]) { + diagnostics.sort(ts.compareDiagnostics); var outputLines: string[] = []; // Count up all the errors we find so we don't miss any var totalErrorsReported = 0; - function outputErrorText(error: Harness.Compiler.HarnessDiagnostic) { - var errLines = RunnerBase.removeFullPaths(error.message) + function outputErrorText(error: ts.Diagnostic) { + var message = ts.flattenDiagnosticMessageText(error.messageText, ts.sys.newLine); + + var errLines = RunnerBase.removeFullPaths(message) .split('\n') .map(s => s.length > 0 && s.charAt(s.length - 1) === '\r' ? s.substr(0, s.length - 1) : s) .filter(s => s.length > 0) - .map(s => '!!! ' + error.category + " TS" + error.code + ": " + s); + .map(s => '!!! ' + ts.DiagnosticCategory[error.category].toLowerCase() + " TS" + error.code + ": " + s); errLines.forEach(e => outputLines.push(e)); totalErrorsReported++; } // Report global errors - var globalErrors = diagnostics.filter(err => !err.fileName); + var globalErrors = diagnostics.filter(err => !err.file); globalErrors.forEach(outputErrorText); // 'merge' the lines of each input file with any errors associated with it inputFiles.filter(f => f.content !== undefined).forEach(inputFile => { // Filter down to the errors in the file var fileErrors = diagnostics.filter(e => { - var errFn = e.fileName; - return errFn && errFn === inputFile.unitName; + var errFn = e.file; + return errFn && errFn.fileName === inputFile.unitName; }); @@ -1334,18 +1306,19 @@ module Harness { outputLines.push(' ' + line); fileErrors.forEach(err => { // Does any error start or continue on to this line? Emit squiggles - if ((err.end >= thisLineStart) && ((err.start < nextLineStart) || (lineIndex === lines.length - 1))) { + let end = ts.textSpanEnd(err); + if ((end >= thisLineStart) && ((err.start < nextLineStart) || (lineIndex === lines.length - 1))) { // How many characters from the start of this line the error starts at (could be positive or negative) var relativeOffset = err.start - thisLineStart; // How many characters of the error are on this line (might be longer than this line in reality) - var length = (err.end - err.start) - Math.max(0, thisLineStart - err.start); + var length = (end - err.start) - Math.max(0, thisLineStart - err.start); // Calculate the start of the squiggle var squiggleStart = Math.max(0, relativeOffset); // TODO/REVIEW: this doesn't work quite right in the browser if a multi file test has files whose names are just the right length relative to one another outputLines.push(' ' + line.substr(0, squiggleStart).replace(/[^\s]/g, ' ') + new Array(Math.min(length, line.length - squiggleStart) + 1).join('~')); // If the error ended here, or we're at the end of the file, emit its message - if ((lineIndex === lines.length - 1) || nextLineStart > err.end) { + if ((lineIndex === lines.length - 1) || nextLineStart > end) { // Just like above, we need to do a split on a string instead of on a regex // because the JS engine does regexes wrong @@ -1361,12 +1334,12 @@ module Harness { }); var numLibraryDiagnostics = ts.countWhere(diagnostics, diagnostic => { - return diagnostic.fileName && (isLibraryFile(diagnostic.fileName) || isBuiltFile(diagnostic.fileName)); + return diagnostic.file && (isLibraryFile(diagnostic.file.fileName) || isBuiltFile(diagnostic.file.fileName)); }); var numTest262HarnessDiagnostics = ts.countWhere(diagnostics, diagnostic => { // Count an error generated from tests262-harness folder.This should only apply for test262 - return diagnostic.fileName && diagnostic.fileName.indexOf("test262-harness") >= 0; + return diagnostic.file && diagnostic.file.fileName.indexOf("test262-harness") >= 0; }); // Verify we didn't miss any errors in total @@ -1419,17 +1392,6 @@ module Harness { //harnessCompiler.compileString(code, unitName, callback); } - export interface HarnessDiagnostic { - fileName: string; - start: number; - end: number; - line: number; - character: number; - message: string; - category: string; - code: number; - } - export interface GeneratedFile { fileName: string; code: string; @@ -1459,12 +1421,12 @@ module Harness { /** Contains the code and errors of a compilation and some helper methods to check its status. */ export class CompilerResult { public files: GeneratedFile[] = []; - public errors: HarnessDiagnostic[] = []; + public errors: ts.Diagnostic[] = []; public declFilesCode: GeneratedFile[] = []; public sourceMaps: GeneratedFile[] = []; /** @param fileResults an array of strings for the fileName and an ITextWriter with its code */ - constructor(fileResults: GeneratedFile[], errors: HarnessDiagnostic[], public program: ts.Program, + constructor(fileResults: GeneratedFile[], errors: ts.Diagnostic[], public program: ts.Program, public currentDirectoryForProgram: string, private sourceMapData: ts.SourceMapData[]) { fileResults.forEach(emittedFile => { @@ -1489,15 +1451,6 @@ module Harness { return Harness.SourceMapRecoder.getSourceMapRecord(this.sourceMapData, this.program, this.files); } } - - public isErrorAt(line: number, column: number, message: string) { - for (var i = 0; i < this.errors.length; i++) { - if ((this.errors[i].line + 1) === line && (this.errors[i].character + 1) === column && this.errors[i].message === message) - return true; - } - - return false; - } } } diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index 39221d55b29..324524272e0 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -323,9 +323,8 @@ class ProjectRunner extends RunnerBase { sourceFile => { return { unitName: sourceFile.fileName, content: sourceFile.text }; }); - var diagnostics = ts.map(compilerResult.errors, error => Harness.Compiler.getMinimalDiagnostic(error)); - return Harness.Compiler.getErrorBaseline(inputFiles, diagnostics); + return Harness.Compiler.getErrorBaseline(inputFiles, compilerResult.errors); } var name = 'Compiling project for ' + testCase.scenario + ': testcase ' + testCaseFileName; diff --git a/tests/baselines/reference/contextualTyping.errors.txt b/tests/baselines/reference/contextualTyping.errors.txt index f6941b7b92d..2e050777bfd 100644 --- a/tests/baselines/reference/contextualTyping.errors.txt +++ b/tests/baselines/reference/contextualTyping.errors.txt @@ -1,5 +1,11 @@ -tests/cases/compiler/contextualTyping.ts(189,18): error TS2384: Overload signatures must all be ambient or non-ambient.\ntests/cases/compiler/contextualTyping.ts(197,15): error TS2300: Duplicate identifier 'Point'.\ntests/cases/compiler/contextualTyping.ts(207,10): error TS2300: Duplicate identifier 'Point'.\ntests/cases/compiler/contextualTyping.ts(230,5): error TS2322: Type '{}' is not assignable to type 'B'. - Property 'x' is missing in type '{}'.\n\n\n==== tests/cases/compiler/contextualTyping.ts (4 errors) ==== +tests/cases/compiler/contextualTyping.ts(189,18): error TS2384: Overload signatures must all be ambient or non-ambient. +tests/cases/compiler/contextualTyping.ts(197,15): error TS2300: Duplicate identifier 'Point'. +tests/cases/compiler/contextualTyping.ts(207,10): error TS2300: Duplicate identifier 'Point'. +tests/cases/compiler/contextualTyping.ts(230,5): error TS2322: Type '{}' is not assignable to type 'B'. + Property 'x' is missing in type '{}'. + + +==== tests/cases/compiler/contextualTyping.ts (4 errors) ==== // DEFAULT INTERFACES interface IFoo { n: number; diff --git a/tests/baselines/reference/inlineSourceMap2.errors.txt b/tests/baselines/reference/inlineSourceMap2.errors.txt index 75db5689c66..2d8bc4be0c1 100644 --- a/tests/baselines/reference/inlineSourceMap2.errors.txt +++ b/tests/baselines/reference/inlineSourceMap2.errors.txt @@ -1,12 +1,12 @@ -error TS5050: Option 'mapRoot' cannot be specified with option 'inlineSourceMap'. -error TS5049: Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'. error TS5048: Option 'sourceMap' cannot be specified with option 'inlineSourceMap'. +error TS5049: Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'. +error TS5050: Option 'mapRoot' cannot be specified with option 'inlineSourceMap'. tests/cases/compiler/inlineSourceMap2.ts(5,1): error TS2304: Cannot find name 'console'. -!!! error TS5050: Option 'mapRoot' cannot be specified with option 'inlineSourceMap'. -!!! error TS5049: Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'. !!! error TS5048: Option 'sourceMap' cannot be specified with option 'inlineSourceMap'. +!!! error TS5049: Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'. +!!! error TS5050: Option 'mapRoot' cannot be specified with option 'inlineSourceMap'. ==== tests/cases/compiler/inlineSourceMap2.ts (1 errors) ==== // configuration errors diff --git a/tests/baselines/reference/noDefaultLib.errors.txt b/tests/baselines/reference/noDefaultLib.errors.txt index b8f42ba7c33..02098950055 100644 --- a/tests/baselines/reference/noDefaultLib.errors.txt +++ b/tests/baselines/reference/noDefaultLib.errors.txt @@ -1,10 +1,10 @@ -error TS2318: Cannot find global type 'IArguments'. error TS2318: Cannot find global type 'Boolean'. +error TS2318: Cannot find global type 'IArguments'. tests/cases/compiler/noDefaultLib.ts(4,11): error TS2317: Global type 'Array' must have 1 type parameter(s). -!!! error TS2318: Cannot find global type 'IArguments'. !!! error TS2318: Cannot find global type 'Boolean'. +!!! error TS2318: Cannot find global type 'IArguments'. ==== tests/cases/compiler/noDefaultLib.ts (1 errors) ==== /// var x; diff --git a/tests/baselines/reference/parser509698.errors.txt b/tests/baselines/reference/parser509698.errors.txt index 85485dd6501..2aaaec18dc2 100644 --- a/tests/baselines/reference/parser509698.errors.txt +++ b/tests/baselines/reference/parser509698.errors.txt @@ -1,21 +1,21 @@ -error TS2318: Cannot find global type 'String'. -error TS2318: Cannot find global type 'RegExp'. -error TS2318: Cannot find global type 'Object'. -error TS2318: Cannot find global type 'Number'. -error TS2318: Cannot find global type 'IArguments'. -error TS2318: Cannot find global type 'Function'. -error TS2318: Cannot find global type 'Boolean'. error TS2318: Cannot find global type 'Array'. +error TS2318: Cannot find global type 'Boolean'. +error TS2318: Cannot find global type 'Function'. +error TS2318: Cannot find global type 'IArguments'. +error TS2318: Cannot find global type 'Number'. +error TS2318: Cannot find global type 'Object'. +error TS2318: Cannot find global type 'RegExp'. +error TS2318: Cannot find global type 'String'. -!!! error TS2318: Cannot find global type 'String'. -!!! error TS2318: Cannot find global type 'RegExp'. -!!! error TS2318: Cannot find global type 'Object'. -!!! error TS2318: Cannot find global type 'Number'. -!!! error TS2318: Cannot find global type 'IArguments'. -!!! error TS2318: Cannot find global type 'Function'. -!!! error TS2318: Cannot find global type 'Boolean'. !!! error TS2318: Cannot find global type 'Array'. +!!! error TS2318: Cannot find global type 'Boolean'. +!!! error TS2318: Cannot find global type 'Function'. +!!! error TS2318: Cannot find global type 'IArguments'. +!!! error TS2318: Cannot find global type 'Number'. +!!! error TS2318: Cannot find global type 'Object'. +!!! error TS2318: Cannot find global type 'RegExp'. +!!! error TS2318: Cannot find global type 'String'. ==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509698.ts (0 errors) ==== ///