From 28938fbc303b2cb2c44b417f8939403b07faf91b Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 6 Jul 2016 11:44:51 -0700 Subject: [PATCH 01/28] Remove the unused text buffer from ScriptInfo --- src/server/editorServices.ts | 2 +- tests/cases/unittests/cachingInServerLSHost.ts | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 092450e526c..6a2beccc243 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -38,7 +38,7 @@ namespace ts.server { path: Path; scriptKind: ScriptKind; - constructor(private host: ServerHost, public fileName: string, public content: string, public isOpen = false) { + constructor(private host: ServerHost, public fileName: string, content: string, public isOpen = false) { this.path = toPath(fileName, host.getCurrentDirectory(), createGetCanonicalFileName(host.useCaseSensitiveFileNames)); this.svc = ScriptVersionCache.fromString(host, content); } diff --git a/tests/cases/unittests/cachingInServerLSHost.ts b/tests/cases/unittests/cachingInServerLSHost.ts index 2608a082d6d..9cd5e071b73 100644 --- a/tests/cases/unittests/cachingInServerLSHost.ts +++ b/tests/cases/unittests/cachingInServerLSHost.ts @@ -108,6 +108,8 @@ namespace ts { let diags = project.compilerService.languageService.getSemanticDiagnostics(imported.name); assert.equal(diags.length, 1); + let content = rootScriptInfo.getText(); + const originalFileExists = serverHost.fileExists; { // patch fileExists to make sure that disk is not touched @@ -118,7 +120,8 @@ namespace ts { const newContent = `import {x} from "f1" var x: string = 1;`; - rootScriptInfo.editContent(0, rootScriptInfo.content.length, newContent); + rootScriptInfo.editContent(0, content.length, newContent); + content = newContent; // trigger synchronization to make sure that import will be fetched from the cache diags = project.compilerService.languageService.getSemanticDiagnostics(imported.name); // ensure file has correct number of errors after edit @@ -135,7 +138,8 @@ namespace ts { return originalFileExists.call(serverHost, fileName); }; const newContent = `import {x} from "f2"`; - rootScriptInfo.editContent(0, rootScriptInfo.content.length, newContent); + rootScriptInfo.editContent(0, content.length, newContent); + content = newContent; try { // trigger synchronization to make sure that LSHost will try to find 'f2' module on disk @@ -160,7 +164,8 @@ namespace ts { }; const newContent = `import {x} from "f1"`; - rootScriptInfo.editContent(0, rootScriptInfo.content.length, newContent); + rootScriptInfo.editContent(0, content.length, newContent); + content = newContent; project.compilerService.languageService.getSemanticDiagnostics(imported.name); assert.isTrue(fileExistsCalled); @@ -205,7 +210,7 @@ namespace ts { }; const { project, rootScriptInfo } = createProject(root.name, serverHost); - + const content = rootScriptInfo.getText(); let diags = project.compilerService.languageService.getSemanticDiagnostics(root.name); assert.isTrue(fileExistsCalledForBar, "'fileExists' should be called"); assert.isTrue(diags.length === 1, "one diagnostic expected"); @@ -214,7 +219,7 @@ namespace ts { // assert that import will success once file appear on disk fileMap[imported.name] = imported; fileExistsCalledForBar = false; - rootScriptInfo.editContent(0, rootScriptInfo.content.length, `import {y} from "bar"`); + rootScriptInfo.editContent(0, content.length, `import {y} from "bar"`); diags = project.compilerService.languageService.getSemanticDiagnostics(root.name); assert.isTrue(fileExistsCalledForBar, "'fileExists' should be called"); From 78e9fe2838c3de234aeb08bca795e855ced668e8 Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Fri, 8 Jul 2016 01:08:49 +0900 Subject: [PATCH 02/28] Fix #9550: exclude 'this' type parameters from unusedParameters checks. --- src/compiler/checker.ts | 5 + .../reference/unusedParametersThis.js | 67 +++++++++++++ .../reference/unusedParametersThis.symbols | 93 ++++++++++++++++++ .../reference/unusedParametersThis.types | 98 +++++++++++++++++++ tests/cases/compiler/unusedParametersThis.ts | 37 +++++++ 5 files changed, 300 insertions(+) create mode 100644 tests/baselines/reference/unusedParametersThis.js create mode 100644 tests/baselines/reference/unusedParametersThis.symbols create mode 100644 tests/baselines/reference/unusedParametersThis.types create mode 100644 tests/cases/compiler/unusedParametersThis.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6427b05c37a..d6db67d3fa8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14563,6 +14563,7 @@ namespace ts { const parameter = local.valueDeclaration; if (compilerOptions.noUnusedParameters && !isParameterPropertyDeclaration(parameter) && + !parameterIsThisKeyword(parameter) && !parameterNameStartsWithUnderscore(parameter)) { error(local.valueDeclaration.name, Diagnostics._0_is_declared_but_never_used, local.name); } @@ -14576,6 +14577,10 @@ namespace ts { } } + function parameterIsThisKeyword(parameter: ParameterDeclaration) { + return parameter.name && (parameter.name).originalKeywordKind === SyntaxKind.ThisKeyword; + } + function parameterNameStartsWithUnderscore(parameter: ParameterDeclaration) { return parameter.name && parameter.name.kind === SyntaxKind.Identifier && (parameter.name).text.charCodeAt(0) === CharacterCodes._; } diff --git a/tests/baselines/reference/unusedParametersThis.js b/tests/baselines/reference/unusedParametersThis.js new file mode 100644 index 00000000000..8cf135bf71a --- /dev/null +++ b/tests/baselines/reference/unusedParametersThis.js @@ -0,0 +1,67 @@ +//// [unusedParametersThis.ts] + +class A { + public a: number; + + public method(this: this): number { + return this.a; + } + + public method2(this: A): number { + return this.a; + } + + public method3(this: this): number { + var fn = () => this.a; + return fn(); + } + + public method4(this: A): number { + var fn = () => this.a; + return fn(); + } + + static staticMethod(this: A): number { + return this.a; + } +} + +function f(this: A): number { + return this.a +} + +var f2 = function f2(this: A): number { + return this.a; +}; + +//// [unusedParametersThis.js] +var A = (function () { + function A() { + } + A.prototype.method = function () { + return this.a; + }; + A.prototype.method2 = function () { + return this.a; + }; + A.prototype.method3 = function () { + var _this = this; + var fn = function () { return _this.a; }; + return fn(); + }; + A.prototype.method4 = function () { + var _this = this; + var fn = function () { return _this.a; }; + return fn(); + }; + A.staticMethod = function () { + return this.a; + }; + return A; +}()); +function f() { + return this.a; +} +var f2 = function f2() { + return this.a; +}; diff --git a/tests/baselines/reference/unusedParametersThis.symbols b/tests/baselines/reference/unusedParametersThis.symbols new file mode 100644 index 00000000000..58f8856c281 --- /dev/null +++ b/tests/baselines/reference/unusedParametersThis.symbols @@ -0,0 +1,93 @@ +=== tests/cases/compiler/unusedParametersThis.ts === + +class A { +>A : Symbol(A, Decl(unusedParametersThis.ts, 0, 0)) + + public a: number; +>a : Symbol(A.a, Decl(unusedParametersThis.ts, 1, 9)) + + public method(this: this): number { +>method : Symbol(A.method, Decl(unusedParametersThis.ts, 2, 21)) +>this : Symbol(this, Decl(unusedParametersThis.ts, 4, 18)) + + return this.a; +>this.a : Symbol(A.a, Decl(unusedParametersThis.ts, 1, 9)) +>this : Symbol(this, Decl(unusedParametersThis.ts, 4, 18)) +>a : Symbol(A.a, Decl(unusedParametersThis.ts, 1, 9)) + } + + public method2(this: A): number { +>method2 : Symbol(A.method2, Decl(unusedParametersThis.ts, 6, 5)) +>this : Symbol(this, Decl(unusedParametersThis.ts, 8, 19)) +>A : Symbol(A, Decl(unusedParametersThis.ts, 0, 0)) + + return this.a; +>this.a : Symbol(A.a, Decl(unusedParametersThis.ts, 1, 9)) +>this : Symbol(this, Decl(unusedParametersThis.ts, 8, 19)) +>a : Symbol(A.a, Decl(unusedParametersThis.ts, 1, 9)) + } + + public method3(this: this): number { +>method3 : Symbol(A.method3, Decl(unusedParametersThis.ts, 10, 5)) +>this : Symbol(this, Decl(unusedParametersThis.ts, 12, 19)) + + var fn = () => this.a; +>fn : Symbol(fn, Decl(unusedParametersThis.ts, 13, 11)) +>this.a : Symbol(A.a, Decl(unusedParametersThis.ts, 1, 9)) +>this : Symbol(this, Decl(unusedParametersThis.ts, 12, 19)) +>a : Symbol(A.a, Decl(unusedParametersThis.ts, 1, 9)) + + return fn(); +>fn : Symbol(fn, Decl(unusedParametersThis.ts, 13, 11)) + } + + public method4(this: A): number { +>method4 : Symbol(A.method4, Decl(unusedParametersThis.ts, 15, 5)) +>this : Symbol(this, Decl(unusedParametersThis.ts, 17, 19)) +>A : Symbol(A, Decl(unusedParametersThis.ts, 0, 0)) + + var fn = () => this.a; +>fn : Symbol(fn, Decl(unusedParametersThis.ts, 18, 11)) +>this.a : Symbol(A.a, Decl(unusedParametersThis.ts, 1, 9)) +>this : Symbol(this, Decl(unusedParametersThis.ts, 17, 19)) +>a : Symbol(A.a, Decl(unusedParametersThis.ts, 1, 9)) + + return fn(); +>fn : Symbol(fn, Decl(unusedParametersThis.ts, 18, 11)) + } + + static staticMethod(this: A): number { +>staticMethod : Symbol(A.staticMethod, Decl(unusedParametersThis.ts, 20, 5)) +>this : Symbol(this, Decl(unusedParametersThis.ts, 22, 24)) +>A : Symbol(A, Decl(unusedParametersThis.ts, 0, 0)) + + return this.a; +>this.a : Symbol(A.a, Decl(unusedParametersThis.ts, 1, 9)) +>this : Symbol(this, Decl(unusedParametersThis.ts, 22, 24)) +>a : Symbol(A.a, Decl(unusedParametersThis.ts, 1, 9)) + } +} + +function f(this: A): number { +>f : Symbol(f, Decl(unusedParametersThis.ts, 25, 1)) +>this : Symbol(this, Decl(unusedParametersThis.ts, 27, 11)) +>A : Symbol(A, Decl(unusedParametersThis.ts, 0, 0)) + + return this.a +>this.a : Symbol(A.a, Decl(unusedParametersThis.ts, 1, 9)) +>this : Symbol(this, Decl(unusedParametersThis.ts, 27, 11)) +>a : Symbol(A.a, Decl(unusedParametersThis.ts, 1, 9)) +} + +var f2 = function f2(this: A): number { +>f2 : Symbol(f2, Decl(unusedParametersThis.ts, 31, 3)) +>f2 : Symbol(f2, Decl(unusedParametersThis.ts, 31, 8)) +>this : Symbol(this, Decl(unusedParametersThis.ts, 31, 21)) +>A : Symbol(A, Decl(unusedParametersThis.ts, 0, 0)) + + return this.a; +>this.a : Symbol(A.a, Decl(unusedParametersThis.ts, 1, 9)) +>this : Symbol(this, Decl(unusedParametersThis.ts, 31, 21)) +>a : Symbol(A.a, Decl(unusedParametersThis.ts, 1, 9)) + +}; diff --git a/tests/baselines/reference/unusedParametersThis.types b/tests/baselines/reference/unusedParametersThis.types new file mode 100644 index 00000000000..814f56be101 --- /dev/null +++ b/tests/baselines/reference/unusedParametersThis.types @@ -0,0 +1,98 @@ +=== tests/cases/compiler/unusedParametersThis.ts === + +class A { +>A : A + + public a: number; +>a : number + + public method(this: this): number { +>method : (this: this) => number +>this : this + + return this.a; +>this.a : number +>this : this +>a : number + } + + public method2(this: A): number { +>method2 : (this: A) => number +>this : A +>A : A + + return this.a; +>this.a : number +>this : A +>a : number + } + + public method3(this: this): number { +>method3 : (this: this) => number +>this : this + + var fn = () => this.a; +>fn : () => number +>() => this.a : () => number +>this.a : number +>this : this +>a : number + + return fn(); +>fn() : number +>fn : () => number + } + + public method4(this: A): number { +>method4 : (this: A) => number +>this : A +>A : A + + var fn = () => this.a; +>fn : () => number +>() => this.a : () => number +>this.a : number +>this : A +>a : number + + return fn(); +>fn() : number +>fn : () => number + } + + static staticMethod(this: A): number { +>staticMethod : (this: A) => number +>this : A +>A : A + + return this.a; +>this.a : number +>this : A +>a : number + } +} + +function f(this: A): number { +>f : (this: A) => number +>this : A +>A : A + + return this.a +>this.a : number +>this : A +>a : number +} + +var f2 = function f2(this: A): number { +>f2 : (this: A) => number +>function f2(this: A): number { return this.a;} : (this: A) => number +>f2 : (this: A) => number +>this : A +>A : A + + return this.a; +>this.a : number +>this : A +>a : number + +}; diff --git a/tests/cases/compiler/unusedParametersThis.ts b/tests/cases/compiler/unusedParametersThis.ts new file mode 100644 index 00000000000..800229fcdbc --- /dev/null +++ b/tests/cases/compiler/unusedParametersThis.ts @@ -0,0 +1,37 @@ +//@noImplicitThis:true +//@noUnusedLocals:true +//@noUnusedParameters:true + +class A { + public a: number; + + public method(this: this): number { + return this.a; + } + + public method2(this: A): number { + return this.a; + } + + public method3(this: this): number { + var fn = () => this.a; + return fn(); + } + + public method4(this: A): number { + var fn = () => this.a; + return fn(); + } + + static staticMethod(this: A): number { + return this.a; + } +} + +function f(this: A): number { + return this.a +} + +var f2 = function f2(this: A): number { + return this.a; +}; \ No newline at end of file From 599b9b0e66d250894d8dabde391bfb9554936b8d Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 7 Jul 2016 12:02:47 -0700 Subject: [PATCH 03/28] Update LKG --- lib/tsc.js | 7 ++++++- lib/tsserver.js | 8 ++++++-- lib/tsserverlibrary.d.ts | 1 - lib/tsserverlibrary.js | 8 ++++++-- lib/typescript.js | 7 ++++++- lib/typescriptServices.js | 7 ++++++- 6 files changed, 30 insertions(+), 8 deletions(-) diff --git a/lib/tsc.js b/lib/tsc.js index 78f4fc3884b..69b9ab5e477 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -7235,7 +7235,8 @@ var ts; } function nextTokenIsClassOrFunctionOrAsync() { nextToken(); - return token === 73 || token === 87 || token === 118; + return token === 73 || token === 87 || + (token === 118 && lookAhead(nextTokenIsFunctionKeywordOnSameLine)); } function isListElement(parsingContext, inErrorRecovery) { var node = currentNode(parsingContext); @@ -24050,6 +24051,7 @@ var ts; var parameter = local_1.valueDeclaration; if (compilerOptions.noUnusedParameters && !ts.isParameterPropertyDeclaration(parameter) && + !parameterIsThisKeyword(parameter) && !parameterNameStartsWithUnderscore(parameter)) { error(local_1.valueDeclaration.name, ts.Diagnostics._0_is_declared_but_never_used, local_1.name); } @@ -24065,6 +24067,9 @@ var ts; } } } + function parameterIsThisKeyword(parameter) { + return parameter.name && parameter.name.originalKeywordKind === 97; + } function parameterNameStartsWithUnderscore(parameter) { return parameter.name && parameter.name.kind === 69 && parameter.name.text.charCodeAt(0) === 95; } diff --git a/lib/tsserver.js b/lib/tsserver.js index 1d0fbd864fa..2a22388b2be 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -8153,7 +8153,8 @@ var ts; } function nextTokenIsClassOrFunctionOrAsync() { nextToken(); - return token === 73 || token === 87 || token === 118; + return token === 73 || token === 87 || + (token === 118 && lookAhead(nextTokenIsFunctionKeywordOnSameLine)); } function isListElement(parsingContext, inErrorRecovery) { var node = currentNode(parsingContext); @@ -24968,6 +24969,7 @@ var ts; var parameter = local_1.valueDeclaration; if (compilerOptions.noUnusedParameters && !ts.isParameterPropertyDeclaration(parameter) && + !parameterIsThisKeyword(parameter) && !parameterNameStartsWithUnderscore(parameter)) { error(local_1.valueDeclaration.name, ts.Diagnostics._0_is_declared_but_never_used, local_1.name); } @@ -24983,6 +24985,9 @@ var ts; } } } + function parameterIsThisKeyword(parameter) { + return parameter.name && parameter.name.originalKeywordKind === 97; + } function parameterNameStartsWithUnderscore(parameter) { return parameter.name && parameter.name.kind === 69 && parameter.name.text.charCodeAt(0) === 95; } @@ -50792,7 +50797,6 @@ var ts; if (isOpen === void 0) { isOpen = false; } this.host = host; this.fileName = fileName; - this.content = content; this.isOpen = isOpen; this.children = []; this.formatCodeOptions = ts.clone(CompilerService.getDefaultFormatCodeOptions(this.host)); diff --git a/lib/tsserverlibrary.d.ts b/lib/tsserverlibrary.d.ts index 2c9fffcfcfb..df3e95e0788 100644 --- a/lib/tsserverlibrary.d.ts +++ b/lib/tsserverlibrary.d.ts @@ -8388,7 +8388,6 @@ declare namespace ts.server { class ScriptInfo { private host; fileName: string; - content: string; isOpen: boolean; svc: ScriptVersionCache; children: ScriptInfo[]; diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index f92b06a1d73..d60d00e66b9 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -8153,7 +8153,8 @@ var ts; } function nextTokenIsClassOrFunctionOrAsync() { nextToken(); - return token === 73 || token === 87 || token === 118; + return token === 73 || token === 87 || + (token === 118 && lookAhead(nextTokenIsFunctionKeywordOnSameLine)); } function isListElement(parsingContext, inErrorRecovery) { var node = currentNode(parsingContext); @@ -24968,6 +24969,7 @@ var ts; var parameter = local_1.valueDeclaration; if (compilerOptions.noUnusedParameters && !ts.isParameterPropertyDeclaration(parameter) && + !parameterIsThisKeyword(parameter) && !parameterNameStartsWithUnderscore(parameter)) { error(local_1.valueDeclaration.name, ts.Diagnostics._0_is_declared_but_never_used, local_1.name); } @@ -24983,6 +24985,9 @@ var ts; } } } + function parameterIsThisKeyword(parameter) { + return parameter.name && parameter.name.originalKeywordKind === 97; + } function parameterNameStartsWithUnderscore(parameter) { return parameter.name && parameter.name.kind === 69 && parameter.name.text.charCodeAt(0) === 95; } @@ -50792,7 +50797,6 @@ var ts; if (isOpen === void 0) { isOpen = false; } this.host = host; this.fileName = fileName; - this.content = content; this.isOpen = isOpen; this.children = []; this.formatCodeOptions = ts.clone(CompilerService.getDefaultFormatCodeOptions(this.host)); diff --git a/lib/typescript.js b/lib/typescript.js index 58376b5ec95..5d8cc8951a0 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -8988,7 +8988,8 @@ var ts; } function nextTokenIsClassOrFunctionOrAsync() { nextToken(); - return token === 73 /* ClassKeyword */ || token === 87 /* FunctionKeyword */ || token === 118 /* AsyncKeyword */; + return token === 73 /* ClassKeyword */ || token === 87 /* FunctionKeyword */ || + (token === 118 /* AsyncKeyword */ && lookAhead(nextTokenIsFunctionKeywordOnSameLine)); } // True if positioned at the start of a list element function isListElement(parsingContext, inErrorRecovery) { @@ -29340,6 +29341,7 @@ var ts; var parameter = local_1.valueDeclaration; if (compilerOptions.noUnusedParameters && !ts.isParameterPropertyDeclaration(parameter) && + !parameterIsThisKeyword(parameter) && !parameterNameStartsWithUnderscore(parameter)) { error(local_1.valueDeclaration.name, ts.Diagnostics._0_is_declared_but_never_used, local_1.name); } @@ -29355,6 +29357,9 @@ var ts; } } } + function parameterIsThisKeyword(parameter) { + return parameter.name && parameter.name.originalKeywordKind === 97 /* ThisKeyword */; + } function parameterNameStartsWithUnderscore(parameter) { return parameter.name && parameter.name.kind === 69 /* Identifier */ && parameter.name.text.charCodeAt(0) === 95 /* _ */; } diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 58376b5ec95..5d8cc8951a0 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -8988,7 +8988,8 @@ var ts; } function nextTokenIsClassOrFunctionOrAsync() { nextToken(); - return token === 73 /* ClassKeyword */ || token === 87 /* FunctionKeyword */ || token === 118 /* AsyncKeyword */; + return token === 73 /* ClassKeyword */ || token === 87 /* FunctionKeyword */ || + (token === 118 /* AsyncKeyword */ && lookAhead(nextTokenIsFunctionKeywordOnSameLine)); } // True if positioned at the start of a list element function isListElement(parsingContext, inErrorRecovery) { @@ -29340,6 +29341,7 @@ var ts; var parameter = local_1.valueDeclaration; if (compilerOptions.noUnusedParameters && !ts.isParameterPropertyDeclaration(parameter) && + !parameterIsThisKeyword(parameter) && !parameterNameStartsWithUnderscore(parameter)) { error(local_1.valueDeclaration.name, ts.Diagnostics._0_is_declared_but_never_used, local_1.name); } @@ -29355,6 +29357,9 @@ var ts; } } } + function parameterIsThisKeyword(parameter) { + return parameter.name && parameter.name.originalKeywordKind === 97 /* ThisKeyword */; + } function parameterNameStartsWithUnderscore(parameter) { return parameter.name && parameter.name.kind === 69 /* Identifier */ && parameter.name.text.charCodeAt(0) === 95 /* _ */; } From bab06f119385fe6cb3fb757e149b93290842d64a Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 7 Jul 2016 16:10:20 -0700 Subject: [PATCH 04/28] Parse the result of getDirectories call --- src/services/shims.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/shims.ts b/src/services/shims.ts index a233f99d03f..e8b9b59b3cd 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -61,7 +61,7 @@ namespace ts { getLocalizedDiagnosticMessages(): string; getCancellationToken(): HostCancellationToken; getCurrentDirectory(): string; - getDirectories(path: string): string[]; + getDirectories(path: string): string; getDefaultLibFileName(options: string): string; getNewLine?(): string; getProjectVersion?(): string; @@ -404,7 +404,7 @@ namespace ts { } public getDirectories(path: string): string[] { - return this.shimHost.getDirectories(path); + return JSON.parse(this.shimHost.getDirectories(path)); } public getDefaultLibFileName(options: CompilerOptions): string { From 028e2024e91007b9617e4d7d6219516eb08e7152 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 7 Jul 2016 16:26:19 -0700 Subject: [PATCH 05/28] Update LKG --- lib/tsserver.js | 2 +- lib/tsserverlibrary.d.ts | 2 +- lib/tsserverlibrary.js | 2 +- lib/typescript.js | 2 +- lib/typescriptServices.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/tsserver.js b/lib/tsserver.js index 2a22388b2be..68bceb54bb9 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -53200,7 +53200,7 @@ var ts; return this.shimHost.getCurrentDirectory(); }; LanguageServiceShimHostAdapter.prototype.getDirectories = function (path) { - return this.shimHost.getDirectories(path); + return JSON.parse(this.shimHost.getDirectories(path)); }; LanguageServiceShimHostAdapter.prototype.getDefaultLibFileName = function (options) { return this.shimHost.getDefaultLibFileName(JSON.stringify(options)); diff --git a/lib/tsserverlibrary.d.ts b/lib/tsserverlibrary.d.ts index df3e95e0788..1e0cefac78b 100644 --- a/lib/tsserverlibrary.d.ts +++ b/lib/tsserverlibrary.d.ts @@ -8728,7 +8728,7 @@ declare namespace ts { getLocalizedDiagnosticMessages(): string; getCancellationToken(): HostCancellationToken; getCurrentDirectory(): string; - getDirectories(path: string): string[]; + getDirectories(path: string): string; getDefaultLibFileName(options: string): string; getNewLine?(): string; getProjectVersion?(): string; diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index d60d00e66b9..f0bfd0f4f3e 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -52966,7 +52966,7 @@ var ts; return this.shimHost.getCurrentDirectory(); }; LanguageServiceShimHostAdapter.prototype.getDirectories = function (path) { - return this.shimHost.getDirectories(path); + return JSON.parse(this.shimHost.getDirectories(path)); }; LanguageServiceShimHostAdapter.prototype.getDefaultLibFileName = function (options) { return this.shimHost.getDefaultLibFileName(JSON.stringify(options)); diff --git a/lib/typescript.js b/lib/typescript.js index 5d8cc8951a0..3b28d8f0e67 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -59705,7 +59705,7 @@ var ts; return this.shimHost.getCurrentDirectory(); }; LanguageServiceShimHostAdapter.prototype.getDirectories = function (path) { - return this.shimHost.getDirectories(path); + return JSON.parse(this.shimHost.getDirectories(path)); }; LanguageServiceShimHostAdapter.prototype.getDefaultLibFileName = function (options) { return this.shimHost.getDefaultLibFileName(JSON.stringify(options)); diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 5d8cc8951a0..3b28d8f0e67 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -59705,7 +59705,7 @@ var ts; return this.shimHost.getCurrentDirectory(); }; LanguageServiceShimHostAdapter.prototype.getDirectories = function (path) { - return this.shimHost.getDirectories(path); + return JSON.parse(this.shimHost.getDirectories(path)); }; LanguageServiceShimHostAdapter.prototype.getDefaultLibFileName = function (options) { return this.shimHost.getDefaultLibFileName(JSON.stringify(options)); From 87e95069fc6a5a46804f7328a8ef0d180e17734a Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 7 Jul 2016 16:46:49 -0700 Subject: [PATCH 06/28] Update harness getDirectories implementation for shims --- src/harness/harnessLanguageService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index b40cbde73e7..d7ed04b627f 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -274,7 +274,7 @@ namespace Harness.LanguageService { getCompilationSettings(): string { return JSON.stringify(this.nativeHost.getCompilationSettings()); } getCancellationToken(): ts.HostCancellationToken { return this.nativeHost.getCancellationToken(); } getCurrentDirectory(): string { return this.nativeHost.getCurrentDirectory(); } - getDirectories(path: string) { return this.nativeHost.getDirectories(path); } + getDirectories(path: string): string { return JSON.stringify(this.nativeHost.getDirectories(path)); } getDefaultLibFileName(): string { return this.nativeHost.getDefaultLibFileName(); } getScriptFileNames(): string { return JSON.stringify(this.nativeHost.getScriptFileNames()); } getScriptSnapshot(fileName: string): ts.ScriptSnapshotShim { From b360ad5f3c8db53f397943999200cc39fcb993dd Mon Sep 17 00:00:00 2001 From: Bill Ticehurst Date: Sun, 10 Jul 2016 16:11:42 -0700 Subject: [PATCH 07/28] Fix module tracking (cherry picked from commit ca874bdd17c0c5e5e8b70c0db7bb847e2711b8f3) --- src/compiler/program.ts | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 2e4492efa7b..5d636847045 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1095,13 +1095,13 @@ namespace ts { // As all these operations happen - and are nested - within the createProgram call, they close over the below variables. // The current resolution depth is tracked by incrementing/decrementing as the depth first search progresses. const maxNodeModulesJsDepth = typeof options.maxNodeModuleJsDepth === "number" ? options.maxNodeModuleJsDepth : 2; - let currentNodeModulesJsDepth = 0; + let currentNodeModulesDepth = 0; // If a module has some of its imports skipped due to being at the depth limit under node_modules, then track // this, as it may be imported at a shallower depth later, and then it will need its skipped imports processed. const modulesWithElidedImports: Map = {}; - // Track source files that are JavaScript files found by searching under node_modules, as these shouldn't be compiled. + // Track source files that are source files found by searching under node_modules, as these shouldn't be compiled. const sourceFilesFoundSearchingNodeModules: Map = {}; const start = new Date().getTime(); @@ -1918,9 +1918,20 @@ namespace ts { reportFileNamesDifferOnlyInCasingError(fileName, file.fileName, refFile, refPos, refEnd); } + // If the file was previously found via a node_modules search, but is now being processed as a root file, + // then everything it sucks in may also be marked incorrectly, and needs to be checked again. + if (file && lookUp(sourceFilesFoundSearchingNodeModules, file.path) && currentNodeModulesDepth == 0) { + if (!options.noResolve) { + processReferencedFiles(file, getDirectoryPath(fileName), isDefaultLib); + processTypeReferenceDirectives(file); + } + + modulesWithElidedImports[file.path] = false; + processImportedModules(file, getDirectoryPath(fileName)); + } // See if we need to reprocess the imports due to prior skipped imports - if (file && lookUp(modulesWithElidedImports, file.path)) { - if (currentNodeModulesJsDepth < maxNodeModulesJsDepth) { + else if (file && lookUp(modulesWithElidedImports, file.path)) { + if (currentNodeModulesDepth < maxNodeModulesJsDepth) { modulesWithElidedImports[file.path] = false; processImportedModules(file, getDirectoryPath(fileName)); } @@ -2075,13 +2086,17 @@ namespace ts { const isJsFileFromNodeModules = isFromNodeModulesSearch && hasJavaScriptFileExtension(resolution.resolvedFileName); if (isFromNodeModulesSearch) { - sourceFilesFoundSearchingNodeModules[resolvedPath] = true; - } - if (isJsFileFromNodeModules) { - currentNodeModulesJsDepth++; + currentNodeModulesDepth++; } - const elideImport = isJsFileFromNodeModules && currentNodeModulesJsDepth > maxNodeModulesJsDepth; + if (currentNodeModulesDepth > 0) { + // If its already present with false, its a root file also. Don't override this. + if (!hasProperty(sourceFilesFoundSearchingNodeModules, resolvedPath)) { + sourceFilesFoundSearchingNodeModules[resolvedPath] = true; + } + } + + const elideImport = isJsFileFromNodeModules && currentNodeModulesDepth > maxNodeModulesJsDepth; const shouldAddFile = resolution && !options.noResolve && i < file.imports.length && !elideImport; if (elideImport) { @@ -2096,8 +2111,8 @@ namespace ts { file.imports[i].end); } - if (isJsFileFromNodeModules) { - currentNodeModulesJsDepth--; + if (isFromNodeModulesSearch) { + currentNodeModulesDepth--; } } } From ab45a56eda597aea72d0f3ec92b6d812e2cf714f Mon Sep 17 00:00:00 2001 From: Bill Ticehurst Date: Sun, 10 Jul 2016 16:38:21 -0700 Subject: [PATCH 08/28] Updated test with relative import (cherry picked from commit db54bda17b86e3a81f2d45e57e4fca732d66725b) --- .../amd/maxDepthExceeded/root.js | 1 + .../amd/nodeModulesMaxDepthExceeded.errors.txt | 13 ++++++++++++- .../amd/nodeModulesMaxDepthExceeded.json | 1 + .../node/maxDepthExceeded/root.js | 1 + .../node/nodeModulesMaxDepthExceeded.errors.txt | 13 ++++++++++++- .../node/nodeModulesMaxDepthExceeded.json | 1 + .../maxDepthExceeded/node_modules/m1/index.js | 3 +++ .../maxDepthExceeded/node_modules/m1/relative.js | 1 + .../NodeModulesSearch/maxDepthExceeded/root.ts | 2 ++ 9 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 tests/cases/projects/NodeModulesSearch/maxDepthExceeded/node_modules/m1/relative.js diff --git a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/maxDepthExceeded/root.js b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/maxDepthExceeded/root.js index 73cef6fc02c..5a3916f07d1 100644 --- a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/maxDepthExceeded/root.js +++ b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/maxDepthExceeded/root.js @@ -2,5 +2,6 @@ define(["require", "exports", "m1"], function (require, exports, m1) { "use strict"; m1.f1("test"); m1.f2.a = "10"; // Error: Should be number + m1.rel = 42; // Error: Should be boolean m1.f2.person.age = "10"; // OK if stopped at 2 modules: person will be "any". }); diff --git a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.errors.txt b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.errors.txt index f03b958275b..52c3611ceda 100644 --- a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.errors.txt +++ b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.errors.txt @@ -1,4 +1,5 @@ maxDepthExceeded/root.ts(3,1): error TS2322: Type 'string' is not assignable to type 'number'. +maxDepthExceeded/root.ts(4,1): error TS2322: Type 'number' is not assignable to type 'boolean'. ==== entry.js (0 errors) ==== @@ -10,8 +11,12 @@ maxDepthExceeded/root.ts(3,1): error TS2322: Type 'string' is not assignable to "person": m3.person }; +==== relative.js (0 errors) ==== + exports.relativeProp = true; + ==== index.js (0 errors) ==== var m2 = require('m2'); + var rel = require('./relative'); /** * @param {string} p1 The first param @@ -22,11 +27,17 @@ maxDepthExceeded/root.ts(3,1): error TS2322: Type 'string' is not assignable to exports.f2 = m2; -==== maxDepthExceeded/root.ts (1 errors) ==== + exports.rel = rel.relativeProp; + +==== maxDepthExceeded/root.ts (2 errors) ==== import * as m1 from "m1"; m1.f1("test"); m1.f2.a = "10"; // Error: Should be number ~~~~~~~ !!! error TS2322: Type 'string' is not assignable to type 'number'. + m1.rel = 42; // Error: Should be boolean + ~~~~~~ +!!! error TS2322: Type 'number' is not assignable to type 'boolean'. + m1.f2.person.age = "10"; // OK if stopped at 2 modules: person will be "any". \ No newline at end of file diff --git a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.json b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.json index 80a0a0fb93d..a4ac37bb2a3 100644 --- a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.json +++ b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.json @@ -8,6 +8,7 @@ "resolvedInputFiles": [ "lib.d.ts", "maxDepthExceeded/node_modules/m2/entry.js", + "maxDepthExceeded/node_modules/m1/relative.js", "maxDepthExceeded/node_modules/m1/index.js", "maxDepthExceeded/root.ts" ], diff --git a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/maxDepthExceeded/root.js b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/maxDepthExceeded/root.js index 28f91fb9b91..fb4faf236b2 100644 --- a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/maxDepthExceeded/root.js +++ b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/maxDepthExceeded/root.js @@ -2,4 +2,5 @@ var m1 = require("m1"); m1.f1("test"); m1.f2.a = "10"; // Error: Should be number +m1.rel = 42; // Error: Should be boolean m1.f2.person.age = "10"; // OK if stopped at 2 modules: person will be "any". diff --git a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.errors.txt b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.errors.txt index f03b958275b..52c3611ceda 100644 --- a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.errors.txt +++ b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.errors.txt @@ -1,4 +1,5 @@ maxDepthExceeded/root.ts(3,1): error TS2322: Type 'string' is not assignable to type 'number'. +maxDepthExceeded/root.ts(4,1): error TS2322: Type 'number' is not assignable to type 'boolean'. ==== entry.js (0 errors) ==== @@ -10,8 +11,12 @@ maxDepthExceeded/root.ts(3,1): error TS2322: Type 'string' is not assignable to "person": m3.person }; +==== relative.js (0 errors) ==== + exports.relativeProp = true; + ==== index.js (0 errors) ==== var m2 = require('m2'); + var rel = require('./relative'); /** * @param {string} p1 The first param @@ -22,11 +27,17 @@ maxDepthExceeded/root.ts(3,1): error TS2322: Type 'string' is not assignable to exports.f2 = m2; -==== maxDepthExceeded/root.ts (1 errors) ==== + exports.rel = rel.relativeProp; + +==== maxDepthExceeded/root.ts (2 errors) ==== import * as m1 from "m1"; m1.f1("test"); m1.f2.a = "10"; // Error: Should be number ~~~~~~~ !!! error TS2322: Type 'string' is not assignable to type 'number'. + m1.rel = 42; // Error: Should be boolean + ~~~~~~ +!!! error TS2322: Type 'number' is not assignable to type 'boolean'. + m1.f2.person.age = "10"; // OK if stopped at 2 modules: person will be "any". \ No newline at end of file diff --git a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.json b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.json index 80a0a0fb93d..a4ac37bb2a3 100644 --- a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.json +++ b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.json @@ -8,6 +8,7 @@ "resolvedInputFiles": [ "lib.d.ts", "maxDepthExceeded/node_modules/m2/entry.js", + "maxDepthExceeded/node_modules/m1/relative.js", "maxDepthExceeded/node_modules/m1/index.js", "maxDepthExceeded/root.ts" ], diff --git a/tests/cases/projects/NodeModulesSearch/maxDepthExceeded/node_modules/m1/index.js b/tests/cases/projects/NodeModulesSearch/maxDepthExceeded/node_modules/m1/index.js index 7ff454a2402..0433199ffd5 100644 --- a/tests/cases/projects/NodeModulesSearch/maxDepthExceeded/node_modules/m1/index.js +++ b/tests/cases/projects/NodeModulesSearch/maxDepthExceeded/node_modules/m1/index.js @@ -1,4 +1,5 @@ var m2 = require('m2'); +var rel = require('./relative'); /** * @param {string} p1 The first param @@ -8,3 +9,5 @@ exports.f1 = function(p1) { }; exports.f2 = m2; + +exports.rel = rel.relativeProp; diff --git a/tests/cases/projects/NodeModulesSearch/maxDepthExceeded/node_modules/m1/relative.js b/tests/cases/projects/NodeModulesSearch/maxDepthExceeded/node_modules/m1/relative.js new file mode 100644 index 00000000000..8b051584b85 --- /dev/null +++ b/tests/cases/projects/NodeModulesSearch/maxDepthExceeded/node_modules/m1/relative.js @@ -0,0 +1 @@ +exports.relativeProp = true; diff --git a/tests/cases/projects/NodeModulesSearch/maxDepthExceeded/root.ts b/tests/cases/projects/NodeModulesSearch/maxDepthExceeded/root.ts index 62604408648..f847ea6048a 100644 --- a/tests/cases/projects/NodeModulesSearch/maxDepthExceeded/root.ts +++ b/tests/cases/projects/NodeModulesSearch/maxDepthExceeded/root.ts @@ -1,4 +1,6 @@ import * as m1 from "m1"; m1.f1("test"); m1.f2.a = "10"; // Error: Should be number +m1.rel = 42; // Error: Should be boolean + m1.f2.person.age = "10"; // OK if stopped at 2 modules: person will be "any". From 5eba2e09fb8ab58be895e93c16daf2571ef14f65 Mon Sep 17 00:00:00 2001 From: Bill Ticehurst Date: Sun, 10 Jul 2016 20:54:07 -0700 Subject: [PATCH 09/28] Fixed the node tracking and a harness bug (cherry picked from commit 2ab1143f1cb694f43cd2622fc3fddbbe304a805b) --- src/compiler/program.ts | 2 ++ src/harness/projectsRunner.ts | 28 +++++++++++++------ .../moduleAugmentationInDependency2.js | 2 ++ tests/baselines/reference/nodeResolution6.js | 2 -- tests/baselines/reference/nodeResolution8.js | 2 -- .../pathMappingBasedModuleResolution5_node.js | 3 ++ .../amd/maxDepthExceeded/{ => built}/root.js | 0 .../nodeModulesMaxDepthExceeded.errors.txt | 2 +- .../amd/nodeModulesMaxDepthExceeded.json | 4 ++- .../node/maxDepthExceeded/{ => built}/root.js | 0 .../nodeModulesMaxDepthExceeded.errors.txt | 2 +- .../node/nodeModulesMaxDepthExceeded.json | 4 ++- .../maxDepthExceeded/tsconfig.json | 8 ++++-- 13 files changed, 40 insertions(+), 19 deletions(-) rename tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/maxDepthExceeded/{ => built}/root.js (100%) rename tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/maxDepthExceeded/{ => built}/root.js (100%) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 5d636847045..57bb3d6ae42 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1921,6 +1921,7 @@ namespace ts { // If the file was previously found via a node_modules search, but is now being processed as a root file, // then everything it sucks in may also be marked incorrectly, and needs to be checked again. if (file && lookUp(sourceFilesFoundSearchingNodeModules, file.path) && currentNodeModulesDepth == 0) { + sourceFilesFoundSearchingNodeModules[file.path] = false; if (!options.noResolve) { processReferencedFiles(file, getDirectoryPath(fileName), isDefaultLib); processTypeReferenceDirectives(file); @@ -1953,6 +1954,7 @@ namespace ts { filesByName.set(path, file); if (file) { + sourceFilesFoundSearchingNodeModules[path] = (currentNodeModulesDepth > 0); file.path = path; if (host.useCaseSensitiveFileNames()) { diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index fb92ff4dfab..4baf423a7ba 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -479,17 +479,27 @@ class ProjectRunner extends RunnerBase { it("Baseline of emitted result (" + moduleNameToString(moduleKind) + "): " + testCaseFileName, () => { if (testCase.baselineCheck) { + let errs = []; ts.forEach(compilerResult.outputFiles, outputFile => { - - Harness.Baseline.runBaseline("Baseline of emitted result (" + moduleNameToString(compilerResult.moduleKind) + "): " + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + outputFile.fileName, () => { - try { - return Harness.IO.readFile(getProjectOutputFolder(outputFile.fileName, compilerResult.moduleKind)); - } - catch (e) { - return undefined; - } - }); + // There may be multiple files with different baselines. Run all and report at the end, else + // it stops copying the remaining emitted files from 'local/projectOutput' to 'local/project'. + try { + Harness.Baseline.runBaseline("Baseline of emitted result (" + moduleNameToString(compilerResult.moduleKind) + "): " + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + outputFile.fileName, () => { + try { + return Harness.IO.readFile(getProjectOutputFolder(outputFile.fileName, compilerResult.moduleKind)); + } + catch (e) { + return undefined; + } + }); + } + catch (e) { + errs.push(e); + } }); + if (errs.length) { + throw Error(errs.join("\n ")); + } } }); diff --git a/tests/baselines/reference/moduleAugmentationInDependency2.js b/tests/baselines/reference/moduleAugmentationInDependency2.js index 0a5d83695a3..381f1e72d8f 100644 --- a/tests/baselines/reference/moduleAugmentationInDependency2.js +++ b/tests/baselines/reference/moduleAugmentationInDependency2.js @@ -8,6 +8,8 @@ export {}; //// [app.ts] import "A" +//// [index.js] +"use strict"; //// [app.js] "use strict"; require("A"); diff --git a/tests/baselines/reference/nodeResolution6.js b/tests/baselines/reference/nodeResolution6.js index 58a9b907250..196e8ae57cf 100644 --- a/tests/baselines/reference/nodeResolution6.js +++ b/tests/baselines/reference/nodeResolution6.js @@ -13,7 +13,5 @@ export declare var y; import y = require("a"); -//// [ref.js] -var x = 1; //// [b.js] "use strict"; diff --git a/tests/baselines/reference/nodeResolution8.js b/tests/baselines/reference/nodeResolution8.js index 36b53eec553..1d90399ff70 100644 --- a/tests/baselines/reference/nodeResolution8.js +++ b/tests/baselines/reference/nodeResolution8.js @@ -12,7 +12,5 @@ export declare var y; //// [b.ts] import y = require("a"); -//// [ref.js] -var x = 1; //// [b.js] "use strict"; diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution5_node.js b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.js index e4440299cc7..1958800f918 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution5_node.js +++ b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.js @@ -31,6 +31,9 @@ exports.x = 1; //// [file2.js] "use strict"; exports.y = 1; +//// [file4.js] +"use strict"; +exports.z1 = 1; //// [file1.js] "use strict"; var file1_1 = require("folder2/file1"); diff --git a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/maxDepthExceeded/root.js b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/maxDepthExceeded/built/root.js similarity index 100% rename from tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/maxDepthExceeded/root.js rename to tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/maxDepthExceeded/built/root.js diff --git a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.errors.txt b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.errors.txt index 52c3611ceda..7099c05d577 100644 --- a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.errors.txt +++ b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.errors.txt @@ -14,7 +14,7 @@ maxDepthExceeded/root.ts(4,1): error TS2322: Type 'number' is not assignable to ==== relative.js (0 errors) ==== exports.relativeProp = true; -==== index.js (0 errors) ==== +==== maxDepthExceeded/node_modules/m1/index.js (0 errors) ==== var m2 = require('m2'); var rel = require('./relative'); diff --git a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.json b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.json index a4ac37bb2a3..86e856dc7b8 100644 --- a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.json +++ b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/nodeModulesMaxDepthExceeded.json @@ -13,6 +13,8 @@ "maxDepthExceeded/root.ts" ], "emittedFiles": [ - "maxDepthExceeded/root.js" + "maxDepthExceeded/built/node_modules/m1/relative.js", + "maxDepthExceeded/built/node_modules/m1/index.js", + "maxDepthExceeded/built/root.js" ] } \ No newline at end of file diff --git a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/maxDepthExceeded/root.js b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/maxDepthExceeded/built/root.js similarity index 100% rename from tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/maxDepthExceeded/root.js rename to tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/maxDepthExceeded/built/root.js diff --git a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.errors.txt b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.errors.txt index 52c3611ceda..7099c05d577 100644 --- a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.errors.txt +++ b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.errors.txt @@ -14,7 +14,7 @@ maxDepthExceeded/root.ts(4,1): error TS2322: Type 'number' is not assignable to ==== relative.js (0 errors) ==== exports.relativeProp = true; -==== index.js (0 errors) ==== +==== maxDepthExceeded/node_modules/m1/index.js (0 errors) ==== var m2 = require('m2'); var rel = require('./relative'); diff --git a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.json b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.json index a4ac37bb2a3..86e856dc7b8 100644 --- a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.json +++ b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/nodeModulesMaxDepthExceeded.json @@ -13,6 +13,8 @@ "maxDepthExceeded/root.ts" ], "emittedFiles": [ - "maxDepthExceeded/root.js" + "maxDepthExceeded/built/node_modules/m1/relative.js", + "maxDepthExceeded/built/node_modules/m1/index.js", + "maxDepthExceeded/built/root.js" ] } \ No newline at end of file diff --git a/tests/cases/projects/NodeModulesSearch/maxDepthExceeded/tsconfig.json b/tests/cases/projects/NodeModulesSearch/maxDepthExceeded/tsconfig.json index 0aafe67d688..52633bb5a98 100644 --- a/tests/cases/projects/NodeModulesSearch/maxDepthExceeded/tsconfig.json +++ b/tests/cases/projects/NodeModulesSearch/maxDepthExceeded/tsconfig.json @@ -1,5 +1,9 @@ { "compilerOptions": { - "allowJs": true - } + "allowJs": true, + "maxNodeModuleJsDepth": 1, // Note: Module m1 is already included as a root file + "outDir": "built" + }, + "include": ["**/*"], + "exclude": ["node_modules/m2/**/*"] } From f8a92611eba079036501086aaa075a68c36320fc Mon Sep 17 00:00:00 2001 From: Bill Ticehurst Date: Sun, 10 Jul 2016 21:40:38 -0700 Subject: [PATCH 10/28] fixed lint error (cherry picked from commit a7467a1d2b5795a1bae38885ee5127cce37a9682) --- src/harness/projectsRunner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index 4baf423a7ba..083f7a7bf39 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -479,7 +479,7 @@ class ProjectRunner extends RunnerBase { it("Baseline of emitted result (" + moduleNameToString(moduleKind) + "): " + testCaseFileName, () => { if (testCase.baselineCheck) { - let errs = []; + const errs = []; ts.forEach(compilerResult.outputFiles, outputFile => { // There may be multiple files with different baselines. Run all and report at the end, else // it stops copying the remaining emitted files from 'local/projectOutput' to 'local/project'. From f5769875e5f53a9379b2b882ff6f540dda927f40 Mon Sep 17 00:00:00 2001 From: Bill Ticehurst Date: Sun, 10 Jul 2016 21:49:13 -0700 Subject: [PATCH 11/28] Fixed implicit any (cherry picked from commit b75053cae3733d0c402a36fab0d7fd2366ed9dc8) --- src/harness/projectsRunner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index 083f7a7bf39..cf3c78d8859 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -479,7 +479,7 @@ class ProjectRunner extends RunnerBase { it("Baseline of emitted result (" + moduleNameToString(moduleKind) + "): " + testCaseFileName, () => { if (testCase.baselineCheck) { - const errs = []; + const errs: Error[] = []; ts.forEach(compilerResult.outputFiles, outputFile => { // There may be multiple files with different baselines. Run all and report at the end, else // it stops copying the remaining emitted files from 'local/projectOutput' to 'local/project'. From dd86be4e085095d6f6100f56f2693488f63f644c Mon Sep 17 00:00:00 2001 From: Bill Ticehurst Date: Sun, 10 Jul 2016 22:25:31 -0700 Subject: [PATCH 12/28] Added missing test files (cherry picked from commit 97025d026da460bd7dd76b2f175813fde2791f34) --- .gitignore | 1 + .../maxDepthExceeded/built/node_modules/m1/index.js | 10 ++++++++++ .../maxDepthExceeded/built/node_modules/m1/relative.js | 1 + .../maxDepthExceeded/built/node_modules/m1/index.js | 10 ++++++++++ .../maxDepthExceeded/built/node_modules/m1/relative.js | 1 + 5 files changed, 23 insertions(+) create mode 100644 tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/maxDepthExceeded/built/node_modules/m1/index.js create mode 100644 tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/maxDepthExceeded/built/node_modules/m1/relative.js create mode 100644 tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/maxDepthExceeded/built/node_modules/m1/index.js create mode 100644 tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/maxDepthExceeded/built/node_modules/m1/relative.js diff --git a/.gitignore b/.gitignore index bbb2e62c8bc..3d78e3b6411 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,4 @@ internal/ !**/.vscode/tasks.json !tests/cases/projects/projectOption/**/node_modules !tests/cases/projects/NodeModulesSearch/**/* +!tests/baselines/reference/project/nodeModules*/**/* diff --git a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/maxDepthExceeded/built/node_modules/m1/index.js b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/maxDepthExceeded/built/node_modules/m1/index.js new file mode 100644 index 00000000000..46d38afba6f --- /dev/null +++ b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/maxDepthExceeded/built/node_modules/m1/index.js @@ -0,0 +1,10 @@ +var m2 = require('m2'); +var rel = require('./relative'); +/** + * @param {string} p1 The first param + */ +exports.f1 = function (p1) { + return 42; +}; +exports.f2 = m2; +exports.rel = rel.relativeProp; diff --git a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/maxDepthExceeded/built/node_modules/m1/relative.js b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/maxDepthExceeded/built/node_modules/m1/relative.js new file mode 100644 index 00000000000..13432076541 --- /dev/null +++ b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/amd/maxDepthExceeded/built/node_modules/m1/relative.js @@ -0,0 +1 @@ +exports.relativeProp = true; diff --git a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/maxDepthExceeded/built/node_modules/m1/index.js b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/maxDepthExceeded/built/node_modules/m1/index.js new file mode 100644 index 00000000000..46d38afba6f --- /dev/null +++ b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/maxDepthExceeded/built/node_modules/m1/index.js @@ -0,0 +1,10 @@ +var m2 = require('m2'); +var rel = require('./relative'); +/** + * @param {string} p1 The first param + */ +exports.f1 = function (p1) { + return 42; +}; +exports.f2 = m2; +exports.rel = rel.relativeProp; diff --git a/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/maxDepthExceeded/built/node_modules/m1/relative.js b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/maxDepthExceeded/built/node_modules/m1/relative.js new file mode 100644 index 00000000000..13432076541 --- /dev/null +++ b/tests/baselines/reference/project/nodeModulesMaxDepthExceeded/node/maxDepthExceeded/built/node_modules/m1/relative.js @@ -0,0 +1 @@ +exports.relativeProp = true; From 5f6eb5bb126e5a5cdbfe023604a4d769a8964b94 Mon Sep 17 00:00:00 2001 From: Bill Ticehurst Date: Sun, 10 Jul 2016 23:07:45 -0700 Subject: [PATCH 13/28] Removed duplicate logic (cherry picked from commit 21bf801c6cd98063ebcbd7439a49c1152717188f) --- src/compiler/program.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 57bb3d6ae42..670d30b7d33 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2091,13 +2091,6 @@ namespace ts { currentNodeModulesDepth++; } - if (currentNodeModulesDepth > 0) { - // If its already present with false, its a root file also. Don't override this. - if (!hasProperty(sourceFilesFoundSearchingNodeModules, resolvedPath)) { - sourceFilesFoundSearchingNodeModules[resolvedPath] = true; - } - } - const elideImport = isJsFileFromNodeModules && currentNodeModulesDepth > maxNodeModulesJsDepth; const shouldAddFile = resolution && !options.noResolve && i < file.imports.length && !elideImport; From 2f8a5b34f6031b4538a8ca2f103c2d11cc250349 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 8 Jul 2016 09:40:54 -0700 Subject: [PATCH 14/28] Test for multiple salsa assignment-declarations --- .../reference/multipleDeclarations.js | 17 +++++++++++ .../reference/multipleDeclarations.symbols | 17 +++++++++++ .../reference/multipleDeclarations.types | 29 +++++++++++++++++++ .../conformance/salsa/multipleDeclarations.ts | 10 +++++++ 4 files changed, 73 insertions(+) create mode 100644 tests/baselines/reference/multipleDeclarations.js create mode 100644 tests/baselines/reference/multipleDeclarations.symbols create mode 100644 tests/baselines/reference/multipleDeclarations.types create mode 100644 tests/cases/conformance/salsa/multipleDeclarations.ts diff --git a/tests/baselines/reference/multipleDeclarations.js b/tests/baselines/reference/multipleDeclarations.js new file mode 100644 index 00000000000..5f5ac29e909 --- /dev/null +++ b/tests/baselines/reference/multipleDeclarations.js @@ -0,0 +1,17 @@ +//// [input.js] + +function C() { + this.m = null; +} +C.prototype.m = function() { + this.nothing(); +}; + + +//// [output.js] +function C() { + this.m = null; +} +C.prototype.m = function () { + this.nothing(); +}; diff --git a/tests/baselines/reference/multipleDeclarations.symbols b/tests/baselines/reference/multipleDeclarations.symbols new file mode 100644 index 00000000000..0c8569ab89e --- /dev/null +++ b/tests/baselines/reference/multipleDeclarations.symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/salsa/input.js === + +function C() { +>C : Symbol(C, Decl(input.js, 0, 0)) + + this.m = null; +>m : Symbol(C.m, Decl(input.js, 1, 14), Decl(input.js, 3, 1)) +} +C.prototype.m = function() { +>C.prototype : Symbol(C.m, Decl(input.js, 1, 14), Decl(input.js, 3, 1)) +>C : Symbol(C, Decl(input.js, 0, 0)) +>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --)) +>m : Symbol(C.m, Decl(input.js, 1, 14), Decl(input.js, 3, 1)) + + this.nothing(); +}; + diff --git a/tests/baselines/reference/multipleDeclarations.types b/tests/baselines/reference/multipleDeclarations.types new file mode 100644 index 00000000000..7c0a3de70c9 --- /dev/null +++ b/tests/baselines/reference/multipleDeclarations.types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/salsa/input.js === + +function C() { +>C : () => void + + this.m = null; +>this.m = null : null +>this.m : any +>this : any +>m : any +>null : null +} +C.prototype.m = function() { +>C.prototype.m = function() { this.nothing();} : () => void +>C.prototype.m : any +>C.prototype : any +>C : () => void +>prototype : any +>m : any +>function() { this.nothing();} : () => void + + this.nothing(); +>this.nothing() : any +>this.nothing : any +>this : { m: () => void; } +>nothing : any + +}; + diff --git a/tests/cases/conformance/salsa/multipleDeclarations.ts b/tests/cases/conformance/salsa/multipleDeclarations.ts new file mode 100644 index 00000000000..6899be2ec89 --- /dev/null +++ b/tests/cases/conformance/salsa/multipleDeclarations.ts @@ -0,0 +1,10 @@ +// @filename: input.js +// @out: output.js +// @allowJs: true + +function C() { + this.m = null; +} +C.prototype.m = function() { + this.nothing(); +}; From 9ae04223e38ed236ccbe2cb24ee59bf6ab242c49 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 8 Jul 2016 09:26:58 -0700 Subject: [PATCH 15/28] Fix multiple Salsa assignment-declarations Previously, all assignment-declarations needed to be of the same kind: either all `this.p = ...` assignments or `C.prototype.p = ...` assignments. --- src/compiler/checker.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d6db67d3fa8..8568f8cf4aa 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3166,17 +3166,17 @@ namespace ts { } let type: Type = undefined; - // Handle module.exports = expr or this.p = expr - if (declaration.kind === SyntaxKind.BinaryExpression) { - type = getUnionType(map(symbol.declarations, (decl: BinaryExpression) => checkExpressionCached(decl.right))); - } - else if (declaration.kind === SyntaxKind.PropertyAccessExpression) { - // Declarations only exist for property access expressions for certain - // special assignment kinds - if (declaration.parent.kind === SyntaxKind.BinaryExpression) { - // Handle exports.p = expr or className.prototype.method = expr - type = checkExpressionCached((declaration.parent).right); - } + // Handle certain special assignment kinds, which happen to union across multiple declarations: + // * module.exports = expr + // * exports.p = expr + // * this.p = expr + // * className.prototype.method = expr + if (declaration.kind === SyntaxKind.BinaryExpression || + declaration.kind === SyntaxKind.PropertyAccessExpression && declaration.parent.kind === SyntaxKind.BinaryExpression) { + type = getUnionType(map(symbol.declarations, + decl => decl.kind === SyntaxKind.BinaryExpression ? + checkExpressionCached((decl).right) : + checkExpressionCached((decl.parent).right))); } if (type === undefined) { From 4598c13eecd8512ca460b61db4d681f792e7be29 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 8 Jul 2016 12:52:54 -0700 Subject: [PATCH 16/28] Provide a symbol for salsa-inferred class types --- src/compiler/checker.ts | 2 +- .../reference/methodsReturningThis.js | 36 +++++ .../reference/methodsReturningThis.symbols | 101 +++++++++++++ .../reference/methodsReturningThis.types | 133 ++++++++++++++++++ ...turesUseJSDocForOptionalParameters.symbols | 2 + ...naturesUseJSDocForOptionalParameters.types | 18 +-- .../conformance/salsa/methodsReturningThis.ts | 21 +++ 7 files changed, 303 insertions(+), 10 deletions(-) create mode 100644 tests/baselines/reference/methodsReturningThis.js create mode 100644 tests/baselines/reference/methodsReturningThis.symbols create mode 100644 tests/baselines/reference/methodsReturningThis.types create mode 100644 tests/cases/conformance/salsa/methodsReturningThis.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8568f8cf4aa..aea8c982a95 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11673,7 +11673,7 @@ namespace ts { function getInferredClassType(symbol: Symbol) { const links = getSymbolLinks(symbol); if (!links.inferredClassType) { - links.inferredClassType = createAnonymousType(undefined, symbol.members, emptyArray, emptyArray, /*stringIndexType*/ undefined, /*numberIndexType*/ undefined); + links.inferredClassType = createAnonymousType(symbol, symbol.members, emptyArray, emptyArray, /*stringIndexType*/ undefined, /*numberIndexType*/ undefined); } return links.inferredClassType; } diff --git a/tests/baselines/reference/methodsReturningThis.js b/tests/baselines/reference/methodsReturningThis.js new file mode 100644 index 00000000000..b0ebd84770d --- /dev/null +++ b/tests/baselines/reference/methodsReturningThis.js @@ -0,0 +1,36 @@ +//// [input.js] +function Class() +{ +} + +// error: 'Class' doesn't have property 'notPresent' +Class.prototype.containsError = function () { return this.notPresent; }; + +// lots of methods that return this, which caused out-of-memory in #9527 +Class.prototype.m1 = function (a, b, c, d, tx, ty) { return this; }; +Class.prototype.m2 = function (x, y) { return this; }; +Class.prototype.m3 = function (x, y) { return this; }; +Class.prototype.m4 = function (angle) { return this; }; +Class.prototype.m5 = function (matrix) { return this; }; +Class.prototype.m6 = function (x, y, pivotX, pivotY, scaleX, scaleY, rotation, skewX, skewY) { return this; }; +Class.prototype.m7 = function(matrix) { return this; }; +Class.prototype.m8 = function() { return this; }; +Class.prototype.m9 = function () { return this; }; + + + +//// [output.js] +function Class() { +} +// error: 'Class' doesn't have property 'notPresent' +Class.prototype.containsError = function () { return this.notPresent; }; +// lots of methods that return this, which caused out-of-memory in #9527 +Class.prototype.m1 = function (a, b, c, d, tx, ty) { return this; }; +Class.prototype.m2 = function (x, y) { return this; }; +Class.prototype.m3 = function (x, y) { return this; }; +Class.prototype.m4 = function (angle) { return this; }; +Class.prototype.m5 = function (matrix) { return this; }; +Class.prototype.m6 = function (x, y, pivotX, pivotY, scaleX, scaleY, rotation, skewX, skewY) { return this; }; +Class.prototype.m7 = function (matrix) { return this; }; +Class.prototype.m8 = function () { return this; }; +Class.prototype.m9 = function () { return this; }; diff --git a/tests/baselines/reference/methodsReturningThis.symbols b/tests/baselines/reference/methodsReturningThis.symbols new file mode 100644 index 00000000000..eccb1a64f89 --- /dev/null +++ b/tests/baselines/reference/methodsReturningThis.symbols @@ -0,0 +1,101 @@ +=== tests/cases/conformance/salsa/input.js === +function Class() +>Class : Symbol(Class, Decl(input.js, 0, 0)) +{ +} + +// error: 'Class' doesn't have property 'notPresent' +Class.prototype.containsError = function () { return this.notPresent; }; +>Class.prototype : Symbol(Class.containsError, Decl(input.js, 2, 1)) +>Class : Symbol(Class, Decl(input.js, 0, 0)) +>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --)) +>containsError : Symbol(Class.containsError, Decl(input.js, 2, 1)) +>this : Symbol(Class, Decl(input.js, 0, 0)) + +// lots of methods that return this, which caused out-of-memory in #9527 +Class.prototype.m1 = function (a, b, c, d, tx, ty) { return this; }; +>Class.prototype : Symbol(Class.m1, Decl(input.js, 5, 72)) +>Class : Symbol(Class, Decl(input.js, 0, 0)) +>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --)) +>m1 : Symbol(Class.m1, Decl(input.js, 5, 72)) +>a : Symbol(a, Decl(input.js, 8, 31)) +>b : Symbol(b, Decl(input.js, 8, 33)) +>c : Symbol(c, Decl(input.js, 8, 36)) +>d : Symbol(d, Decl(input.js, 8, 39)) +>tx : Symbol(tx, Decl(input.js, 8, 42)) +>ty : Symbol(ty, Decl(input.js, 8, 46)) +>this : Symbol(Class, Decl(input.js, 0, 0)) + +Class.prototype.m2 = function (x, y) { return this; }; +>Class.prototype : Symbol(Class.m2, Decl(input.js, 8, 68)) +>Class : Symbol(Class, Decl(input.js, 0, 0)) +>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --)) +>m2 : Symbol(Class.m2, Decl(input.js, 8, 68)) +>x : Symbol(x, Decl(input.js, 9, 31)) +>y : Symbol(y, Decl(input.js, 9, 33)) +>this : Symbol(Class, Decl(input.js, 0, 0)) + +Class.prototype.m3 = function (x, y) { return this; }; +>Class.prototype : Symbol(Class.m3, Decl(input.js, 9, 54)) +>Class : Symbol(Class, Decl(input.js, 0, 0)) +>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --)) +>m3 : Symbol(Class.m3, Decl(input.js, 9, 54)) +>x : Symbol(x, Decl(input.js, 10, 31)) +>y : Symbol(y, Decl(input.js, 10, 33)) +>this : Symbol(Class, Decl(input.js, 0, 0)) + +Class.prototype.m4 = function (angle) { return this; }; +>Class.prototype : Symbol(Class.m4, Decl(input.js, 10, 54)) +>Class : Symbol(Class, Decl(input.js, 0, 0)) +>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --)) +>m4 : Symbol(Class.m4, Decl(input.js, 10, 54)) +>angle : Symbol(angle, Decl(input.js, 11, 31)) +>this : Symbol(Class, Decl(input.js, 0, 0)) + +Class.prototype.m5 = function (matrix) { return this; }; +>Class.prototype : Symbol(Class.m5, Decl(input.js, 11, 55)) +>Class : Symbol(Class, Decl(input.js, 0, 0)) +>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --)) +>m5 : Symbol(Class.m5, Decl(input.js, 11, 55)) +>matrix : Symbol(matrix, Decl(input.js, 12, 31)) +>this : Symbol(Class, Decl(input.js, 0, 0)) + +Class.prototype.m6 = function (x, y, pivotX, pivotY, scaleX, scaleY, rotation, skewX, skewY) { return this; }; +>Class.prototype : Symbol(Class.m6, Decl(input.js, 12, 56)) +>Class : Symbol(Class, Decl(input.js, 0, 0)) +>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --)) +>m6 : Symbol(Class.m6, Decl(input.js, 12, 56)) +>x : Symbol(x, Decl(input.js, 13, 31)) +>y : Symbol(y, Decl(input.js, 13, 33)) +>pivotX : Symbol(pivotX, Decl(input.js, 13, 36)) +>pivotY : Symbol(pivotY, Decl(input.js, 13, 44)) +>scaleX : Symbol(scaleX, Decl(input.js, 13, 52)) +>scaleY : Symbol(scaleY, Decl(input.js, 13, 60)) +>rotation : Symbol(rotation, Decl(input.js, 13, 68)) +>skewX : Symbol(skewX, Decl(input.js, 13, 78)) +>skewY : Symbol(skewY, Decl(input.js, 13, 85)) +>this : Symbol(Class, Decl(input.js, 0, 0)) + +Class.prototype.m7 = function(matrix) { return this; }; +>Class.prototype : Symbol(Class.m7, Decl(input.js, 13, 110)) +>Class : Symbol(Class, Decl(input.js, 0, 0)) +>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --)) +>m7 : Symbol(Class.m7, Decl(input.js, 13, 110)) +>matrix : Symbol(matrix, Decl(input.js, 14, 30)) +>this : Symbol(Class, Decl(input.js, 0, 0)) + +Class.prototype.m8 = function() { return this; }; +>Class.prototype : Symbol(Class.m8, Decl(input.js, 14, 55)) +>Class : Symbol(Class, Decl(input.js, 0, 0)) +>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --)) +>m8 : Symbol(Class.m8, Decl(input.js, 14, 55)) +>this : Symbol(Class, Decl(input.js, 0, 0)) + +Class.prototype.m9 = function () { return this; }; +>Class.prototype : Symbol(Class.m9, Decl(input.js, 15, 49)) +>Class : Symbol(Class, Decl(input.js, 0, 0)) +>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --)) +>m9 : Symbol(Class.m9, Decl(input.js, 15, 49)) +>this : Symbol(Class, Decl(input.js, 0, 0)) + + diff --git a/tests/baselines/reference/methodsReturningThis.types b/tests/baselines/reference/methodsReturningThis.types new file mode 100644 index 00000000000..5bcaa992a71 --- /dev/null +++ b/tests/baselines/reference/methodsReturningThis.types @@ -0,0 +1,133 @@ +=== tests/cases/conformance/salsa/input.js === +function Class() +>Class : () => void +{ +} + +// error: 'Class' doesn't have property 'notPresent' +Class.prototype.containsError = function () { return this.notPresent; }; +>Class.prototype.containsError = function () { return this.notPresent; } : () => any +>Class.prototype.containsError : any +>Class.prototype : any +>Class : () => void +>prototype : any +>containsError : any +>function () { return this.notPresent; } : () => any +>this.notPresent : any +>this : { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: () => typeof Class; } +>notPresent : any + +// lots of methods that return this, which caused out-of-memory in #9527 +Class.prototype.m1 = function (a, b, c, d, tx, ty) { return this; }; +>Class.prototype.m1 = function (a, b, c, d, tx, ty) { return this; } : (a: any, b: any, c: any, d: any, tx: any, ty: any) => { containsError: () => any; m1: any; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: () => typeof Class; } +>Class.prototype.m1 : any +>Class.prototype : any +>Class : () => void +>prototype : any +>m1 : any +>function (a, b, c, d, tx, ty) { return this; } : (a: any, b: any, c: any, d: any, tx: any, ty: any) => { containsError: () => any; m1: any; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: () => typeof Class; } +>a : any +>b : any +>c : any +>d : any +>tx : any +>ty : any +>this : { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: () => typeof Class; } + +Class.prototype.m2 = function (x, y) { return this; }; +>Class.prototype.m2 = function (x, y) { return this; } : (x: any, y: any) => { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: any; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: () => typeof Class; } +>Class.prototype.m2 : any +>Class.prototype : any +>Class : () => void +>prototype : any +>m2 : any +>function (x, y) { return this; } : (x: any, y: any) => { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: any; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: () => typeof Class; } +>x : any +>y : any +>this : { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: () => typeof Class; } + +Class.prototype.m3 = function (x, y) { return this; }; +>Class.prototype.m3 = function (x, y) { return this; } : (x: any, y: any) => { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: any; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: () => typeof Class; } +>Class.prototype.m3 : any +>Class.prototype : any +>Class : () => void +>prototype : any +>m3 : any +>function (x, y) { return this; } : (x: any, y: any) => { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: any; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: () => typeof Class; } +>x : any +>y : any +>this : { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: () => typeof Class; } + +Class.prototype.m4 = function (angle) { return this; }; +>Class.prototype.m4 = function (angle) { return this; } : (angle: any) => { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: any; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: () => typeof Class; } +>Class.prototype.m4 : any +>Class.prototype : any +>Class : () => void +>prototype : any +>m4 : any +>function (angle) { return this; } : (angle: any) => { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: any; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: () => typeof Class; } +>angle : any +>this : { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: () => typeof Class; } + +Class.prototype.m5 = function (matrix) { return this; }; +>Class.prototype.m5 = function (matrix) { return this; } : (matrix: any) => { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: any; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: () => typeof Class; } +>Class.prototype.m5 : any +>Class.prototype : any +>Class : () => void +>prototype : any +>m5 : any +>function (matrix) { return this; } : (matrix: any) => { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: any; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: () => typeof Class; } +>matrix : any +>this : { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: () => typeof Class; } + +Class.prototype.m6 = function (x, y, pivotX, pivotY, scaleX, scaleY, rotation, skewX, skewY) { return this; }; +>Class.prototype.m6 = function (x, y, pivotX, pivotY, scaleX, scaleY, rotation, skewX, skewY) { return this; } : (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: any; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: () => typeof Class; } +>Class.prototype.m6 : any +>Class.prototype : any +>Class : () => void +>prototype : any +>m6 : any +>function (x, y, pivotX, pivotY, scaleX, scaleY, rotation, skewX, skewY) { return this; } : (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: any; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: () => typeof Class; } +>x : any +>y : any +>pivotX : any +>pivotY : any +>scaleX : any +>scaleY : any +>rotation : any +>skewX : any +>skewY : any +>this : { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: () => typeof Class; } + +Class.prototype.m7 = function(matrix) { return this; }; +>Class.prototype.m7 = function(matrix) { return this; } : (matrix: any) => { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: any; m8: () => typeof Class; m9: () => typeof Class; } +>Class.prototype.m7 : any +>Class.prototype : any +>Class : () => void +>prototype : any +>m7 : any +>function(matrix) { return this; } : (matrix: any) => { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: any; m8: () => typeof Class; m9: () => typeof Class; } +>matrix : any +>this : { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: () => typeof Class; } + +Class.prototype.m8 = function() { return this; }; +>Class.prototype.m8 = function() { return this; } : () => { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: any; m9: () => typeof Class; } +>Class.prototype.m8 : any +>Class.prototype : any +>Class : () => void +>prototype : any +>m8 : any +>function() { return this; } : () => { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: any; m9: () => typeof Class; } +>this : { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: () => typeof Class; } + +Class.prototype.m9 = function () { return this; }; +>Class.prototype.m9 = function () { return this; } : () => { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: any; } +>Class.prototype.m9 : any +>Class.prototype : any +>Class : () => void +>prototype : any +>m9 : any +>function () { return this; } : () => { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: any; } +>this : { containsError: () => any; m1: (a: any, b: any, c: any, d: any, tx: any, ty: any) => typeof Class; m2: (x: any, y: any) => typeof Class; m3: (x: any, y: any) => typeof Class; m4: (angle: any) => typeof Class; m5: (matrix: any) => typeof Class; m6: (x: any, y: any, pivotX: any, pivotY: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any) => typeof Class; m7: (matrix: any) => typeof Class; m8: () => typeof Class; m9: () => typeof Class; } + + diff --git a/tests/baselines/reference/signaturesUseJSDocForOptionalParameters.symbols b/tests/baselines/reference/signaturesUseJSDocForOptionalParameters.symbols index 5ea2756598e..52fc8b9a9a9 100644 --- a/tests/baselines/reference/signaturesUseJSDocForOptionalParameters.symbols +++ b/tests/baselines/reference/signaturesUseJSDocForOptionalParameters.symbols @@ -19,6 +19,8 @@ MyClass.prototype.optionalParam = function(required, notRequired) { >notRequired : Symbol(notRequired, Decl(jsDocOptionality.js, 8, 52)) return this; +>this : Symbol(MyClass, Decl(jsDocOptionality.js, 0, 0)) + }; let pInst = new MyClass(); >pInst : Symbol(pInst, Decl(jsDocOptionality.js, 11, 3)) diff --git a/tests/baselines/reference/signaturesUseJSDocForOptionalParameters.types b/tests/baselines/reference/signaturesUseJSDocForOptionalParameters.types index 2dcaa37b947..48d44bb5406 100644 --- a/tests/baselines/reference/signaturesUseJSDocForOptionalParameters.types +++ b/tests/baselines/reference/signaturesUseJSDocForOptionalParameters.types @@ -26,27 +26,27 @@ MyClass.prototype.optionalParam = function(required, notRequired) { >notRequired : string return this; ->this : { prop: null; optionalParam: (required: string, notRequired?: string) => { prop: null; optionalParam: any; }; } +>this : { prop: null; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } }; let pInst = new MyClass(); ->pInst : { prop: null; optionalParam: (required: string, notRequired?: string) => { prop: null; optionalParam: any; }; } ->new MyClass() : { prop: null; optionalParam: (required: string, notRequired?: string) => { prop: null; optionalParam: any; }; } +>pInst : { prop: null; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } +>new MyClass() : { prop: null; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } >MyClass : () => void let c1 = pInst.optionalParam('hello') ->c1 : { prop: null; optionalParam: (required: string, notRequired?: string) => { prop: null; optionalParam: any; }; } ->pInst.optionalParam('hello') : { prop: null; optionalParam: (required: string, notRequired?: string) => { prop: null; optionalParam: any; }; } +>c1 : { prop: null; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } +>pInst.optionalParam('hello') : { prop: null; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } >pInst.optionalParam : (required: string, notRequired?: string) => { prop: null; optionalParam: any; } ->pInst : { prop: null; optionalParam: (required: string, notRequired?: string) => { prop: null; optionalParam: any; }; } +>pInst : { prop: null; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } >optionalParam : (required: string, notRequired?: string) => { prop: null; optionalParam: any; } >'hello' : string let c2 = pInst.optionalParam('hello', null) ->c2 : { prop: null; optionalParam: (required: string, notRequired?: string) => { prop: null; optionalParam: any; }; } ->pInst.optionalParam('hello', null) : { prop: null; optionalParam: (required: string, notRequired?: string) => { prop: null; optionalParam: any; }; } +>c2 : { prop: null; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } +>pInst.optionalParam('hello', null) : { prop: null; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } >pInst.optionalParam : (required: string, notRequired?: string) => { prop: null; optionalParam: any; } ->pInst : { prop: null; optionalParam: (required: string, notRequired?: string) => { prop: null; optionalParam: any; }; } +>pInst : { prop: null; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } >optionalParam : (required: string, notRequired?: string) => { prop: null; optionalParam: any; } >'hello' : string >null : null diff --git a/tests/cases/conformance/salsa/methodsReturningThis.ts b/tests/cases/conformance/salsa/methodsReturningThis.ts new file mode 100644 index 00000000000..4c9f0d5cd0b --- /dev/null +++ b/tests/cases/conformance/salsa/methodsReturningThis.ts @@ -0,0 +1,21 @@ +// @filename: input.js +// @out: output.js +// @allowJs: true +function Class() +{ +} + +// error: 'Class' doesn't have property 'notPresent' +Class.prototype.containsError = function () { return this.notPresent; }; + +// lots of methods that return this, which caused out-of-memory in #9527 +Class.prototype.m1 = function (a, b, c, d, tx, ty) { return this; }; +Class.prototype.m2 = function (x, y) { return this; }; +Class.prototype.m3 = function (x, y) { return this; }; +Class.prototype.m4 = function (angle) { return this; }; +Class.prototype.m5 = function (matrix) { return this; }; +Class.prototype.m6 = function (x, y, pivotX, pivotY, scaleX, scaleY, rotation, skewX, skewY) { return this; }; +Class.prototype.m7 = function(matrix) { return this; }; +Class.prototype.m8 = function() { return this; }; +Class.prototype.m9 = function () { return this; }; + From 4e02bc61a2551c883ba0beefc527fbcb5d156afe Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 11 Jul 2016 13:04:48 -0700 Subject: [PATCH 17/28] Update conflicting baseline. PR #9574 added a baseline that #9578 caused to be changed. The two PRs went in so close to each other that the CI build didn't catch the change to the new test's baseline. --- tests/baselines/reference/multipleDeclarations.symbols | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/baselines/reference/multipleDeclarations.symbols b/tests/baselines/reference/multipleDeclarations.symbols index 0c8569ab89e..a256943dd50 100644 --- a/tests/baselines/reference/multipleDeclarations.symbols +++ b/tests/baselines/reference/multipleDeclarations.symbols @@ -13,5 +13,7 @@ C.prototype.m = function() { >m : Symbol(C.m, Decl(input.js, 1, 14), Decl(input.js, 3, 1)) this.nothing(); +>this : Symbol(C, Decl(input.js, 0, 0)) + }; From 122c47c0350d8142900315778c438e5cbab76155 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 13 Jul 2016 08:15:55 -0700 Subject: [PATCH 18/28] Handle JSX bodies in formatter --- src/services/formatting/formattingScanner.ts | 13 ++++++++++++- tests/cases/fourslash/formatTsx.ts | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/formatTsx.ts diff --git a/src/services/formatting/formattingScanner.ts b/src/services/formatting/formattingScanner.ts index 401794a077b..7822e4a72fc 100644 --- a/src/services/formatting/formattingScanner.ts +++ b/src/services/formatting/formattingScanner.ts @@ -26,7 +26,8 @@ namespace ts.formatting { RescanGreaterThanToken, RescanSlashToken, RescanTemplateToken, - RescanJsxIdentifier + RescanJsxIdentifier, + RescanJsxText, } export function getFormattingScanner(sourceFile: SourceFile, startPos: number, endPos: number): FormattingScanner { @@ -140,6 +141,10 @@ namespace ts.formatting { return false; } + function shouldRescanJsxText(node: Node): boolean { + return node && node.kind === SyntaxKind.JsxText; + } + function shouldRescanSlashToken(container: Node): boolean { return container.kind === SyntaxKind.RegularExpressionLiteral; } @@ -176,6 +181,8 @@ namespace ts.formatting { ? ScanAction.RescanTemplateToken : shouldRescanJsxIdentifier(n) ? ScanAction.RescanJsxIdentifier + : shouldRescanJsxText(n) + ? ScanAction.RescanJsxText : ScanAction.Scan; if (lastTokenInfo && expectedScanAction === lastScanAction) { @@ -215,6 +222,10 @@ namespace ts.formatting { currentToken = scanner.scanJsxIdentifier(); lastScanAction = ScanAction.RescanJsxIdentifier; } + else if (expectedScanAction === ScanAction.RescanJsxText) { + currentToken = scanner.reScanJsxToken(); + lastScanAction = ScanAction.RescanJsxText; + } else { lastScanAction = ScanAction.Scan; } diff --git a/tests/cases/fourslash/formatTsx.ts b/tests/cases/fourslash/formatTsx.ts new file mode 100644 index 00000000000..1472351fe40 --- /dev/null +++ b/tests/cases/fourslash/formatTsx.ts @@ -0,0 +1,18 @@ +/// + +// @Filename: foo.tsx +////

'

{function(){return 1;}]}

+ +format.document(); +verify.currentFileContentIs("

'

{function() { return 1; }]}

"); + +/* +< 0 +p 1 +> 2 +' 3 +< 4 +/ 5 +p 6 +> 7 +*/ From 606ac0e533d78f5e89bc61ce4b0beec7af77ccad Mon Sep 17 00:00:00 2001 From: zhengbli Date: Wed, 13 Jul 2016 11:38:26 -0700 Subject: [PATCH 19/28] Port #9621 to release-2.0 --- src/compiler/checker.ts | 3 ++ .../cases/fourslash/server/jsdocTypedefTag.ts | 34 ++++++++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index aea8c982a95..e842f008bbe 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3160,6 +3160,9 @@ namespace ts { if (declaration.kind === SyntaxKind.ExportAssignment) { return links.type = checkExpression((declaration).expression); } + if (declaration.flags & NodeFlags.JavaScriptFile && declaration.kind === SyntaxKind.JSDocPropertyTag && (declaration).typeExpression) { + return links.type = getTypeFromTypeNode((declaration).typeExpression.type); + } // Handle variable, parameter or property if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) { return unknownType; diff --git a/tests/cases/fourslash/server/jsdocTypedefTag.ts b/tests/cases/fourslash/server/jsdocTypedefTag.ts index e645b518020..968e30a412d 100644 --- a/tests/cases/fourslash/server/jsdocTypedefTag.ts +++ b/tests/cases/fourslash/server/jsdocTypedefTag.ts @@ -32,16 +32,24 @@ //// var numberLike; numberLike./*numberLike*/ //// //// /** @type {Person} */ -//// var p;p./*person*/ +//// var p;p./*person*/; +//// p.personName./*personName*/; +//// p.personAge./*personAge*/; //// //// /** @type {Animal} */ -//// var a;a./*animal*/ +//// var a;a./*animal*/; +//// a.animalName./*animalName*/; +//// a.animalAge./*animalAge*/; //// //// /** @type {Cat} */ -//// var c;c./*cat*/ +//// var c;c./*cat*/; +//// c.catName./*catName*/; +//// c.catAge./*catAge*/; //// //// /** @type {Dog} */ -//// var d;d./*dog*/ +//// var d;d./*dog*/; +//// d.dogName./*dogName*/; +//// d.dogAge./*dogAge*/; goTo.marker('numberLike'); verify.memberListContains('charAt'); @@ -50,15 +58,31 @@ verify.memberListContains('toExponential'); goTo.marker('person'); verify.memberListContains('personName'); verify.memberListContains('personAge'); +goTo.marker('personName'); +verify.memberListContains('charAt'); +goTo.marker('personAge'); +verify.memberListContains('toExponential'); goTo.marker('animal'); verify.memberListContains('animalName'); verify.memberListContains('animalAge'); +goTo.marker('animalName'); +verify.memberListContains('charAt'); +goTo.marker('animalAge'); +verify.memberListContains('toExponential'); goTo.marker('dog'); verify.memberListContains('dogName'); verify.memberListContains('dogAge'); +goTo.marker('dogName'); +verify.memberListContains('charAt'); +goTo.marker('dogAge'); +verify.memberListContains('toExponential'); goTo.marker('cat'); verify.memberListContains('catName'); -verify.memberListContains('catAge'); \ No newline at end of file +verify.memberListContains('catAge'); +goTo.marker('catName'); +verify.memberListContains('charAt'); +goTo.marker('catAge'); +verify.memberListContains('toExponential'); \ No newline at end of file From e28acd3c1f57d04c38fcf509c89d41a9597f6efe Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Wed, 13 Jul 2016 09:13:55 -0700 Subject: [PATCH 20/28] Add formatDiagnostics utility --- src/compiler/program.ts | 17 +++++++++++++++++ src/compiler/tsc.ts | 19 ++----------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 670d30b7d33..032c5dc847b 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -997,6 +997,23 @@ namespace ts { return sortAndDeduplicateDiagnostics(diagnostics); } + export function formatDiagnostics(diagnostics: Diagnostic[], host: CompilerHost): string { + let output = ""; + + for (const diagnostic of diagnostics) { + if (diagnostic.file) { + const { line, character } = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start); + const fileName = diagnostic.file.fileName; + const relativeFileName = convertToRelativePath(fileName, host.getCurrentDirectory(), fileName => host.getCanonicalFileName(fileName)); + output += `${ relativeFileName }(${ line + 1 },${ character + 1 }): `; + } + + const category = DiagnosticCategory[diagnostic.category].toLowerCase(); + output += `${ category } TS${ diagnostic.code }: ${ flattenDiagnosticMessageText(diagnostic.messageText, sys.newLine) }${ sys.newLine }`; + } + return output; + } + export function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string { if (typeof messageText === "string") { return messageText; diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index e25ae37e21f..36f71f063bb 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -101,23 +101,8 @@ namespace ts { return diagnostic.messageText; } - function getRelativeFileName(fileName: string, host: CompilerHost): string { - return host ? convertToRelativePath(fileName, host.getCurrentDirectory(), fileName => host.getCanonicalFileName(fileName)) : fileName; - } - function reportDiagnosticSimply(diagnostic: Diagnostic, host: CompilerHost): void { - let output = ""; - - if (diagnostic.file) { - const { line, character } = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start); - const relativeFileName = getRelativeFileName(diagnostic.file.fileName, host); - output += `${ relativeFileName }(${ line + 1 },${ character + 1 }): `; - } - - const category = DiagnosticCategory[diagnostic.category].toLowerCase(); - output += `${ category } TS${ diagnostic.code }: ${ flattenDiagnosticMessageText(diagnostic.messageText, sys.newLine) }${ sys.newLine }`; - - sys.write(output); + sys.write(ts.formatDiagnostics([diagnostic], host)); } const redForegroundEscapeSequence = "\u001b[91m"; @@ -145,7 +130,7 @@ namespace ts { const { line: firstLine, character: firstLineChar } = getLineAndCharacterOfPosition(file, start); const { line: lastLine, character: lastLineChar } = getLineAndCharacterOfPosition(file, start + length); const lastLineInFile = getLineAndCharacterOfPosition(file, file.text.length).line; - const relativeFileName = getRelativeFileName(file.fileName, host); + const relativeFileName = host ? convertToRelativePath(file.fileName, host.getCurrentDirectory(), fileName => host.getCanonicalFileName(fileName)) : file.fileName;; const hasMoreThanFiveLines = (lastLine - firstLine) >= 4; let gutterWidth = (lastLine + 1 + "").length; From 05fbe7cddd89ad62994702228c90fe53e199a0a3 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Wed, 13 Jul 2016 15:25:15 -0700 Subject: [PATCH 21/28] use getNewLine from host rather than sys --- src/compiler/program.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 032c5dc847b..eceaff3df6d 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1009,7 +1009,7 @@ namespace ts { } const category = DiagnosticCategory[diagnostic.category].toLowerCase(); - output += `${ category } TS${ diagnostic.code }: ${ flattenDiagnosticMessageText(diagnostic.messageText, sys.newLine) }${ sys.newLine }`; + output += `${ category } TS${ diagnostic.code }: ${ flattenDiagnosticMessageText(diagnostic.messageText, host.getNewLine()) }${ host.getNewLine() }`; } return output; } From af0c548312e2e3867249964b2ed107beb22cf53e Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 15 Jul 2016 12:33:53 -0700 Subject: [PATCH 22/28] Merge pull request #9750 from Microsoft/fixFormatDiagnostics use sys based host for formatting diagnostics --- src/compiler/program.ts | 8 +++++++- src/compiler/tsc.ts | 38 ++++++++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index eceaff3df6d..39a55afe27a 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -997,7 +997,13 @@ namespace ts { return sortAndDeduplicateDiagnostics(diagnostics); } - export function formatDiagnostics(diagnostics: Diagnostic[], host: CompilerHost): string { + export interface FormatDiagnosticsHost { + getCurrentDirectory(): string; + getCanonicalFileName(fileName: string): string; + getNewLine(): string; + } + + export function formatDiagnostics(diagnostics: Diagnostic[], host: FormatDiagnosticsHost): string { let output = ""; for (const diagnostic of diagnostics) { diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 36f71f063bb..9ff03ba74b4 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -6,9 +6,19 @@ namespace ts { fileWatcher?: FileWatcher; } - let reportDiagnostic = reportDiagnosticSimply; + const defaultFormatDiagnosticsHost: FormatDiagnosticsHost = { + getCurrentDirectory: () => sys.getCurrentDirectory(), + getNewLine: () => sys.newLine, + getCanonicalFileName: createGetCanonicalFileName(sys.useCaseSensitiveFileNames) + }; - function reportDiagnostics(diagnostics: Diagnostic[], host: CompilerHost): void { + let reportDiagnosticWorker = reportDiagnosticSimply; + + function reportDiagnostic(diagnostic: Diagnostic, host: FormatDiagnosticsHost) { + reportDiagnosticWorker(diagnostic, host || defaultFormatDiagnosticsHost); + } + + function reportDiagnostics(diagnostics: Diagnostic[], host: FormatDiagnosticsHost): void { for (const diagnostic of diagnostics) { reportDiagnostic(diagnostic, host); } @@ -101,7 +111,7 @@ namespace ts { return diagnostic.messageText; } - function reportDiagnosticSimply(diagnostic: Diagnostic, host: CompilerHost): void { + function reportDiagnosticSimply(diagnostic: Diagnostic, host: FormatDiagnosticsHost): void { sys.write(ts.formatDiagnostics([diagnostic], host)); } @@ -122,7 +132,7 @@ namespace ts { return formatStyle + text + resetEscapeSequence; } - function reportDiagnosticWithColorAndContext(diagnostic: Diagnostic, host: CompilerHost): void { + function reportDiagnosticWithColorAndContext(diagnostic: Diagnostic, host: FormatDiagnosticsHost): void { let output = ""; if (diagnostic.file) { @@ -257,7 +267,7 @@ namespace ts { if (commandLine.options.locale) { if (!isJSONSupported()) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--locale"), /* compilerHost */ undefined); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--locale"), /* host */ undefined); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } validateLocaleAndSetLanguage(commandLine.options.locale, commandLine.errors); @@ -288,11 +298,11 @@ namespace ts { if (commandLine.options.project) { if (!isJSONSupported()) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--project"), /* compilerHost */ undefined); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--project"), /* host */ undefined); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } if (commandLine.fileNames.length !== 0) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.Option_project_cannot_be_mixed_with_source_files_on_a_command_line), /* compilerHost */ undefined); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.Option_project_cannot_be_mixed_with_source_files_on_a_command_line), /* host */ undefined); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } @@ -300,14 +310,14 @@ namespace ts { if (!fileOrDirectory /* current directory "." */ || sys.directoryExists(fileOrDirectory)) { configFileName = combinePaths(fileOrDirectory, "tsconfig.json"); if (!sys.fileExists(configFileName)) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.Cannot_find_a_tsconfig_json_file_at_the_specified_directory_Colon_0, commandLine.options.project), /* compilerHost */ undefined); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.Cannot_find_a_tsconfig_json_file_at_the_specified_directory_Colon_0, commandLine.options.project), /* host */ undefined); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } } else { configFileName = fileOrDirectory; if (!sys.fileExists(configFileName)) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_specified_path_does_not_exist_Colon_0, commandLine.options.project), /* compilerHost */ undefined); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_specified_path_does_not_exist_Colon_0, commandLine.options.project), /* host */ undefined); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } } @@ -325,7 +335,7 @@ namespace ts { if (isWatchSet(commandLine.options)) { if (!sys.watchFile) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch"), /* compilerHost */ undefined); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch"), /* host */ undefined); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } if (configFileName) { @@ -378,7 +388,7 @@ namespace ts { } if (isWatchSet(configParseResult.options)) { if (!sys.watchFile) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch"), /* compilerHost */ undefined); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch"), /* host */ undefined); sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } @@ -417,7 +427,7 @@ namespace ts { } if (compilerOptions.pretty) { - reportDiagnostic = reportDiagnosticWithColorAndContext; + reportDiagnosticWorker = reportDiagnosticWithColorAndContext; } // reset the cache of existing files @@ -742,7 +752,7 @@ namespace ts { const currentDirectory = sys.getCurrentDirectory(); const file = normalizePath(combinePaths(currentDirectory, "tsconfig.json")); if (sys.fileExists(file)) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.A_tsconfig_json_file_is_already_defined_at_Colon_0, file), /* compilerHost */ undefined); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.A_tsconfig_json_file_is_already_defined_at_Colon_0, file), /* host */ undefined); } else { const compilerOptions = extend(options, defaultInitCompilerOptions); @@ -762,7 +772,7 @@ namespace ts { } sys.writeFile(file, JSON.stringify(configurations, undefined, 4)); - reportDiagnostic(createCompilerDiagnostic(Diagnostics.Successfully_created_a_tsconfig_json_file), /* compilerHost */ undefined); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.Successfully_created_a_tsconfig_json_file), /* host */ undefined); } return; From bf8937cc84e9d868dd762f765d9dda52ecb5dddc Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 15 Jul 2016 12:51:53 -0700 Subject: [PATCH 23/28] remove extra semicolon --- src/compiler/tsc.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 9ff03ba74b4..e32a3816d64 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -140,7 +140,7 @@ namespace ts { const { line: firstLine, character: firstLineChar } = getLineAndCharacterOfPosition(file, start); const { line: lastLine, character: lastLineChar } = getLineAndCharacterOfPosition(file, start + length); const lastLineInFile = getLineAndCharacterOfPosition(file, file.text.length).line; - const relativeFileName = host ? convertToRelativePath(file.fileName, host.getCurrentDirectory(), fileName => host.getCanonicalFileName(fileName)) : file.fileName;; + const relativeFileName = host ? convertToRelativePath(file.fileName, host.getCurrentDirectory(), fileName => host.getCanonicalFileName(fileName)) : file.fileName; const hasMoreThanFiveLines = (lastLine - firstLine) >= 4; let gutterWidth = (lastLine + 1 + "").length; From 5319fa3a0d9f7710345801df6ada0253349d82e2 Mon Sep 17 00:00:00 2001 From: Yui Date: Fri, 15 Jul 2016 16:49:18 -0700 Subject: [PATCH 24/28] Fix linting error (#9762) --- src/compiler/tsc.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 36f71f063bb..2d90804a03b 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -130,7 +130,7 @@ namespace ts { const { line: firstLine, character: firstLineChar } = getLineAndCharacterOfPosition(file, start); const { line: lastLine, character: lastLineChar } = getLineAndCharacterOfPosition(file, start + length); const lastLineInFile = getLineAndCharacterOfPosition(file, file.text.length).line; - const relativeFileName = host ? convertToRelativePath(file.fileName, host.getCurrentDirectory(), fileName => host.getCanonicalFileName(fileName)) : file.fileName;; + const relativeFileName = host ? convertToRelativePath(file.fileName, host.getCurrentDirectory(), fileName => host.getCanonicalFileName(fileName)) : file.fileName; const hasMoreThanFiveLines = (lastLine - firstLine) >= 4; let gutterWidth = (lastLine + 1 + "").length; From 9ef65cf3af3e40d463135b466361ef7293d8b526 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Sun, 17 Jul 2016 23:25:33 -0700 Subject: [PATCH 25/28] remove unused method declaration --- src/compiler/types.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 3a3a937ade7..981c9db96f2 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2908,7 +2908,6 @@ namespace ts { getCancellationToken?(): CancellationToken; getDefaultLibFileName(options: CompilerOptions): string; getDefaultLibLocation?(): string; - getDefaultTypeDirectiveNames?(rootPath: string): string[]; writeFile: WriteFileCallback; getCurrentDirectory(): string; getDirectories(path: string): string[]; From 290caad40254101faf324a05360a142d0ed88301 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Sun, 17 Jul 2016 23:51:17 -0700 Subject: [PATCH 26/28] Fix #9636: Report unused type paramters only on last declaration --- src/compiler/checker.ts | 13 +++-- .../reference/unusedTypeParameters6.js | 16 ++++++ .../reference/unusedTypeParameters6.symbols | 13 +++++ .../reference/unusedTypeParameters6.types | 13 +++++ .../reference/unusedTypeParameters7.js | 16 ++++++ .../reference/unusedTypeParameters7.symbols | 13 +++++ .../reference/unusedTypeParameters7.types | 13 +++++ .../unusedTypeParameters8.errors.txt | 11 ++++ .../reference/unusedTypeParameters8.js | 16 ++++++ .../reference/unusedTypeParameters9.js | 30 +++++++++++ .../reference/unusedTypeParameters9.symbols | 53 +++++++++++++++++++ .../reference/unusedTypeParameters9.types | 53 +++++++++++++++++++ tests/cases/compiler/unusedTypeParameters6.ts | 8 +++ tests/cases/compiler/unusedTypeParameters7.ts | 8 +++ tests/cases/compiler/unusedTypeParameters8.ts | 8 +++ tests/cases/compiler/unusedTypeParameters9.ts | 17 ++++++ 16 files changed, 298 insertions(+), 3 deletions(-) create mode 100644 tests/baselines/reference/unusedTypeParameters6.js create mode 100644 tests/baselines/reference/unusedTypeParameters6.symbols create mode 100644 tests/baselines/reference/unusedTypeParameters6.types create mode 100644 tests/baselines/reference/unusedTypeParameters7.js create mode 100644 tests/baselines/reference/unusedTypeParameters7.symbols create mode 100644 tests/baselines/reference/unusedTypeParameters7.types create mode 100644 tests/baselines/reference/unusedTypeParameters8.errors.txt create mode 100644 tests/baselines/reference/unusedTypeParameters8.js create mode 100644 tests/baselines/reference/unusedTypeParameters9.js create mode 100644 tests/baselines/reference/unusedTypeParameters9.symbols create mode 100644 tests/baselines/reference/unusedTypeParameters9.types create mode 100644 tests/cases/compiler/unusedTypeParameters6.ts create mode 100644 tests/cases/compiler/unusedTypeParameters7.ts create mode 100644 tests/cases/compiler/unusedTypeParameters8.ts create mode 100644 tests/cases/compiler/unusedTypeParameters9.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d6db67d3fa8..5ca952f883f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13274,7 +13274,7 @@ namespace ts { checkAsyncFunctionReturnType(node); } } - if (!(node).body) { + if (noUnusedIdentifiers && !(node).body) { checkUnusedTypeParameters(node); } } @@ -14609,8 +14609,15 @@ namespace ts { function checkUnusedTypeParameters(node: ClassDeclaration | ClassExpression | FunctionDeclaration | MethodDeclaration | FunctionExpression | ArrowFunction | ConstructorDeclaration | SignatureDeclaration | InterfaceDeclaration) { if (compilerOptions.noUnusedLocals && !isInAmbientContext(node)) { if (node.typeParameters) { + // Only report errors on the last declaration for the type parameter container; + // this ensures that all uses have been accounted for. + const symbol = node.symbol && getMergedSymbol(node.symbol); + const lastDeclaration = symbol && symbol.declarations && lastOrUndefined(symbol.declarations); + if (lastDeclaration !== node) { + return; + } for (const typeParameter of node.typeParameters) { - if (!typeParameter.symbol.isReferenced) { + if (!getMergedSymbol(typeParameter.symbol).isReferenced) { error(typeParameter.name, Diagnostics._0_is_declared_but_never_used, typeParameter.symbol.name); } } @@ -16119,7 +16126,7 @@ namespace ts { if (produceDiagnostics) { checkTypeForDuplicateIndexSignatures(node); - checkUnusedTypeParameters(node); + registerForUnusedIdentifiersCheck(node); } } diff --git a/tests/baselines/reference/unusedTypeParameters6.js b/tests/baselines/reference/unusedTypeParameters6.js new file mode 100644 index 00000000000..4c2b3a9d0ba --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters6.js @@ -0,0 +1,16 @@ +//// [tests/cases/compiler/unusedTypeParameters6.ts] //// + +//// [a.ts] + +class C { } + +//// [b.ts] +interface C { a: T; } + +//// [a.js] +var C = (function () { + function C() { + } + return C; +}()); +//// [b.js] diff --git a/tests/baselines/reference/unusedTypeParameters6.symbols b/tests/baselines/reference/unusedTypeParameters6.symbols new file mode 100644 index 00000000000..bf20b44d347 --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters6.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/a.ts === + +class C { } +>C : Symbol(C, Decl(a.ts, 0, 0), Decl(b.ts, 0, 0)) +>T : Symbol(T, Decl(a.ts, 1, 8), Decl(b.ts, 0, 12)) + +=== tests/cases/compiler/b.ts === +interface C { a: T; } +>C : Symbol(C, Decl(a.ts, 0, 0), Decl(b.ts, 0, 0)) +>T : Symbol(T, Decl(a.ts, 1, 8), Decl(b.ts, 0, 12)) +>a : Symbol(C.a, Decl(b.ts, 0, 16)) +>T : Symbol(T, Decl(a.ts, 1, 8), Decl(b.ts, 0, 12)) + diff --git a/tests/baselines/reference/unusedTypeParameters6.types b/tests/baselines/reference/unusedTypeParameters6.types new file mode 100644 index 00000000000..165862c0080 --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters6.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/a.ts === + +class C { } +>C : C +>T : T + +=== tests/cases/compiler/b.ts === +interface C { a: T; } +>C : C +>T : T +>a : T +>T : T + diff --git a/tests/baselines/reference/unusedTypeParameters7.js b/tests/baselines/reference/unusedTypeParameters7.js new file mode 100644 index 00000000000..d63f7a0edc3 --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters7.js @@ -0,0 +1,16 @@ +//// [tests/cases/compiler/unusedTypeParameters7.ts] //// + +//// [a.ts] + +class C { a: T; } + +//// [b.ts] +interface C { } + +//// [a.js] +var C = (function () { + function C() { + } + return C; +}()); +//// [b.js] diff --git a/tests/baselines/reference/unusedTypeParameters7.symbols b/tests/baselines/reference/unusedTypeParameters7.symbols new file mode 100644 index 00000000000..79704b437a6 --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters7.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/a.ts === + +class C { a: T; } +>C : Symbol(C, Decl(a.ts, 0, 0), Decl(b.ts, 0, 0)) +>T : Symbol(T, Decl(a.ts, 1, 8), Decl(b.ts, 0, 12)) +>a : Symbol(C.a, Decl(a.ts, 1, 12)) +>T : Symbol(T, Decl(a.ts, 1, 8), Decl(b.ts, 0, 12)) + +=== tests/cases/compiler/b.ts === +interface C { } +>C : Symbol(C, Decl(a.ts, 0, 0), Decl(b.ts, 0, 0)) +>T : Symbol(T, Decl(a.ts, 1, 8), Decl(b.ts, 0, 12)) + diff --git a/tests/baselines/reference/unusedTypeParameters7.types b/tests/baselines/reference/unusedTypeParameters7.types new file mode 100644 index 00000000000..a52b4cee7ec --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters7.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/a.ts === + +class C { a: T; } +>C : C +>T : T +>a : T +>T : T + +=== tests/cases/compiler/b.ts === +interface C { } +>C : C +>T : T + diff --git a/tests/baselines/reference/unusedTypeParameters8.errors.txt b/tests/baselines/reference/unusedTypeParameters8.errors.txt new file mode 100644 index 00000000000..d7928d36900 --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters8.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/b.ts(1,13): error TS6133: 'T' is declared but never used. + + +==== tests/cases/compiler/a.ts (0 errors) ==== + + class C { } + +==== tests/cases/compiler/b.ts (1 errors) ==== + interface C { } + ~ +!!! error TS6133: 'T' is declared but never used. \ No newline at end of file diff --git a/tests/baselines/reference/unusedTypeParameters8.js b/tests/baselines/reference/unusedTypeParameters8.js new file mode 100644 index 00000000000..0c34373d315 --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters8.js @@ -0,0 +1,16 @@ +//// [tests/cases/compiler/unusedTypeParameters8.ts] //// + +//// [a.ts] + +class C { } + +//// [b.ts] +interface C { } + +//// [a.js] +var C = (function () { + function C() { + } + return C; +}()); +//// [b.js] diff --git a/tests/baselines/reference/unusedTypeParameters9.js b/tests/baselines/reference/unusedTypeParameters9.js new file mode 100644 index 00000000000..8d82921b076 --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters9.js @@ -0,0 +1,30 @@ +//// [unusedTypeParameters9.ts] + +// clas + interface +class C1 { } +interface C1 { a: T; } + +// interface + class +class C2 { a: T; } +interface C2 { } + +// interfaces +interface C3 { a(c: (p: T) => void): void; } +interface C3 { b: string; } +interface C3 { c: number; } +interface C3 { d: boolean; } +interface C3 { e: any; } + +//// [unusedTypeParameters9.js] +// clas + interface +var C1 = (function () { + function C1() { + } + return C1; +}()); +// interface + class +var C2 = (function () { + function C2() { + } + return C2; +}()); diff --git a/tests/baselines/reference/unusedTypeParameters9.symbols b/tests/baselines/reference/unusedTypeParameters9.symbols new file mode 100644 index 00000000000..6c4f6aab71c --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters9.symbols @@ -0,0 +1,53 @@ +=== tests/cases/compiler/unusedTypeParameters9.ts === + +// clas + interface +class C1 { } +>C1 : Symbol(C1, Decl(unusedTypeParameters9.ts, 0, 0), Decl(unusedTypeParameters9.ts, 2, 15)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 2, 9), Decl(unusedTypeParameters9.ts, 3, 13)) + +interface C1 { a: T; } +>C1 : Symbol(C1, Decl(unusedTypeParameters9.ts, 0, 0), Decl(unusedTypeParameters9.ts, 2, 15)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 2, 9), Decl(unusedTypeParameters9.ts, 3, 13)) +>a : Symbol(C1.a, Decl(unusedTypeParameters9.ts, 3, 17)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 2, 9), Decl(unusedTypeParameters9.ts, 3, 13)) + +// interface + class +class C2 { a: T; } +>C2 : Symbol(C2, Decl(unusedTypeParameters9.ts, 3, 25), Decl(unusedTypeParameters9.ts, 6, 21)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 6, 9), Decl(unusedTypeParameters9.ts, 7, 13)) +>a : Symbol(C2.a, Decl(unusedTypeParameters9.ts, 6, 13)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 6, 9), Decl(unusedTypeParameters9.ts, 7, 13)) + +interface C2 { } +>C2 : Symbol(C2, Decl(unusedTypeParameters9.ts, 3, 25), Decl(unusedTypeParameters9.ts, 6, 21)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 6, 9), Decl(unusedTypeParameters9.ts, 7, 13)) + +// interfaces +interface C3 { a(c: (p: T) => void): void; } +>C3 : Symbol(C3, Decl(unusedTypeParameters9.ts, 7, 19), Decl(unusedTypeParameters9.ts, 10, 47), Decl(unusedTypeParameters9.ts, 11, 30), Decl(unusedTypeParameters9.ts, 12, 30), Decl(unusedTypeParameters9.ts, 13, 32)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 10, 13), Decl(unusedTypeParameters9.ts, 11, 13), Decl(unusedTypeParameters9.ts, 12, 13), Decl(unusedTypeParameters9.ts, 13, 13), Decl(unusedTypeParameters9.ts, 14, 13)) +>a : Symbol(C3.a, Decl(unusedTypeParameters9.ts, 10, 17)) +>c : Symbol(c, Decl(unusedTypeParameters9.ts, 10, 20)) +>p : Symbol(p, Decl(unusedTypeParameters9.ts, 10, 24)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 10, 13), Decl(unusedTypeParameters9.ts, 11, 13), Decl(unusedTypeParameters9.ts, 12, 13), Decl(unusedTypeParameters9.ts, 13, 13), Decl(unusedTypeParameters9.ts, 14, 13)) + +interface C3 { b: string; } +>C3 : Symbol(C3, Decl(unusedTypeParameters9.ts, 7, 19), Decl(unusedTypeParameters9.ts, 10, 47), Decl(unusedTypeParameters9.ts, 11, 30), Decl(unusedTypeParameters9.ts, 12, 30), Decl(unusedTypeParameters9.ts, 13, 32)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 10, 13), Decl(unusedTypeParameters9.ts, 11, 13), Decl(unusedTypeParameters9.ts, 12, 13), Decl(unusedTypeParameters9.ts, 13, 13), Decl(unusedTypeParameters9.ts, 14, 13)) +>b : Symbol(C3.b, Decl(unusedTypeParameters9.ts, 11, 17)) + +interface C3 { c: number; } +>C3 : Symbol(C3, Decl(unusedTypeParameters9.ts, 7, 19), Decl(unusedTypeParameters9.ts, 10, 47), Decl(unusedTypeParameters9.ts, 11, 30), Decl(unusedTypeParameters9.ts, 12, 30), Decl(unusedTypeParameters9.ts, 13, 32)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 10, 13), Decl(unusedTypeParameters9.ts, 11, 13), Decl(unusedTypeParameters9.ts, 12, 13), Decl(unusedTypeParameters9.ts, 13, 13), Decl(unusedTypeParameters9.ts, 14, 13)) +>c : Symbol(C3.c, Decl(unusedTypeParameters9.ts, 12, 17)) + +interface C3 { d: boolean; } +>C3 : Symbol(C3, Decl(unusedTypeParameters9.ts, 7, 19), Decl(unusedTypeParameters9.ts, 10, 47), Decl(unusedTypeParameters9.ts, 11, 30), Decl(unusedTypeParameters9.ts, 12, 30), Decl(unusedTypeParameters9.ts, 13, 32)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 10, 13), Decl(unusedTypeParameters9.ts, 11, 13), Decl(unusedTypeParameters9.ts, 12, 13), Decl(unusedTypeParameters9.ts, 13, 13), Decl(unusedTypeParameters9.ts, 14, 13)) +>d : Symbol(C3.d, Decl(unusedTypeParameters9.ts, 13, 17)) + +interface C3 { e: any; } +>C3 : Symbol(C3, Decl(unusedTypeParameters9.ts, 7, 19), Decl(unusedTypeParameters9.ts, 10, 47), Decl(unusedTypeParameters9.ts, 11, 30), Decl(unusedTypeParameters9.ts, 12, 30), Decl(unusedTypeParameters9.ts, 13, 32)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 10, 13), Decl(unusedTypeParameters9.ts, 11, 13), Decl(unusedTypeParameters9.ts, 12, 13), Decl(unusedTypeParameters9.ts, 13, 13), Decl(unusedTypeParameters9.ts, 14, 13)) +>e : Symbol(C3.e, Decl(unusedTypeParameters9.ts, 14, 17)) + diff --git a/tests/baselines/reference/unusedTypeParameters9.types b/tests/baselines/reference/unusedTypeParameters9.types new file mode 100644 index 00000000000..58a75e67297 --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters9.types @@ -0,0 +1,53 @@ +=== tests/cases/compiler/unusedTypeParameters9.ts === + +// clas + interface +class C1 { } +>C1 : C1 +>T : T + +interface C1 { a: T; } +>C1 : C1 +>T : T +>a : T +>T : T + +// interface + class +class C2 { a: T; } +>C2 : C2 +>T : T +>a : T +>T : T + +interface C2 { } +>C2 : C2 +>T : T + +// interfaces +interface C3 { a(c: (p: T) => void): void; } +>C3 : C3 +>T : T +>a : (c: (p: T) => void) => void +>c : (p: T) => void +>p : T +>T : T + +interface C3 { b: string; } +>C3 : C3 +>T : T +>b : string + +interface C3 { c: number; } +>C3 : C3 +>T : T +>c : number + +interface C3 { d: boolean; } +>C3 : C3 +>T : T +>d : boolean + +interface C3 { e: any; } +>C3 : C3 +>T : T +>e : any + diff --git a/tests/cases/compiler/unusedTypeParameters6.ts b/tests/cases/compiler/unusedTypeParameters6.ts new file mode 100644 index 00000000000..f445665f4ea --- /dev/null +++ b/tests/cases/compiler/unusedTypeParameters6.ts @@ -0,0 +1,8 @@ +//@noUnusedLocals:true +//@noUnusedParameters:true + +// @fileName: a.ts +class C { } + +// @fileName: b.ts +interface C { a: T; } \ No newline at end of file diff --git a/tests/cases/compiler/unusedTypeParameters7.ts b/tests/cases/compiler/unusedTypeParameters7.ts new file mode 100644 index 00000000000..87b42d97650 --- /dev/null +++ b/tests/cases/compiler/unusedTypeParameters7.ts @@ -0,0 +1,8 @@ +//@noUnusedLocals:true +//@noUnusedParameters:true + +// @fileName: a.ts +class C { a: T; } + +// @fileName: b.ts +interface C { } \ No newline at end of file diff --git a/tests/cases/compiler/unusedTypeParameters8.ts b/tests/cases/compiler/unusedTypeParameters8.ts new file mode 100644 index 00000000000..4034ed04c72 --- /dev/null +++ b/tests/cases/compiler/unusedTypeParameters8.ts @@ -0,0 +1,8 @@ +//@noUnusedLocals:true +//@noUnusedParameters:true + +// @fileName: a.ts +class C { } + +// @fileName: b.ts +interface C { } \ No newline at end of file diff --git a/tests/cases/compiler/unusedTypeParameters9.ts b/tests/cases/compiler/unusedTypeParameters9.ts new file mode 100644 index 00000000000..48581d4ab2e --- /dev/null +++ b/tests/cases/compiler/unusedTypeParameters9.ts @@ -0,0 +1,17 @@ +//@noUnusedLocals:true +//@noUnusedParameters:true + +// clas + interface +class C1 { } +interface C1 { a: T; } + +// interface + class +class C2 { a: T; } +interface C2 { } + +// interfaces +interface C3 { a(c: (p: T) => void): void; } +interface C3 { b: string; } +interface C3 { c: number; } +interface C3 { d: boolean; } +interface C3 { e: any; } \ No newline at end of file From 9886f88004168d4cce287f8f323ffeaab8100a92 Mon Sep 17 00:00:00 2001 From: Yui Date: Mon, 18 Jul 2016 08:48:12 -0700 Subject: [PATCH 27/28] [Release-2.0] Fix 9685: missing decoratedClassAlias emit in self-reference decorated class (#9763) * Wip * Fix incorrect emit decorated class alias when targeting es6 or higher * Add tests and baselines * Remove unused test file --- src/compiler/emitter.ts | 15 +++---- .../decoratedClassExportsCommonJS1.js | 28 +++++++++++++ .../decoratedClassExportsCommonJS1.symbols | 21 ++++++++++ .../decoratedClassExportsCommonJS1.types | 24 ++++++++++++ .../decoratedClassExportsCommonJS2.js | 26 +++++++++++++ .../decoratedClassExportsCommonJS2.symbols | 17 ++++++++ .../decoratedClassExportsCommonJS2.types | 20 ++++++++++ .../reference/decoratedClassExportsSystem1.js | 39 +++++++++++++++++++ .../decoratedClassExportsSystem1.symbols | 26 +++++++++++++ .../decoratedClassExportsSystem1.types | 29 ++++++++++++++ .../reference/decoratedClassExportsSystem2.js | 35 +++++++++++++++++ .../decoratedClassExportsSystem2.symbols | 17 ++++++++ .../decoratedClassExportsSystem2.types | 20 ++++++++++ .../class/decoratedClassExportsCommonJS1.ts | 13 +++++++ .../class/decoratedClassExportsCommonJS2.ts | 10 +++++ .../class/decoratedClassExportsSystem1.ts | 13 +++++++ .../class/decoratedClassExportsSystem2.ts | 10 +++++ 17 files changed, 356 insertions(+), 7 deletions(-) create mode 100644 tests/baselines/reference/decoratedClassExportsCommonJS1.js create mode 100644 tests/baselines/reference/decoratedClassExportsCommonJS1.symbols create mode 100644 tests/baselines/reference/decoratedClassExportsCommonJS1.types create mode 100644 tests/baselines/reference/decoratedClassExportsCommonJS2.js create mode 100644 tests/baselines/reference/decoratedClassExportsCommonJS2.symbols create mode 100644 tests/baselines/reference/decoratedClassExportsCommonJS2.types create mode 100644 tests/baselines/reference/decoratedClassExportsSystem1.js create mode 100644 tests/baselines/reference/decoratedClassExportsSystem1.symbols create mode 100644 tests/baselines/reference/decoratedClassExportsSystem1.types create mode 100644 tests/baselines/reference/decoratedClassExportsSystem2.js create mode 100644 tests/baselines/reference/decoratedClassExportsSystem2.symbols create mode 100644 tests/baselines/reference/decoratedClassExportsSystem2.types create mode 100644 tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts create mode 100644 tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS2.ts create mode 100644 tests/cases/conformance/decorators/class/decoratedClassExportsSystem1.ts create mode 100644 tests/cases/conformance/decorators/class/decoratedClassExportsSystem2.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 2d5acb3b486..7ac3b5acfb0 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2749,7 +2749,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge * if we should also export the value after its it changed * - check if node is a source level declaration to emit it differently, * i.e non-exported variable statement 'var x = 1' is hoisted so - * we we emit variable statement 'var' should be dropped. + * when we emit variable statement 'var' should be dropped. */ function isSourceFileLevelDeclarationInSystemJsModule(node: Node, isExported: boolean): boolean { if (!node || !isCurrentFileSystemExternalModule()) { @@ -5503,16 +5503,15 @@ const _super = (function (geti, seti) { write("export "); } - if (!isHoistedDeclarationInSystemModule) { - write("let "); - } if (decoratedClassAlias !== undefined) { - write(`${decoratedClassAlias}`); + write(`let ${decoratedClassAlias}`); } else { + if (!isHoistedDeclarationInSystemModule) { + write("let "); + } emitDeclarationName(node); } - write(" = "); } else if (isES6ExportedDeclaration(node)) { @@ -5530,7 +5529,9 @@ const _super = (function (geti, seti) { // // We'll emit: // - // (_temp = class C { ... }, _temp.a = 1, _temp.b = 2, _temp) + // let C_1 = class C{}; + // C_1.a = 1; + // C_1.b = 2; // so forth and so on // // This keeps the expression as an expression, while ensuring that the static parts // of it have been initialized by the time it is used. diff --git a/tests/baselines/reference/decoratedClassExportsCommonJS1.js b/tests/baselines/reference/decoratedClassExportsCommonJS1.js new file mode 100644 index 00000000000..4a04d724f0c --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsCommonJS1.js @@ -0,0 +1,28 @@ +//// [decoratedClassExportsCommonJS1.ts] +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { + static prop0: string; + static prop1 = Testing123.prop0; +} + +//// [decoratedClassExportsCommonJS1.js] +"use strict"; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +let Testing123_1 = class Testing123 { +}; +let Testing123 = Testing123_1; +Testing123.prop1 = Testing123.prop0; +Testing123 = Testing123_1 = __decorate([ + Something({ v: () => Testing123 }), + __metadata('design:paramtypes', []) +], Testing123); +exports.Testing123 = Testing123; diff --git a/tests/baselines/reference/decoratedClassExportsCommonJS1.symbols b/tests/baselines/reference/decoratedClassExportsCommonJS1.symbols new file mode 100644 index 00000000000..3381ef7c06a --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsCommonJS1.symbols @@ -0,0 +1,21 @@ +=== tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts === +declare var Something: any; +>Something : Symbol(Something, Decl(decoratedClassExportsCommonJS1.ts, 0, 11)) + +@Something({ v: () => Testing123 }) +>Something : Symbol(Something, Decl(decoratedClassExportsCommonJS1.ts, 0, 11)) +>v : Symbol(v, Decl(decoratedClassExportsCommonJS1.ts, 1, 12)) +>Testing123 : Symbol(Testing123, Decl(decoratedClassExportsCommonJS1.ts, 0, 27)) + +export class Testing123 { +>Testing123 : Symbol(Testing123, Decl(decoratedClassExportsCommonJS1.ts, 0, 27)) + + static prop0: string; +>prop0 : Symbol(Testing123.prop0, Decl(decoratedClassExportsCommonJS1.ts, 2, 25)) + + static prop1 = Testing123.prop0; +>prop1 : Symbol(Testing123.prop1, Decl(decoratedClassExportsCommonJS1.ts, 3, 25)) +>Testing123.prop0 : Symbol(Testing123.prop0, Decl(decoratedClassExportsCommonJS1.ts, 2, 25)) +>Testing123 : Symbol(Testing123, Decl(decoratedClassExportsCommonJS1.ts, 0, 27)) +>prop0 : Symbol(Testing123.prop0, Decl(decoratedClassExportsCommonJS1.ts, 2, 25)) +} diff --git a/tests/baselines/reference/decoratedClassExportsCommonJS1.types b/tests/baselines/reference/decoratedClassExportsCommonJS1.types new file mode 100644 index 00000000000..0142adb654f --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsCommonJS1.types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts === +declare var Something: any; +>Something : any + +@Something({ v: () => Testing123 }) +>Something({ v: () => Testing123 }) : any +>Something : any +>{ v: () => Testing123 } : { v: () => typeof Testing123; } +>v : () => typeof Testing123 +>() => Testing123 : () => typeof Testing123 +>Testing123 : typeof Testing123 + +export class Testing123 { +>Testing123 : Testing123 + + static prop0: string; +>prop0 : string + + static prop1 = Testing123.prop0; +>prop1 : string +>Testing123.prop0 : string +>Testing123 : typeof Testing123 +>prop0 : string +} diff --git a/tests/baselines/reference/decoratedClassExportsCommonJS2.js b/tests/baselines/reference/decoratedClassExportsCommonJS2.js new file mode 100644 index 00000000000..c5e8eb9aa29 --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsCommonJS2.js @@ -0,0 +1,26 @@ +//// [a.ts] + +declare function forwardRef(x: any): any; +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { } + +//// [a.js] +"use strict"; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +let Testing123_1 = class Testing123 { +}; +let Testing123 = Testing123_1; +Testing123 = Testing123_1 = __decorate([ + Something({ v: () => Testing123 }), + __metadata('design:paramtypes', []) +], Testing123); +exports.Testing123 = Testing123; diff --git a/tests/baselines/reference/decoratedClassExportsCommonJS2.symbols b/tests/baselines/reference/decoratedClassExportsCommonJS2.symbols new file mode 100644 index 00000000000..8f587c1bff1 --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsCommonJS2.symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/decorators/class/a.ts === + +declare function forwardRef(x: any): any; +>forwardRef : Symbol(forwardRef, Decl(a.ts, 0, 0)) +>x : Symbol(x, Decl(a.ts, 1, 28)) + +declare var Something: any; +>Something : Symbol(Something, Decl(a.ts, 2, 11)) + +@Something({ v: () => Testing123 }) +>Something : Symbol(Something, Decl(a.ts, 2, 11)) +>v : Symbol(v, Decl(a.ts, 3, 12)) +>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27)) + +export class Testing123 { } +>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27)) + diff --git a/tests/baselines/reference/decoratedClassExportsCommonJS2.types b/tests/baselines/reference/decoratedClassExportsCommonJS2.types new file mode 100644 index 00000000000..eba793247de --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsCommonJS2.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/decorators/class/a.ts === + +declare function forwardRef(x: any): any; +>forwardRef : (x: any) => any +>x : any + +declare var Something: any; +>Something : any + +@Something({ v: () => Testing123 }) +>Something({ v: () => Testing123 }) : any +>Something : any +>{ v: () => Testing123 } : { v: () => typeof Testing123; } +>v : () => typeof Testing123 +>() => Testing123 : () => typeof Testing123 +>Testing123 : typeof Testing123 + +export class Testing123 { } +>Testing123 : Testing123 + diff --git a/tests/baselines/reference/decoratedClassExportsSystem1.js b/tests/baselines/reference/decoratedClassExportsSystem1.js new file mode 100644 index 00000000000..1730ba4460f --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsSystem1.js @@ -0,0 +1,39 @@ +//// [a.ts] + +declare function forwardRef(x: any): any; +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { + static prop0: string; + static prop1 = Testing123.prop0; +} + +//// [a.js] +System.register([], function(exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; + }; + var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); + }; + var Testing123; + return { + setters:[], + execute: function() { + let Testing123_1 = class Testing123 { + }; + let Testing123 = Testing123_1; + Testing123.prop1 = Testing123.prop0; + Testing123 = Testing123_1 = __decorate([ + Something({ v: () => Testing123 }), + __metadata('design:paramtypes', []) + ], Testing123); + exports_1("Testing123", Testing123); + } + } +}); diff --git a/tests/baselines/reference/decoratedClassExportsSystem1.symbols b/tests/baselines/reference/decoratedClassExportsSystem1.symbols new file mode 100644 index 00000000000..559f78624e3 --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsSystem1.symbols @@ -0,0 +1,26 @@ +=== tests/cases/conformance/decorators/class/a.ts === + +declare function forwardRef(x: any): any; +>forwardRef : Symbol(forwardRef, Decl(a.ts, 0, 0)) +>x : Symbol(x, Decl(a.ts, 1, 28)) + +declare var Something: any; +>Something : Symbol(Something, Decl(a.ts, 2, 11)) + +@Something({ v: () => Testing123 }) +>Something : Symbol(Something, Decl(a.ts, 2, 11)) +>v : Symbol(v, Decl(a.ts, 3, 12)) +>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27)) + +export class Testing123 { +>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27)) + + static prop0: string; +>prop0 : Symbol(Testing123.prop0, Decl(a.ts, 4, 25)) + + static prop1 = Testing123.prop0; +>prop1 : Symbol(Testing123.prop1, Decl(a.ts, 5, 25)) +>Testing123.prop0 : Symbol(Testing123.prop0, Decl(a.ts, 4, 25)) +>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27)) +>prop0 : Symbol(Testing123.prop0, Decl(a.ts, 4, 25)) +} diff --git a/tests/baselines/reference/decoratedClassExportsSystem1.types b/tests/baselines/reference/decoratedClassExportsSystem1.types new file mode 100644 index 00000000000..1cc69e8b680 --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsSystem1.types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/decorators/class/a.ts === + +declare function forwardRef(x: any): any; +>forwardRef : (x: any) => any +>x : any + +declare var Something: any; +>Something : any + +@Something({ v: () => Testing123 }) +>Something({ v: () => Testing123 }) : any +>Something : any +>{ v: () => Testing123 } : { v: () => typeof Testing123; } +>v : () => typeof Testing123 +>() => Testing123 : () => typeof Testing123 +>Testing123 : typeof Testing123 + +export class Testing123 { +>Testing123 : Testing123 + + static prop0: string; +>prop0 : string + + static prop1 = Testing123.prop0; +>prop1 : string +>Testing123.prop0 : string +>Testing123 : typeof Testing123 +>prop0 : string +} diff --git a/tests/baselines/reference/decoratedClassExportsSystem2.js b/tests/baselines/reference/decoratedClassExportsSystem2.js new file mode 100644 index 00000000000..b4d34de2958 --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsSystem2.js @@ -0,0 +1,35 @@ +//// [a.ts] + +declare function forwardRef(x: any): any; +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { } + +//// [a.js] +System.register([], function(exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; + }; + var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); + }; + var Testing123; + return { + setters:[], + execute: function() { + let Testing123_1 = class Testing123 { + }; + let Testing123 = Testing123_1; + Testing123 = Testing123_1 = __decorate([ + Something({ v: () => Testing123 }), + __metadata('design:paramtypes', []) + ], Testing123); + exports_1("Testing123", Testing123); + } + } +}); diff --git a/tests/baselines/reference/decoratedClassExportsSystem2.symbols b/tests/baselines/reference/decoratedClassExportsSystem2.symbols new file mode 100644 index 00000000000..8f587c1bff1 --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsSystem2.symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/decorators/class/a.ts === + +declare function forwardRef(x: any): any; +>forwardRef : Symbol(forwardRef, Decl(a.ts, 0, 0)) +>x : Symbol(x, Decl(a.ts, 1, 28)) + +declare var Something: any; +>Something : Symbol(Something, Decl(a.ts, 2, 11)) + +@Something({ v: () => Testing123 }) +>Something : Symbol(Something, Decl(a.ts, 2, 11)) +>v : Symbol(v, Decl(a.ts, 3, 12)) +>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27)) + +export class Testing123 { } +>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27)) + diff --git a/tests/baselines/reference/decoratedClassExportsSystem2.types b/tests/baselines/reference/decoratedClassExportsSystem2.types new file mode 100644 index 00000000000..eba793247de --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsSystem2.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/decorators/class/a.ts === + +declare function forwardRef(x: any): any; +>forwardRef : (x: any) => any +>x : any + +declare var Something: any; +>Something : any + +@Something({ v: () => Testing123 }) +>Something({ v: () => Testing123 }) : any +>Something : any +>{ v: () => Testing123 } : { v: () => typeof Testing123; } +>v : () => typeof Testing123 +>() => Testing123 : () => typeof Testing123 +>Testing123 : typeof Testing123 + +export class Testing123 { } +>Testing123 : Testing123 + diff --git a/tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts b/tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts new file mode 100644 index 00000000000..e00adf3d63b --- /dev/null +++ b/tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts @@ -0,0 +1,13 @@ +// @target: es6 +// @experimentaldecorators: true +// @emitDecoratorMetadata: true +// @module: commonjs +// @filename: a.ts + +declare function forwardRef(x: any): any; +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { + static prop0: string; + static prop1 = Testing123.prop0; +} \ No newline at end of file diff --git a/tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS2.ts b/tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS2.ts new file mode 100644 index 00000000000..38f6ce9f27d --- /dev/null +++ b/tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS2.ts @@ -0,0 +1,10 @@ +// @target: es6 +// @experimentaldecorators: true +// @emitDecoratorMetadata: true +// @module: commonjs +// @filename: a.ts + +declare function forwardRef(x: any): any; +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { } \ No newline at end of file diff --git a/tests/cases/conformance/decorators/class/decoratedClassExportsSystem1.ts b/tests/cases/conformance/decorators/class/decoratedClassExportsSystem1.ts new file mode 100644 index 00000000000..1e2619ab89e --- /dev/null +++ b/tests/cases/conformance/decorators/class/decoratedClassExportsSystem1.ts @@ -0,0 +1,13 @@ +// @target: es6 +// @experimentaldecorators: true +// @emitDecoratorMetadata: true +// @module: system +// @filename: a.ts + +declare function forwardRef(x: any): any; +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { + static prop0: string; + static prop1 = Testing123.prop0; +} \ No newline at end of file diff --git a/tests/cases/conformance/decorators/class/decoratedClassExportsSystem2.ts b/tests/cases/conformance/decorators/class/decoratedClassExportsSystem2.ts new file mode 100644 index 00000000000..bf7c9a0ca2d --- /dev/null +++ b/tests/cases/conformance/decorators/class/decoratedClassExportsSystem2.ts @@ -0,0 +1,10 @@ +// @target: es6 +// @experimentaldecorators: true +// @emitDecoratorMetadata: true +// @module: system +// @filename: a.ts + +declare function forwardRef(x: any): any; +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { } \ No newline at end of file From 7f045adc86ac09822fdecdbdc28c66edd9228aa4 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 18 Jul 2016 09:19:29 -0700 Subject: [PATCH 28/28] Code review comments --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 38c55efe6a3..d68502dc8e8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14614,7 +14614,7 @@ namespace ts { if (node.typeParameters) { // Only report errors on the last declaration for the type parameter container; // this ensures that all uses have been accounted for. - const symbol = node.symbol && getMergedSymbol(node.symbol); + const symbol = getSymbolOfNode(node); const lastDeclaration = symbol && symbol.declarations && lastOrUndefined(symbol.declarations); if (lastDeclaration !== node) { return;