From b7f4480656ad10221d4f87fa8150e73a03eaa0dc Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 26 Mar 2015 16:48:17 -0700 Subject: [PATCH 01/33] unify file extension resolution logic --- src/compiler/checker.ts | 5 +++-- src/compiler/core.ts | 10 ++++++---- src/compiler/program.ts | 14 ++++++-------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 04766f22c4e..c16b7ccda02 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -853,10 +853,11 @@ module ts { return symbol; } } + let fileName: string; let sourceFile: SourceFile; while (true) { - let fileName = normalizePath(combinePaths(searchPath, moduleName)); - sourceFile = host.getSourceFile(fileName + ".ts") || host.getSourceFile(fileName + ".d.ts"); + fileName = normalizePath(combinePaths(searchPath, moduleName)); + sourceFile = forEach(supportedExtensions, extension => host.getSourceFile(fileName + extension)); if (sourceFile || isRelative) { break; } diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 9b987ba77c6..92dc412889d 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -640,16 +640,18 @@ module ts { return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension; } - let supportedExtensions = [".d.ts", ".ts", ".js"]; + /** + * List of supported extensions in order of file resolution precedence. + */ + export const supportedExtensions = [".ts", ".d.ts"]; + const extensitionsToRemove = [".d.ts", ".ts", ".js"]; export function removeFileExtension(path: string): string { - for (let ext of supportedExtensions) { - + for (let ext of extensitionsToRemove) { if (fileExtensionIs(path, ext)) { return path.substr(0, path.length - ext.length); } } - return path; } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 3ebd8740faa..28fcdb73642 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -313,7 +313,7 @@ module ts { } let diagnostic: DiagnosticMessage; if (hasExtension(fileName)) { - if (!options.allowNonTsExtensions && !fileExtensionIs(host.getCanonicalFileName(fileName), ".ts")) { + if (!options.allowNonTsExtensions && !forEach(supportedExtensions, extension => fileExtensionIs(host.getCanonicalFileName(fileName), extension))) { diagnostic = Diagnostics.File_0_must_have_extension_ts_or_d_ts; } else if (!findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) { @@ -327,7 +327,7 @@ module ts { if (options.allowNonTsExtensions && !findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) { diagnostic = Diagnostics.File_0_not_found; } - else if (!findSourceFile(fileName + ".ts", isDefaultLib, refFile, refPos, refEnd) && !findSourceFile(fileName + ".d.ts", isDefaultLib, refFile, refPos, refEnd)) { + else if (!forEach(supportedExtensions, extension => findSourceFile(fileName + extension, isDefaultLib, refFile, refPos, refEnd))) { diagnostic = Diagnostics.File_0_not_found; fileName += ".ts"; } @@ -417,9 +417,10 @@ module ts { let moduleNameText = (moduleNameExpr).text; if (moduleNameText) { let searchPath = basePath; + let searchName: string; while (true) { - let searchName = normalizePath(combinePaths(searchPath, moduleNameText)); - if (findModuleSourceFile(searchName + ".ts", moduleNameExpr) || findModuleSourceFile(searchName + ".d.ts", moduleNameExpr)) { + searchName = normalizePath(combinePaths(searchPath, moduleNameText)); + if (forEach(supportedExtensions, extension => findModuleSourceFile(searchName + extension, moduleNameExpr))) { break; } let parentPath = getDirectoryPath(searchPath); @@ -448,10 +449,7 @@ module ts { // An ExternalImportDeclaration in anAmbientExternalModuleDeclaration may reference other external modules // only through top - level external module names. Relative external module names are not permitted. let searchName = normalizePath(combinePaths(basePath, moduleName)); - let tsFile = findModuleSourceFile(searchName + ".ts", nameLiteral); - if (!tsFile) { - findModuleSourceFile(searchName + ".d.ts", nameLiteral); - } + forEach(supportedExtensions, extension => findModuleSourceFile(searchName + extension, nameLiteral)); } } }); From cc41daab61785507ba46c7c9bb307444617f85ed Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 4 May 2015 23:30:01 -0700 Subject: [PATCH 02/33] Fix typo --- src/compiler/core.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 92dc412889d..9fe9747fb57 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -645,9 +645,9 @@ module ts { */ export const supportedExtensions = [".ts", ".d.ts"]; - const extensitionsToRemove = [".d.ts", ".ts", ".js"]; + const extensionsToRemove = [".d.ts", ".ts", ".js"]; export function removeFileExtension(path: string): string { - for (let ext of extensitionsToRemove) { + for (let ext of extensionsToRemove) { if (fileExtensionIs(path, ext)) { return path.substr(0, path.length - ext.length); } From 19933870a4d23bad8e97d4085f9db854504831ea Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 4 May 2015 23:30:43 -0700 Subject: [PATCH 03/33] Update error message --- src/compiler/diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- src/compiler/program.ts | 13 ++++++++++--- .../invalidRootFile/amd/invalidRootFile.errors.txt | 4 ++-- .../invalidRootFile/node/invalidRootFile.errors.txt | 4 ++-- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 14163e81195..0160a8dc46c 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -496,7 +496,7 @@ module ts { Corrupted_locale_file_0: { code: 6051, category: DiagnosticCategory.Error, key: "Corrupted locale file {0}." }, Raise_error_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: DiagnosticCategory.Message, key: "Raise error on expressions and declarations with an implied 'any' type." }, File_0_not_found: { code: 6053, category: DiagnosticCategory.Error, key: "File '{0}' not found." }, - File_0_must_have_extension_ts_or_d_ts: { code: 6054, category: DiagnosticCategory.Error, key: "File '{0}' must have extension '.ts' or '.d.ts'." }, + File_0_has_unsupported_extension_The_only_supported_extensions_are_1: { code: 6054, category: DiagnosticCategory.Error, key: "File '{0}' has unsupported extension. The only supported extensions are {1}." }, Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." }, Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." }, Preserve_new_lines_when_emitting_code: { code: 6057, category: DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 18c98928dda..d3255ff4aff 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1974,7 +1974,7 @@ "category": "Error", "code": 6053 }, - "File '{0}' must have extension '.ts' or '.d.ts'.": { + "File '{0}' has unsupported extension. The only supported extensions are {1}.": { "category": "Error", "code": 6054 }, diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 28fcdb73642..98b6927fc4c 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -307,6 +307,8 @@ module ts { function processSourceFile(fileName: string, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number) { let start: number; let length: number; + let extensions: string; + let diagnosticArgument: string[]; if (refEnd !== undefined && refPos !== undefined) { start = refPos; length = refEnd - refPos; @@ -314,31 +316,36 @@ module ts { let diagnostic: DiagnosticMessage; if (hasExtension(fileName)) { if (!options.allowNonTsExtensions && !forEach(supportedExtensions, extension => fileExtensionIs(host.getCanonicalFileName(fileName), extension))) { - diagnostic = Diagnostics.File_0_must_have_extension_ts_or_d_ts; + diagnostic = Diagnostics.File_0_has_unsupported_extension_The_only_supported_extensions_are_1; + diagnosticArgument = [fileName, "'" + supportedExtensions.join("', '") + "'"]; } else if (!findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) { diagnostic = Diagnostics.File_0_not_found; + diagnosticArgument = [fileName]; } else if (refFile && host.getCanonicalFileName(fileName) === host.getCanonicalFileName(refFile.fileName)) { diagnostic = Diagnostics.A_file_cannot_have_a_reference_to_itself; + diagnosticArgument = [fileName]; } } else { if (options.allowNonTsExtensions && !findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) { diagnostic = Diagnostics.File_0_not_found; + diagnosticArgument = [fileName]; } else if (!forEach(supportedExtensions, extension => findSourceFile(fileName + extension, isDefaultLib, refFile, refPos, refEnd))) { diagnostic = Diagnostics.File_0_not_found; fileName += ".ts"; + diagnosticArgument = [fileName]; } } if (diagnostic) { if (refFile) { - diagnostics.add(createFileDiagnostic(refFile, start, length, diagnostic, fileName)); + diagnostics.add(createFileDiagnostic(refFile, start, length, diagnostic, ...diagnosticArgument)); } else { - diagnostics.add(createCompilerDiagnostic(diagnostic, fileName)); + diagnostics.add(createCompilerDiagnostic(diagnostic, ...diagnosticArgument)); } } } diff --git a/tests/baselines/reference/project/invalidRootFile/amd/invalidRootFile.errors.txt b/tests/baselines/reference/project/invalidRootFile/amd/invalidRootFile.errors.txt index 25059478bf5..1bda32a0b4c 100644 --- a/tests/baselines/reference/project/invalidRootFile/amd/invalidRootFile.errors.txt +++ b/tests/baselines/reference/project/invalidRootFile/amd/invalidRootFile.errors.txt @@ -1,6 +1,6 @@ -error TS6054: File 'a.t' must have extension '.ts' or '.d.ts'. +error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.d.ts'. error TS6053: File 'a.ts' not found. -!!! error TS6054: File 'a.t' must have extension '.ts' or '.d.ts'. +!!! error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.d.ts'. !!! error TS6053: File 'a.ts' not found. \ No newline at end of file diff --git a/tests/baselines/reference/project/invalidRootFile/node/invalidRootFile.errors.txt b/tests/baselines/reference/project/invalidRootFile/node/invalidRootFile.errors.txt index 25059478bf5..1bda32a0b4c 100644 --- a/tests/baselines/reference/project/invalidRootFile/node/invalidRootFile.errors.txt +++ b/tests/baselines/reference/project/invalidRootFile/node/invalidRootFile.errors.txt @@ -1,6 +1,6 @@ -error TS6054: File 'a.t' must have extension '.ts' or '.d.ts'. +error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.d.ts'. error TS6053: File 'a.ts' not found. -!!! error TS6054: File 'a.t' must have extension '.ts' or '.d.ts'. +!!! error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.d.ts'. !!! error TS6053: File 'a.ts' not found. \ No newline at end of file From 170403fc531122da4954021afd33d9a5a58e20e5 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 5 May 2015 13:49:06 -0700 Subject: [PATCH 04/33] Remove isParameterDeclaration to utilities --- src/compiler/checker.ts | 7 ------- src/compiler/utilities.ts | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 04766f22c4e..3e694bc4a1a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9149,13 +9149,6 @@ module ts { } } - function isParameterDeclaration(node: VariableLikeDeclaration) { - while (node.kind === SyntaxKind.BindingElement) { - node = node.parent.parent; - } - return node.kind === SyntaxKind.Parameter; - } - // Check that a parameter initializer contains no references to parameters declared to the right of itself function checkParameterInitializer(node: VariableLikeDeclaration): void { if (getRootDeclaration(node).kind !== SyntaxKind.Parameter) { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 3e825c6802c..a3f6676119f 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1149,6 +1149,13 @@ module ts { } return false; } + + export function isParameterDeclaration(node: VariableLikeDeclaration) { + while (node.kind === SyntaxKind.BindingElement) { + node = node.parent.parent; + } + return node.kind === SyntaxKind.Parameter; + } export function nodeStartsNewLexicalEnvironment(n: Node): boolean { return isFunctionLike(n) || n.kind === SyntaxKind.ModuleDeclaration || n.kind === SyntaxKind.SourceFile; From 0fa240d232ceadc5c265aa93c2f41c72919446a8 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 5 May 2015 15:00:01 -0700 Subject: [PATCH 05/33] Check that bindingElement is in parameter declaration and pass in correct symbol exclusion flag --- src/compiler/binder.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 170f3d3c830..12c8b3e409c 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -440,6 +440,15 @@ module ts { else if (isBlockOrCatchScoped(node)) { bindBlockScopedVariableDeclaration(node); } + else if (isParameterDeclaration(node)) { + // If node is a binding element in parameter declaration, we need to use ParameterExcludes. + // Using ParameterExcludes flag allows the compiler to report an error on duplicate identifiers in Parameter Declaration + // For example: + // function foo([a,a]) {} // Duplicate Identifier error + // function bar(a,a) {} // Duplicate Identifier error, binding parameter declaration in this case is handled in bindParameter + // // which correctly set excluded symbols + bindDeclaration(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.ParameterExcludes, /*isBlockScopeContainer*/ false); + } else { bindDeclaration(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.FunctionScopedVariableExcludes, /*isBlockScopeContainer*/ false); } From d701f22a7d22428ae5605ec45645a2614692cc99 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 5 May 2015 15:00:41 -0700 Subject: [PATCH 06/33] update baselines --- .../declarationEmitDestructuring2.symbols | 40 -- .../declarationEmitDestructuring2.types | 68 --- .../destructuringParameterDeclaration1ES6.js | 4 +- ...tructuringParameterDeclaration1ES6.symbols | 314 ------------- ...estructuringParameterDeclaration1ES6.types | 422 ------------------ ...tructuringParameterDeclaration2.errors.txt | 13 +- .../destructuringParameterDeclaration2.js | 4 +- .../destructuringParameterDeclaration1ES6.ts | 2 +- .../destructuringParameterDeclaration2.ts | 2 +- 9 files changed, 17 insertions(+), 852 deletions(-) delete mode 100644 tests/baselines/reference/declarationEmitDestructuring2.symbols delete mode 100644 tests/baselines/reference/declarationEmitDestructuring2.types delete mode 100644 tests/baselines/reference/destructuringParameterDeclaration1ES6.symbols delete mode 100644 tests/baselines/reference/destructuringParameterDeclaration1ES6.types diff --git a/tests/baselines/reference/declarationEmitDestructuring2.symbols b/tests/baselines/reference/declarationEmitDestructuring2.symbols deleted file mode 100644 index 9cf35c1d866..00000000000 --- a/tests/baselines/reference/declarationEmitDestructuring2.symbols +++ /dev/null @@ -1,40 +0,0 @@ -=== tests/cases/compiler/declarationEmitDestructuring2.ts === -function f({x = 10, y: [a, b, c, d] = [1, 2, 3, 4]} = { x: 10, y: [2, 4, 6, 8] }) { } ->f : Symbol(f, Decl(declarationEmitDestructuring2.ts, 0, 0)) ->x : Symbol(x, Decl(declarationEmitDestructuring2.ts, 0, 12)) ->a : Symbol(a, Decl(declarationEmitDestructuring2.ts, 0, 24)) ->b : Symbol(b, Decl(declarationEmitDestructuring2.ts, 0, 26)) ->c : Symbol(c, Decl(declarationEmitDestructuring2.ts, 0, 29)) ->d : Symbol(d, Decl(declarationEmitDestructuring2.ts, 0, 32)) ->x : Symbol(x, Decl(declarationEmitDestructuring2.ts, 0, 55)) ->y : Symbol(y, Decl(declarationEmitDestructuring2.ts, 0, 62)) - -function g([a, b, c, d] = [1, 2, 3, 4]) { } ->g : Symbol(g, Decl(declarationEmitDestructuring2.ts, 0, 85)) ->a : Symbol(a, Decl(declarationEmitDestructuring2.ts, 1, 12)) ->b : Symbol(b, Decl(declarationEmitDestructuring2.ts, 1, 14)) ->c : Symbol(c, Decl(declarationEmitDestructuring2.ts, 1, 17)) ->d : Symbol(d, Decl(declarationEmitDestructuring2.ts, 1, 20)) - -function h([a, [b], [[c]], {x = 10, y: [a, b, c], z: {a1, b1}}]){ } ->h : Symbol(h, Decl(declarationEmitDestructuring2.ts, 1, 43)) ->a : Symbol(a, Decl(declarationEmitDestructuring2.ts, 2, 12), Decl(declarationEmitDestructuring2.ts, 2, 40)) ->b : Symbol(b, Decl(declarationEmitDestructuring2.ts, 2, 16), Decl(declarationEmitDestructuring2.ts, 2, 42)) ->c : Symbol(c, Decl(declarationEmitDestructuring2.ts, 2, 22), Decl(declarationEmitDestructuring2.ts, 2, 45)) ->x : Symbol(x, Decl(declarationEmitDestructuring2.ts, 2, 28)) ->a : Symbol(a, Decl(declarationEmitDestructuring2.ts, 2, 12), Decl(declarationEmitDestructuring2.ts, 2, 40)) ->b : Symbol(b, Decl(declarationEmitDestructuring2.ts, 2, 16), Decl(declarationEmitDestructuring2.ts, 2, 42)) ->c : Symbol(c, Decl(declarationEmitDestructuring2.ts, 2, 22), Decl(declarationEmitDestructuring2.ts, 2, 45)) ->a1 : Symbol(a1, Decl(declarationEmitDestructuring2.ts, 2, 54)) ->b1 : Symbol(b1, Decl(declarationEmitDestructuring2.ts, 2, 57)) - -function h1([a, [b], [[c]], {x = 10, y = [1, 2, 3], z: {a1, b1}}]){ } ->h1 : Symbol(h1, Decl(declarationEmitDestructuring2.ts, 2, 67)) ->a : Symbol(a, Decl(declarationEmitDestructuring2.ts, 3, 13)) ->b : Symbol(b, Decl(declarationEmitDestructuring2.ts, 3, 17)) ->c : Symbol(c, Decl(declarationEmitDestructuring2.ts, 3, 23)) ->x : Symbol(x, Decl(declarationEmitDestructuring2.ts, 3, 29)) ->y : Symbol(y, Decl(declarationEmitDestructuring2.ts, 3, 36)) ->a1 : Symbol(a1, Decl(declarationEmitDestructuring2.ts, 3, 56)) ->b1 : Symbol(b1, Decl(declarationEmitDestructuring2.ts, 3, 59)) - diff --git a/tests/baselines/reference/declarationEmitDestructuring2.types b/tests/baselines/reference/declarationEmitDestructuring2.types deleted file mode 100644 index 619ad13d084..00000000000 --- a/tests/baselines/reference/declarationEmitDestructuring2.types +++ /dev/null @@ -1,68 +0,0 @@ -=== tests/cases/compiler/declarationEmitDestructuring2.ts === -function f({x = 10, y: [a, b, c, d] = [1, 2, 3, 4]} = { x: 10, y: [2, 4, 6, 8] }) { } ->f : ({x = 10, y: [a, b, c, d] = [1, 2, 3, 4]}?: { x: number; y: [number, number, number, number]; }) => void ->x : number ->10 : number ->y : any ->a : number ->b : number ->c : number ->d : number ->[1, 2, 3, 4] : [number, number, number, number] ->1 : number ->2 : number ->3 : number ->4 : number ->{ x: 10, y: [2, 4, 6, 8] } : { x: number; y: [number, number, number, number]; } ->x : number ->10 : number ->y : [number, number, number, number] ->[2, 4, 6, 8] : [number, number, number, number] ->2 : number ->4 : number ->6 : number ->8 : number - -function g([a, b, c, d] = [1, 2, 3, 4]) { } ->g : ([a, b, c, d]?: [number, number, number, number]) => void ->a : number ->b : number ->c : number ->d : number ->[1, 2, 3, 4] : [number, number, number, number] ->1 : number ->2 : number ->3 : number ->4 : number - -function h([a, [b], [[c]], {x = 10, y: [a, b, c], z: {a1, b1}}]){ } ->h : ([a, [b], [[c]], {x = 10, y: [a, b, c], z: {a1, b1}}]: [any, [any], [[any]], { x?: number; y: [any, any, any]; z: { a1: any; b1: any; }; }]) => void ->a : any ->b : any ->c : any ->x : number ->10 : number ->y : any ->a : any ->b : any ->c : any ->z : any ->a1 : any ->b1 : any - -function h1([a, [b], [[c]], {x = 10, y = [1, 2, 3], z: {a1, b1}}]){ } ->h1 : ([a, [b], [[c]], {x = 10, y = [1, 2, 3], z: {a1, b1}}]: [any, [any], [[any]], { x?: number; y?: number[]; z: { a1: any; b1: any; }; }]) => void ->a : any ->b : any ->c : any ->x : number ->10 : number ->y : number[] ->[1, 2, 3] : number[] ->1 : number ->2 : number ->3 : number ->z : any ->a1 : any ->b1 : any - diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.js b/tests/baselines/reference/destructuringParameterDeclaration1ES6.js index 6310a8f638e..f5c79c5fe88 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES6.js +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES6.js @@ -94,7 +94,7 @@ function e3({x}: { x?: number }) { } // x is an optional with type number function e4({x: [number,string,any] }) { } // x has type [any, any, any] function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] -function e6({x: [number, number, number]}) { } // should be an error, duplicate identifier; +function e6({x: [number, number, number]}) { } // error, duplicate identifier; @@ -166,4 +166,4 @@ function e2({ x }) { } // x is type number function e3({ x }) { } // x is an optional with type number function e4({ x: [number, string, any] }) { } // x has type [any, any, any] function e5({ x: [a, b, c] }) { } // x has type [any, any, any] -function e6({ x: [number, number, number] }) { } // should be an error, duplicate identifier; +function e6({ x: [number, number, number] }) { } // error, duplicate identifier; diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.symbols b/tests/baselines/reference/destructuringParameterDeclaration1ES6.symbols deleted file mode 100644 index 3267d4470db..00000000000 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES6.symbols +++ /dev/null @@ -1,314 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts === -// Conformance for emitting ES6 - -// A parameter declaration may specify either an identifier or a binding pattern. -// The identifiers specified in parameter declarations and binding patterns -// in a parameter list must be unique within that parameter list. - -// If the declaration includes a type annotation, the parameter is of that type -function a1([a, b, [[c]]]: [number, number, string[][]]) { } ->a1 : Symbol(a1, Decl(destructuringParameterDeclaration1ES6.ts, 0, 0)) ->a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 7, 13)) ->b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 7, 15)) ->c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 7, 21)) - -function a2(o: { x: number, a: number }) { } ->a2 : Symbol(a2, Decl(destructuringParameterDeclaration1ES6.ts, 7, 60)) ->o : Symbol(o, Decl(destructuringParameterDeclaration1ES6.ts, 8, 12)) ->x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 8, 16)) ->a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 8, 27)) - -function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { }; ->a3 : Symbol(a3, Decl(destructuringParameterDeclaration1ES6.ts, 8, 44)) ->j : Symbol(j, Decl(destructuringParameterDeclaration1ES6.ts, 9, 13)) ->k : Symbol(k, Decl(destructuringParameterDeclaration1ES6.ts, 9, 15)) ->m : Symbol(m, Decl(destructuringParameterDeclaration1ES6.ts, 9, 23)) ->n : Symbol(n, Decl(destructuringParameterDeclaration1ES6.ts, 9, 25)) ->a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 9, 34)) ->b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 9, 36)) ->c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 9, 39)) ->j : Symbol(j, Decl(destructuringParameterDeclaration1ES6.ts, 9, 46)) ->k : Symbol(k, Decl(destructuringParameterDeclaration1ES6.ts, 9, 57)) ->l : Symbol(l, Decl(destructuringParameterDeclaration1ES6.ts, 9, 68)) ->m : Symbol(m, Decl(destructuringParameterDeclaration1ES6.ts, 9, 73)) ->n : Symbol(n, Decl(destructuringParameterDeclaration1ES6.ts, 9, 85)) ->q : Symbol(q, Decl(destructuringParameterDeclaration1ES6.ts, 9, 98)) - -function a4({x, a}: { x: number, a: number }) { } ->a4 : Symbol(a4, Decl(destructuringParameterDeclaration1ES6.ts, 9, 127)) ->x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 10, 13)) ->a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 10, 15)) ->x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 10, 21)) ->a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 10, 32)) - -a1([1, 2, [["world"]]]); ->a1 : Symbol(a1, Decl(destructuringParameterDeclaration1ES6.ts, 0, 0)) - -a1([1, 2, [["world"]], 3]); ->a1 : Symbol(a1, Decl(destructuringParameterDeclaration1ES6.ts, 0, 0)) - - -// If the declaration includes an initializer expression (which is permitted only -// when the parameter list occurs in conjunction with a function body), -// the parameter type is the widened form (section 3.11) of the type of the initializer expression. - -function b1(z = [undefined, null]) { }; ->b1 : Symbol(b1, Decl(destructuringParameterDeclaration1ES6.ts, 13, 27)) ->z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 20, 12)) ->undefined : Symbol(undefined) - -function b2(z = null, o = { x: 0, y: undefined }) { } ->b2 : Symbol(b2, Decl(destructuringParameterDeclaration1ES6.ts, 20, 39)) ->z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 21, 12)) ->o : Symbol(o, Decl(destructuringParameterDeclaration1ES6.ts, 21, 21)) ->x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 21, 27)) ->y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 21, 33)) ->undefined : Symbol(undefined) - -function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } ->b3 : Symbol(b3, Decl(destructuringParameterDeclaration1ES6.ts, 21, 53)) ->x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 22, 17)) ->j : Symbol(j, Decl(destructuringParameterDeclaration1ES6.ts, 22, 24)) ->z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 22, 32)) ->x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 22, 37)) ->y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 22, 46)) ->j : Symbol(j, Decl(destructuringParameterDeclaration1ES6.ts, 22, 51)) - -interface F1 { ->F1 : Symbol(F1, Decl(destructuringParameterDeclaration1ES6.ts, 22, 67)) - - b5(z, y, [, a, b], {p, m: { q, r}}); ->b5 : Symbol(b5, Decl(destructuringParameterDeclaration1ES6.ts, 24, 14)) ->z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 25, 7)) ->y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 25, 9)) ->a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 25, 15)) ->b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 25, 18)) ->p : Symbol(p, Decl(destructuringParameterDeclaration1ES6.ts, 25, 24)) ->q : Symbol(q, Decl(destructuringParameterDeclaration1ES6.ts, 25, 31)) ->r : Symbol(r, Decl(destructuringParameterDeclaration1ES6.ts, 25, 34)) -} - -function b6([a, z, y] = [undefined, null, undefined]) { } ->b6 : Symbol(b6, Decl(destructuringParameterDeclaration1ES6.ts, 26, 1)) ->a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 28, 13)) ->z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 28, 15)) ->y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 28, 18)) ->undefined : Symbol(undefined) ->undefined : Symbol(undefined) - -function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } ->b7 : Symbol(b7, Decl(destructuringParameterDeclaration1ES6.ts, 28, 57)) ->a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 29, 14)) ->b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 29, 17)) ->c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 29, 23)) ->d : Symbol(d, Decl(destructuringParameterDeclaration1ES6.ts, 29, 25)) ->undefined : Symbol(undefined) ->undefined : Symbol(undefined) ->undefined : Symbol(undefined) ->undefined : Symbol(undefined) - -b1([1, 2, 3]); // z is widen to the type any[] ->b1 : Symbol(b1, Decl(destructuringParameterDeclaration1ES6.ts, 13, 27)) - -b2("string", { x: 200, y: "string" }); ->b2 : Symbol(b2, Decl(destructuringParameterDeclaration1ES6.ts, 20, 39)) ->x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 32, 14)) ->y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 32, 22)) - -b2("string", { x: 200, y: true }); ->b2 : Symbol(b2, Decl(destructuringParameterDeclaration1ES6.ts, 20, 39)) ->x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 33, 14)) ->y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 33, 22)) - - -// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) -enum Foo { a } ->Foo : Symbol(Foo, Decl(destructuringParameterDeclaration1ES6.ts, 33, 34)) ->a : Symbol(Foo.a, Decl(destructuringParameterDeclaration1ES6.ts, 37, 10)) - -function c0({z: {x, y: {j}}}) { } ->c0 : Symbol(c0, Decl(destructuringParameterDeclaration1ES6.ts, 37, 14)) ->x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 38, 17)) ->j : Symbol(j, Decl(destructuringParameterDeclaration1ES6.ts, 38, 24)) - -function c1({z} = { z: 10 }) { } ->c1 : Symbol(c1, Decl(destructuringParameterDeclaration1ES6.ts, 38, 33)) ->z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 39, 13)) ->z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 39, 19)) - -function c2({z = 10}) { } ->c2 : Symbol(c2, Decl(destructuringParameterDeclaration1ES6.ts, 39, 32)) ->z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 40, 13)) - -function c3({b}: { b: number|string} = { b: "hello" }) { } ->c3 : Symbol(c3, Decl(destructuringParameterDeclaration1ES6.ts, 40, 25)) ->b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 41, 13)) ->b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 41, 18)) ->b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 41, 40)) - -function c5([a, b, [[c]]]) { } ->c5 : Symbol(c5, Decl(destructuringParameterDeclaration1ES6.ts, 41, 58)) ->a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 42, 13)) ->b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 42, 15)) ->c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 42, 21)) - -function c6([a, b, [[c=1]]]) { } ->c6 : Symbol(c6, Decl(destructuringParameterDeclaration1ES6.ts, 42, 30)) ->a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 43, 13)) ->b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 43, 15)) ->c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 43, 21)) - -c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} } ->c0 : Symbol(c0, Decl(destructuringParameterDeclaration1ES6.ts, 37, 14)) ->z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 45, 4)) ->x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 45, 9)) ->y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 45, 15)) ->j : Symbol(j, Decl(destructuringParameterDeclaration1ES6.ts, 45, 20)) - -c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} } ->c0 : Symbol(c0, Decl(destructuringParameterDeclaration1ES6.ts, 37, 14)) ->z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 46, 4)) ->x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 46, 9)) ->y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 46, 22)) ->j : Symbol(j, Decl(destructuringParameterDeclaration1ES6.ts, 46, 27)) - -c1(); // Implied type is {z:number}? ->c1 : Symbol(c1, Decl(destructuringParameterDeclaration1ES6.ts, 38, 33)) - -c1({ z: 1 }) // Implied type is {z:number}? ->c1 : Symbol(c1, Decl(destructuringParameterDeclaration1ES6.ts, 38, 33)) ->z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 49, 4)) - -c2({}); // Implied type is {z?: number} ->c2 : Symbol(c2, Decl(destructuringParameterDeclaration1ES6.ts, 39, 32)) - -c2({z:1}); // Implied type is {z?: number} ->c2 : Symbol(c2, Decl(destructuringParameterDeclaration1ES6.ts, 39, 32)) ->z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 52, 4)) - -c3({ b: 1 }); // Implied type is { b: number|string }. ->c3 : Symbol(c3, Decl(destructuringParameterDeclaration1ES6.ts, 40, 25)) ->b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 54, 4)) - -c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] ->c5 : Symbol(c5, Decl(destructuringParameterDeclaration1ES6.ts, 41, 58)) - -c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] ->c5 : Symbol(c5, Decl(destructuringParameterDeclaration1ES6.ts, 41, 58)) - - -// A parameter can be marked optional by following its name or binding pattern with a question mark (?) -// or by including an initializer. - -interface F2 { ->F2 : Symbol(F2, Decl(destructuringParameterDeclaration1ES6.ts, 57, 38)) - - d3([a, b, c]?); ->d3 : Symbol(d3, Decl(destructuringParameterDeclaration1ES6.ts, 63, 14)) ->a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 64, 8)) ->b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 64, 10)) ->c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 64, 13)) - - d4({x, y, z}?); ->d4 : Symbol(d4, Decl(destructuringParameterDeclaration1ES6.ts, 64, 19)) ->x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 65, 8)) ->y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 65, 10)) ->z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 65, 13)) - - e0([a, b, c]); ->e0 : Symbol(e0, Decl(destructuringParameterDeclaration1ES6.ts, 65, 19)) ->a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 66, 8)) ->b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 66, 10)) ->c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 66, 13)) -} - -class C2 implements F2 { ->C2 : Symbol(C2, Decl(destructuringParameterDeclaration1ES6.ts, 67, 1)) ->F2 : Symbol(F2, Decl(destructuringParameterDeclaration1ES6.ts, 57, 38)) - - constructor() { } - d3() { } ->d3 : Symbol(d3, Decl(destructuringParameterDeclaration1ES6.ts, 70, 21)) - - d4() { } ->d4 : Symbol(d4, Decl(destructuringParameterDeclaration1ES6.ts, 71, 12)) - - e0([a, b, c]) { } ->e0 : Symbol(e0, Decl(destructuringParameterDeclaration1ES6.ts, 72, 12)) ->a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 73, 8)) ->b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 73, 10)) ->c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 73, 13)) -} - -class C3 implements F2 { ->C3 : Symbol(C3, Decl(destructuringParameterDeclaration1ES6.ts, 74, 1)) ->F2 : Symbol(F2, Decl(destructuringParameterDeclaration1ES6.ts, 57, 38)) - - d3([a, b, c]) { } ->d3 : Symbol(d3, Decl(destructuringParameterDeclaration1ES6.ts, 76, 24)) ->a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 77, 8)) ->b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 77, 10)) ->c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 77, 13)) - - d4({x, y, z}) { } ->d4 : Symbol(d4, Decl(destructuringParameterDeclaration1ES6.ts, 77, 21)) ->x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 78, 8)) ->y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 78, 10)) ->z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 78, 13)) - - e0([a, b, c]) { } ->e0 : Symbol(e0, Decl(destructuringParameterDeclaration1ES6.ts, 78, 21)) ->a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 79, 8)) ->b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 79, 10)) ->c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 79, 13)) -} - -function d5({x, y} = { x: 1, y: 2 }) { } ->d5 : Symbol(d5, Decl(destructuringParameterDeclaration1ES6.ts, 80, 1)) ->x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 82, 13)) ->y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 82, 15)) ->x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 82, 22)) ->y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 82, 28)) - -d5(); // Parameter is optional as its declaration included an initializer ->d5 : Symbol(d5, Decl(destructuringParameterDeclaration1ES6.ts, 80, 1)) - -// Destructuring parameter declarations do not permit type annotations on the individual binding patterns, -// as such annotations would conflict with the already established meaning of colons in object literals. -// Type annotations must instead be written on the top- level parameter declaration - -function e1({x: number}) { } // x has type any NOT number ->e1 : Symbol(e1, Decl(destructuringParameterDeclaration1ES6.ts, 83, 5)) ->number : Symbol(number, Decl(destructuringParameterDeclaration1ES6.ts, 89, 13)) - -function e2({x}: { x: number }) { } // x is type number ->e2 : Symbol(e2, Decl(destructuringParameterDeclaration1ES6.ts, 89, 28)) ->x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 90, 13)) ->x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 90, 18)) - -function e3({x}: { x?: number }) { } // x is an optional with type number ->e3 : Symbol(e3, Decl(destructuringParameterDeclaration1ES6.ts, 90, 35)) ->x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 91, 13)) ->x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 91, 18)) - -function e4({x: [number,string,any] }) { } // x has type [any, any, any] ->e4 : Symbol(e4, Decl(destructuringParameterDeclaration1ES6.ts, 91, 36)) ->number : Symbol(number, Decl(destructuringParameterDeclaration1ES6.ts, 92, 17)) ->string : Symbol(string, Decl(destructuringParameterDeclaration1ES6.ts, 92, 24)) ->any : Symbol(any, Decl(destructuringParameterDeclaration1ES6.ts, 92, 31)) - -function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] ->e5 : Symbol(e5, Decl(destructuringParameterDeclaration1ES6.ts, 92, 42)) ->a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 93, 17)) ->b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 93, 19)) ->c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 93, 22)) ->x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 93, 29)) - -function e6({x: [number, number, number]}) { } // should be an error, duplicate identifier; ->e6 : Symbol(e6, Decl(destructuringParameterDeclaration1ES6.ts, 93, 64)) ->number : Symbol(number, Decl(destructuringParameterDeclaration1ES6.ts, 95, 17), Decl(destructuringParameterDeclaration1ES6.ts, 95, 24), Decl(destructuringParameterDeclaration1ES6.ts, 95, 32)) ->number : Symbol(number, Decl(destructuringParameterDeclaration1ES6.ts, 95, 17), Decl(destructuringParameterDeclaration1ES6.ts, 95, 24), Decl(destructuringParameterDeclaration1ES6.ts, 95, 32)) ->number : Symbol(number, Decl(destructuringParameterDeclaration1ES6.ts, 95, 17), Decl(destructuringParameterDeclaration1ES6.ts, 95, 24), Decl(destructuringParameterDeclaration1ES6.ts, 95, 32)) - - - diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.types b/tests/baselines/reference/destructuringParameterDeclaration1ES6.types deleted file mode 100644 index 9395fa49b5b..00000000000 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES6.types +++ /dev/null @@ -1,422 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts === -// Conformance for emitting ES6 - -// A parameter declaration may specify either an identifier or a binding pattern. -// The identifiers specified in parameter declarations and binding patterns -// in a parameter list must be unique within that parameter list. - -// If the declaration includes a type annotation, the parameter is of that type -function a1([a, b, [[c]]]: [number, number, string[][]]) { } ->a1 : ([a, b, [[c]]]: [number, number, string[][]]) => void ->a : number ->b : number ->c : string - -function a2(o: { x: number, a: number }) { } ->a2 : (o: { x: number; a: number; }) => void ->o : { x: number; a: number; } ->x : number ->a : number - -function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { }; ->a3 : ({j, k, l: {m, n}, q: [a, b, c]}: { j: number; k: string; l: { m: boolean; n: number; }; q: (string | number)[]; }) => void ->j : number ->k : string ->l : any ->m : boolean ->n : number ->q : any ->a : string | number ->b : string | number ->c : string | number ->j : number ->k : string ->l : { m: boolean; n: number; } ->m : boolean ->n : number ->q : (string | number)[] - -function a4({x, a}: { x: number, a: number }) { } ->a4 : ({x, a}: { x: number; a: number; }) => void ->x : number ->a : number ->x : number ->a : number - -a1([1, 2, [["world"]]]); ->a1([1, 2, [["world"]]]) : void ->a1 : ([a, b, [[c]]]: [number, number, string[][]]) => void ->[1, 2, [["world"]]] : [number, number, string[][]] ->1 : number ->2 : number ->[["world"]] : string[][] ->["world"] : string[] ->"world" : string - -a1([1, 2, [["world"]], 3]); ->a1([1, 2, [["world"]], 3]) : void ->a1 : ([a, b, [[c]]]: [number, number, string[][]]) => void ->[1, 2, [["world"]], 3] : [number, number, string[][], number] ->1 : number ->2 : number ->[["world"]] : string[][] ->["world"] : string[] ->"world" : string ->3 : number - - -// If the declaration includes an initializer expression (which is permitted only -// when the parameter list occurs in conjunction with a function body), -// the parameter type is the widened form (section 3.11) of the type of the initializer expression. - -function b1(z = [undefined, null]) { }; ->b1 : (z?: any[]) => void ->z : any[] ->[undefined, null] : null[] ->undefined : undefined ->null : null - -function b2(z = null, o = { x: 0, y: undefined }) { } ->b2 : (z?: any, o?: { x: number; y: any; }) => void ->z : any ->null : null ->o : { x: number; y: any; } ->{ x: 0, y: undefined } : { x: number; y: undefined; } ->x : number ->0 : number ->y : undefined ->undefined : undefined - -function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } ->b3 : ({z: {x, y: {j}}}?: { z: { x: string; y: { j: number; }; }; }) => void ->z : any ->x : string ->y : any ->j : number ->{ z: { x: "hi", y: { j: 1 } } } : { z: { x: string; y: { j: number; }; }; } ->z : { x: string; y: { j: number; }; } ->{ x: "hi", y: { j: 1 } } : { x: string; y: { j: number; }; } ->x : string ->"hi" : string ->y : { j: number; } ->{ j: 1 } : { j: number; } ->j : number ->1 : number - -interface F1 { ->F1 : F1 - - b5(z, y, [, a, b], {p, m: { q, r}}); ->b5 : (z: any, y: any, [, a, b]: [any, any, any], {p, m: { q, r}}: { p: any; m: { q: any; r: any; }; }) => any ->z : any ->y : any -> : undefined ->a : any ->b : any ->p : any ->m : any ->q : any ->r : any -} - -function b6([a, z, y] = [undefined, null, undefined]) { } ->b6 : ([a, z, y]?: [undefined, null, undefined]) => void ->a : any ->z : any ->y : any ->[undefined, null, undefined] : [undefined, null, undefined] ->undefined : undefined ->null : null ->undefined : undefined - -function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } ->b7 : ([[a], b, [[c, d]]]?: [[undefined], undefined, [[undefined, undefined]]]) => void ->a : any ->b : any ->c : any ->d : any ->[[undefined], undefined, [[undefined, undefined]]] : [[undefined], undefined, [[undefined, undefined]]] ->[undefined] : [undefined] ->undefined : undefined ->undefined : undefined ->[[undefined, undefined]] : [[undefined, undefined]] ->[undefined, undefined] : [undefined, undefined] ->undefined : undefined ->undefined : undefined - -b1([1, 2, 3]); // z is widen to the type any[] ->b1([1, 2, 3]) : void ->b1 : (z?: any[]) => void ->[1, 2, 3] : number[] ->1 : number ->2 : number ->3 : number - -b2("string", { x: 200, y: "string" }); ->b2("string", { x: 200, y: "string" }) : void ->b2 : (z?: any, o?: { x: number; y: any; }) => void ->"string" : string ->{ x: 200, y: "string" } : { x: number; y: string; } ->x : number ->200 : number ->y : string ->"string" : string - -b2("string", { x: 200, y: true }); ->b2("string", { x: 200, y: true }) : void ->b2 : (z?: any, o?: { x: number; y: any; }) => void ->"string" : string ->{ x: 200, y: true } : { x: number; y: boolean; } ->x : number ->200 : number ->y : boolean ->true : boolean - - -// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) -enum Foo { a } ->Foo : Foo ->a : Foo - -function c0({z: {x, y: {j}}}) { } ->c0 : ({z: {x, y: {j}}}: { z: { x: any; y: { j: any; }; }; }) => void ->z : any ->x : any ->y : any ->j : any - -function c1({z} = { z: 10 }) { } ->c1 : ({z}?: { z: number; }) => void ->z : number ->{ z: 10 } : { z: number; } ->z : number ->10 : number - -function c2({z = 10}) { } ->c2 : ({z = 10}: { z?: number; }) => void ->z : number ->10 : number - -function c3({b}: { b: number|string} = { b: "hello" }) { } ->c3 : ({b}?: { b: string | number; }) => void ->b : string | number ->b : string | number ->{ b: "hello" } : { b: string; } ->b : string ->"hello" : string - -function c5([a, b, [[c]]]) { } ->c5 : ([a, b, [[c]]]: [any, any, [[any]]]) => void ->a : any ->b : any ->c : any - -function c6([a, b, [[c=1]]]) { } ->c6 : ([a, b, [[c=1]]]: [any, any, [[number]]]) => void ->a : any ->b : any ->c : number ->1 : number - -c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} } ->c0({z : { x: 1, y: { j: "world" } }}) : void ->c0 : ({z: {x, y: {j}}}: { z: { x: any; y: { j: any; }; }; }) => void ->{z : { x: 1, y: { j: "world" } }} : { z: { x: number; y: { j: string; }; }; } ->z : { x: number; y: { j: string; }; } ->{ x: 1, y: { j: "world" } } : { x: number; y: { j: string; }; } ->x : number ->1 : number ->y : { j: string; } ->{ j: "world" } : { j: string; } ->j : string ->"world" : string - -c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} } ->c0({z : { x: "string", y: { j: true } }}) : void ->c0 : ({z: {x, y: {j}}}: { z: { x: any; y: { j: any; }; }; }) => void ->{z : { x: "string", y: { j: true } }} : { z: { x: string; y: { j: boolean; }; }; } ->z : { x: string; y: { j: boolean; }; } ->{ x: "string", y: { j: true } } : { x: string; y: { j: boolean; }; } ->x : string ->"string" : string ->y : { j: boolean; } ->{ j: true } : { j: boolean; } ->j : boolean ->true : boolean - -c1(); // Implied type is {z:number}? ->c1() : void ->c1 : ({z}?: { z: number; }) => void - -c1({ z: 1 }) // Implied type is {z:number}? ->c1({ z: 1 }) : void ->c1 : ({z}?: { z: number; }) => void ->{ z: 1 } : { z: number; } ->z : number ->1 : number - -c2({}); // Implied type is {z?: number} ->c2({}) : void ->c2 : ({z = 10}: { z?: number; }) => void ->{} : {} - -c2({z:1}); // Implied type is {z?: number} ->c2({z:1}) : void ->c2 : ({z = 10}: { z?: number; }) => void ->{z:1} : { z: number; } ->z : number ->1 : number - -c3({ b: 1 }); // Implied type is { b: number|string }. ->c3({ b: 1 }) : void ->c3 : ({b}?: { b: string | number; }) => void ->{ b: 1 } : { b: number; } ->b : number ->1 : number - -c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] ->c5([1, 2, [["string"]]]) : void ->c5 : ([a, b, [[c]]]: [any, any, [[any]]]) => void ->[1, 2, [["string"]]] : [number, number, [[string]]] ->1 : number ->2 : number ->[["string"]] : [[string]] ->["string"] : [string] ->"string" : string - -c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] ->c5([1, 2, [["string"]], false, true]) : void ->c5 : ([a, b, [[c]]]: [any, any, [[any]]]) => void ->[1, 2, [["string"]], false, true] : [number, number, [[string]], boolean, boolean] ->1 : number ->2 : number ->[["string"]] : [[string]] ->["string"] : [string] ->"string" : string ->false : boolean ->true : boolean - - -// A parameter can be marked optional by following its name or binding pattern with a question mark (?) -// or by including an initializer. - -interface F2 { ->F2 : F2 - - d3([a, b, c]?); ->d3 : ([a, b, c]?: [any, any, any]) => any ->a : any ->b : any ->c : any - - d4({x, y, z}?); ->d4 : ({x, y, z}?: { x: any; y: any; z: any; }) => any ->x : any ->y : any ->z : any - - e0([a, b, c]); ->e0 : ([a, b, c]: [any, any, any]) => any ->a : any ->b : any ->c : any -} - -class C2 implements F2 { ->C2 : C2 ->F2 : F2 - - constructor() { } - d3() { } ->d3 : () => void - - d4() { } ->d4 : () => void - - e0([a, b, c]) { } ->e0 : ([a, b, c]: [any, any, any]) => void ->a : any ->b : any ->c : any -} - -class C3 implements F2 { ->C3 : C3 ->F2 : F2 - - d3([a, b, c]) { } ->d3 : ([a, b, c]: [any, any, any]) => void ->a : any ->b : any ->c : any - - d4({x, y, z}) { } ->d4 : ({x, y, z}: { x: any; y: any; z: any; }) => void ->x : any ->y : any ->z : any - - e0([a, b, c]) { } ->e0 : ([a, b, c]: [any, any, any]) => void ->a : any ->b : any ->c : any -} - -function d5({x, y} = { x: 1, y: 2 }) { } ->d5 : ({x, y}?: { x: number; y: number; }) => void ->x : number ->y : number ->{ x: 1, y: 2 } : { x: number; y: number; } ->x : number ->1 : number ->y : number ->2 : number - -d5(); // Parameter is optional as its declaration included an initializer ->d5() : void ->d5 : ({x, y}?: { x: number; y: number; }) => void - -// Destructuring parameter declarations do not permit type annotations on the individual binding patterns, -// as such annotations would conflict with the already established meaning of colons in object literals. -// Type annotations must instead be written on the top- level parameter declaration - -function e1({x: number}) { } // x has type any NOT number ->e1 : ({x: number}: { x: any; }) => void ->x : any ->number : any - -function e2({x}: { x: number }) { } // x is type number ->e2 : ({x}: { x: number; }) => void ->x : number ->x : number - -function e3({x}: { x?: number }) { } // x is an optional with type number ->e3 : ({x}: { x?: number; }) => void ->x : number ->x : number - -function e4({x: [number,string,any] }) { } // x has type [any, any, any] ->e4 : ({x: [number,string,any] }: { x: [any, any, any]; }) => void ->x : any ->number : any ->string : any ->any : any - -function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] ->e5 : ({x: [a, b, c]}: { x: [number, number, number]; }) => void ->x : any ->a : number ->b : number ->c : number ->x : [number, number, number] - -function e6({x: [number, number, number]}) { } // should be an error, duplicate identifier; ->e6 : ({x: [number, number, number]}: { x: [any, any, any]; }) => void ->x : any ->number : any ->number : any ->number : any - - - diff --git a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt index 11af7b0d17c..12f50d6886c 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt @@ -50,9 +50,12 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts( Type '{ x: any; y: any; c: any; }' is not assignable to type '{ x: any; y: any; z: any; }'. Property 'z' is missing in type '{ x: any; y: any; c: any; }'. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(56,8): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(65,18): error TS2300: Duplicate identifier 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(65,26): error TS2300: Duplicate identifier 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(65,34): error TS2300: Duplicate identifier 'number'. -==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts (19 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts (22 errors) ==== // A parameter declaration may specify either an identifier or a binding pattern. // The identifiers specified in parameter declarations and binding patterns // in a parameter list must be unique within that parameter list. @@ -188,7 +191,13 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts( // as such annotations would conflict with the already established meaning of colons in object literals. // Type annotations must instead be written on the top- level parameter declaration - function e0({x: [number, number, number]}) { } // should be an error, duplicate identifier; + function e0({x: [number, number, number]}) { } // error, duplicate identifier; + ~~~~~~ +!!! error TS2300: Duplicate identifier 'number'. + ~~~~~~ +!!! error TS2300: Duplicate identifier 'number'. + ~~~~~~ +!!! error TS2300: Duplicate identifier 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration2.js b/tests/baselines/reference/destructuringParameterDeclaration2.js index 8033ff7eeae..dcb2c87f25b 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration2.js +++ b/tests/baselines/reference/destructuringParameterDeclaration2.js @@ -63,7 +63,7 @@ class C4 implements F2 { // as such annotations would conflict with the already established meaning of colons in object literals. // Type annotations must instead be written on the top- level parameter declaration -function e0({x: [number, number, number]}) { } // should be an error, duplicate identifier; +function e0({x: [number, number, number]}) { } // error, duplicate identifier; @@ -146,4 +146,4 @@ var C4 = (function () { // Type annotations must instead be written on the top- level parameter declaration function e0(_a) { var _b = _a.x, number = _b[0], number = _b[1], number = _b[2]; -} // should be an error, duplicate identifier; +} // error, duplicate identifier; diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts index 58d69729b98..b66e14f017b 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts @@ -94,6 +94,6 @@ function e3({x}: { x?: number }) { } // x is an optional with type number function e4({x: [number,string,any] }) { } // x has type [any, any, any] function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] -function e6({x: [number, number, number]}) { } // should be an error, duplicate identifier; +function e6({x: [number, number, number]}) { } // error, duplicate identifier; diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts index 19f508c0625..48858044932 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts @@ -62,6 +62,6 @@ class C4 implements F2 { // as such annotations would conflict with the already established meaning of colons in object literals. // Type annotations must instead be written on the top- level parameter declaration -function e0({x: [number, number, number]}) { } // should be an error, duplicate identifier; +function e0({x: [number, number, number]}) { } // error, duplicate identifier; From cabfdba7327a5e2c738c7488f4b6f4b470c191eb Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 5 May 2015 15:01:01 -0700 Subject: [PATCH 07/33] Add tests for duplicate identifier in parameter declaration --- .../declarationEmitDestructuring2.errors.txt | 25 ++++ ...cturingParameterDeclaration1ES6.errors.txt | 111 ++++++++++++++++++ ...gElementInParameterDeclaration1.errors.txt | 70 +++++++++++ ...erBindingElementInParameterDeclaration1.js | 39 ++++++ ...gElementInParameterDeclaration2.errors.txt | 71 +++++++++++ ...erBindingElementInParameterDeclaration2.js | 41 +++++++ ...erBindingElementInParameterDeclaration1.ts | 10 ++ ...erBindingElementInParameterDeclaration2.ts | 11 ++ 8 files changed, 378 insertions(+) create mode 100644 tests/baselines/reference/declarationEmitDestructuring2.errors.txt create mode 100644 tests/baselines/reference/destructuringParameterDeclaration1ES6.errors.txt create mode 100644 tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration1.errors.txt create mode 100644 tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration1.js create mode 100644 tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration2.errors.txt create mode 100644 tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration2.js create mode 100644 tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts create mode 100644 tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts diff --git a/tests/baselines/reference/declarationEmitDestructuring2.errors.txt b/tests/baselines/reference/declarationEmitDestructuring2.errors.txt new file mode 100644 index 00000000000..4e8561e83ad --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuring2.errors.txt @@ -0,0 +1,25 @@ +tests/cases/compiler/declarationEmitDestructuring2.ts(3,13): error TS2300: Duplicate identifier 'a'. +tests/cases/compiler/declarationEmitDestructuring2.ts(3,17): error TS2300: Duplicate identifier 'b'. +tests/cases/compiler/declarationEmitDestructuring2.ts(3,23): error TS2300: Duplicate identifier 'c'. +tests/cases/compiler/declarationEmitDestructuring2.ts(3,41): error TS2300: Duplicate identifier 'a'. +tests/cases/compiler/declarationEmitDestructuring2.ts(3,44): error TS2300: Duplicate identifier 'b'. +tests/cases/compiler/declarationEmitDestructuring2.ts(3,47): error TS2300: Duplicate identifier 'c'. + + +==== tests/cases/compiler/declarationEmitDestructuring2.ts (6 errors) ==== + function f({x = 10, y: [a, b, c, d] = [1, 2, 3, 4]} = { x: 10, y: [2, 4, 6, 8] }) { } + function g([a, b, c, d] = [1, 2, 3, 4]) { } + function h([a, [b], [[c]], {x = 10, y: [a, b, c], z: {a1, b1}}]){ } + ~ +!!! error TS2300: Duplicate identifier 'a'. + ~ +!!! error TS2300: Duplicate identifier 'b'. + ~ +!!! error TS2300: Duplicate identifier 'c'. + ~ +!!! error TS2300: Duplicate identifier 'a'. + ~ +!!! error TS2300: Duplicate identifier 'b'. + ~ +!!! error TS2300: Duplicate identifier 'c'. + function h1([a, [b], [[c]], {x = 10, y = [1, 2, 3], z: {a1, b1}}]){ } \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration1ES6.errors.txt new file mode 100644 index 00000000000..e900b9be393 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES6.errors.txt @@ -0,0 +1,111 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(96,18): error TS2300: Duplicate identifier 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(96,26): error TS2300: Duplicate identifier 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(96,34): error TS2300: Duplicate identifier 'number'. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts (3 errors) ==== + // Conformance for emitting ES6 + + // A parameter declaration may specify either an identifier or a binding pattern. + // The identifiers specified in parameter declarations and binding patterns + // in a parameter list must be unique within that parameter list. + + // If the declaration includes a type annotation, the parameter is of that type + function a1([a, b, [[c]]]: [number, number, string[][]]) { } + function a2(o: { x: number, a: number }) { } + function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { }; + function a4({x, a}: { x: number, a: number }) { } + + a1([1, 2, [["world"]]]); + a1([1, 2, [["world"]], 3]); + + + // If the declaration includes an initializer expression (which is permitted only + // when the parameter list occurs in conjunction with a function body), + // the parameter type is the widened form (section 3.11) of the type of the initializer expression. + + function b1(z = [undefined, null]) { }; + function b2(z = null, o = { x: 0, y: undefined }) { } + function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } + + interface F1 { + b5(z, y, [, a, b], {p, m: { q, r}}); + } + + function b6([a, z, y] = [undefined, null, undefined]) { } + function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } + + b1([1, 2, 3]); // z is widen to the type any[] + b2("string", { x: 200, y: "string" }); + b2("string", { x: 200, y: true }); + + + // If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) + enum Foo { a } + function c0({z: {x, y: {j}}}) { } + function c1({z} = { z: 10 }) { } + function c2({z = 10}) { } + function c3({b}: { b: number|string} = { b: "hello" }) { } + function c5([a, b, [[c]]]) { } + function c6([a, b, [[c=1]]]) { } + + c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} } + c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} } + + c1(); // Implied type is {z:number}? + c1({ z: 1 }) // Implied type is {z:number}? + + c2({}); // Implied type is {z?: number} + c2({z:1}); // Implied type is {z?: number} + + c3({ b: 1 }); // Implied type is { b: number|string }. + + c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] + c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] + + + // A parameter can be marked optional by following its name or binding pattern with a question mark (?) + // or by including an initializer. + + interface F2 { + d3([a, b, c]?); + d4({x, y, z}?); + e0([a, b, c]); + } + + class C2 implements F2 { + constructor() { } + d3() { } + d4() { } + e0([a, b, c]) { } + } + + class C3 implements F2 { + d3([a, b, c]) { } + d4({x, y, z}) { } + e0([a, b, c]) { } + } + + function d5({x, y} = { x: 1, y: 2 }) { } + d5(); // Parameter is optional as its declaration included an initializer + + // Destructuring parameter declarations do not permit type annotations on the individual binding patterns, + // as such annotations would conflict with the already established meaning of colons in object literals. + // Type annotations must instead be written on the top- level parameter declaration + + function e1({x: number}) { } // x has type any NOT number + function e2({x}: { x: number }) { } // x is type number + function e3({x}: { x?: number }) { } // x is an optional with type number + function e4({x: [number,string,any] }) { } // x has type [any, any, any] + function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] + + function e6({x: [number, number, number]}) { } // error, duplicate identifier; + ~~~~~~ +!!! error TS2300: Duplicate identifier 'number'. + ~~~~~~ +!!! error TS2300: Duplicate identifier 'number'. + ~~~~~~ +!!! error TS2300: Duplicate identifier 'number'. + + + \ No newline at end of file diff --git a/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration1.errors.txt b/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration1.errors.txt new file mode 100644 index 00000000000..62872f6c806 --- /dev/null +++ b/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration1.errors.txt @@ -0,0 +1,70 @@ +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(2,13): error TS2300: Duplicate identifier 'a'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(2,17): error TS2300: Duplicate identifier 'a'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(2,21): error TS2300: Duplicate identifier 'b'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(2,27): error TS2300: Duplicate identifier 'b'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(3,14): error TS2300: Duplicate identifier 'a'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(3,17): error TS2300: Duplicate identifier 'a'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(4,14): error TS2300: Duplicate identifier 'b'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(4,19): error TS2300: Duplicate identifier 'b'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(5,14): error TS2300: Duplicate identifier 'c'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(5,17): error TS2300: Duplicate identifier 'c'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(5,22): error TS2300: Duplicate identifier 'c'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(6,14): error TS2300: Duplicate identifier 'd'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(6,20): error TS2300: Duplicate identifier 'd'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(7,14): error TS2300: Duplicate identifier 'e'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(7,21): error TS2300: Duplicate identifier 'e'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(7,27): error TS2300: Duplicate identifier 'e'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(7,34): error TS2300: Duplicate identifier 'e'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(7,39): error TS2300: Duplicate identifier 'e'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(7,48): error TS2300: Duplicate identifier 'e'. + + +==== tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts (19 errors) ==== + + function f0(a, [a, [b]], {b}) { } + ~ +!!! error TS2300: Duplicate identifier 'a'. + ~ +!!! error TS2300: Duplicate identifier 'a'. + ~ +!!! error TS2300: Duplicate identifier 'b'. + ~ +!!! error TS2300: Duplicate identifier 'b'. + function f1([a, a]) { } + ~ +!!! error TS2300: Duplicate identifier 'a'. + ~ +!!! error TS2300: Duplicate identifier 'a'. + function f2({b}, {b}) { } + ~ +!!! error TS2300: Duplicate identifier 'b'. + ~ +!!! error TS2300: Duplicate identifier 'b'. + function f3([c,[c],[[c]]]) { } + ~ +!!! error TS2300: Duplicate identifier 'c'. + ~ +!!! error TS2300: Duplicate identifier 'c'. + ~ +!!! error TS2300: Duplicate identifier 'c'. + function f4({d, d:{d}}) { } + ~ +!!! error TS2300: Duplicate identifier 'd'. + ~ +!!! error TS2300: Duplicate identifier 'd'. + function f5({e, e: {e}}, {e}, [d,e, [[e]]], ...e) { } + ~ +!!! error TS2300: Duplicate identifier 'e'. + ~ +!!! error TS2300: Duplicate identifier 'e'. + ~ +!!! error TS2300: Duplicate identifier 'e'. + ~ +!!! error TS2300: Duplicate identifier 'e'. + ~ +!!! error TS2300: Duplicate identifier 'e'. + ~ +!!! error TS2300: Duplicate identifier 'e'. + + + \ No newline at end of file diff --git a/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration1.js b/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration1.js new file mode 100644 index 00000000000..cdf70b29835 --- /dev/null +++ b/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration1.js @@ -0,0 +1,39 @@ +//// [duplicateIdentifierBindingElementInParameterDeclaration1.ts] + +function f0(a, [a, [b]], {b}) { } +function f1([a, a]) { } +function f2({b}, {b}) { } +function f3([c,[c],[[c]]]) { } +function f4({d, d:{d}}) { } +function f5({e, e: {e}}, {e}, [d,e, [[e]]], ...e) { } + + + + +//// [duplicateIdentifierBindingElementInParameterDeclaration1.js] +function f0(a, _a, _b) { + var a = _a[0], b = _a[1][0]; + var b = _b.b; +} +function f1(_a) { + var a = _a[0], a = _a[1]; +} +function f2(_a, _b) { + var b = _a.b; + var b = _b.b; +} +function f3(_a) { + var c = _a[0], c = _a[1][0], c = _a[2][0][0]; +} +function f4(_a) { + var d = _a.d, d = _a.d.d; +} +function f5(_a, _b, _c) { + var e = _a.e, e = _a.e.e; + var e = _b.e; + var d = _c[0], e = _c[1], e = _c[2][0][0]; + var e = []; + for (var _i = 3; _i < arguments.length; _i++) { + e[_i - 3] = arguments[_i]; + } +} diff --git a/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration2.errors.txt b/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration2.errors.txt new file mode 100644 index 00000000000..8a6df4b075b --- /dev/null +++ b/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration2.errors.txt @@ -0,0 +1,71 @@ +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(3,13): error TS2300: Duplicate identifier 'a'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(3,17): error TS2300: Duplicate identifier 'a'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(3,21): error TS2300: Duplicate identifier 'b'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(3,27): error TS2300: Duplicate identifier 'b'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(4,14): error TS2300: Duplicate identifier 'a'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(4,17): error TS2300: Duplicate identifier 'a'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(5,14): error TS2300: Duplicate identifier 'b'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(5,19): error TS2300: Duplicate identifier 'b'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(6,14): error TS2300: Duplicate identifier 'c'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(6,18): error TS2300: Duplicate identifier 'c'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(6,24): error TS2300: Duplicate identifier 'c'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(7,14): error TS2300: Duplicate identifier 'd'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(7,21): error TS2300: Duplicate identifier 'd'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(8,14): error TS2300: Duplicate identifier 'e'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(8,21): error TS2300: Duplicate identifier 'e'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(8,27): error TS2300: Duplicate identifier 'e'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(8,35): error TS2300: Duplicate identifier 'e'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(8,40): error TS2300: Duplicate identifier 'e'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(8,49): error TS2300: Duplicate identifier 'e'. + + +==== tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts (19 errors) ==== + + "use strict" + function f0(a, [a, [b]], {b}) { } + ~ +!!! error TS2300: Duplicate identifier 'a'. + ~ +!!! error TS2300: Duplicate identifier 'a'. + ~ +!!! error TS2300: Duplicate identifier 'b'. + ~ +!!! error TS2300: Duplicate identifier 'b'. + function f1([a, a]) { } + ~ +!!! error TS2300: Duplicate identifier 'a'. + ~ +!!! error TS2300: Duplicate identifier 'a'. + function f2({b}, {b}) { } + ~ +!!! error TS2300: Duplicate identifier 'b'. + ~ +!!! error TS2300: Duplicate identifier 'b'. + function f3([c, [c], [[c]]]) { } + ~ +!!! error TS2300: Duplicate identifier 'c'. + ~ +!!! error TS2300: Duplicate identifier 'c'. + ~ +!!! error TS2300: Duplicate identifier 'c'. + function f4({d, d: {d}}) { } + ~ +!!! error TS2300: Duplicate identifier 'd'. + ~ +!!! error TS2300: Duplicate identifier 'd'. + function f5({e, e: {e}}, {e}, [d, e, [[e]]], ...e) { } + ~ +!!! error TS2300: Duplicate identifier 'e'. + ~ +!!! error TS2300: Duplicate identifier 'e'. + ~ +!!! error TS2300: Duplicate identifier 'e'. + ~ +!!! error TS2300: Duplicate identifier 'e'. + ~ +!!! error TS2300: Duplicate identifier 'e'. + ~ +!!! error TS2300: Duplicate identifier 'e'. + + + \ No newline at end of file diff --git a/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration2.js b/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration2.js new file mode 100644 index 00000000000..46f59c6c96d --- /dev/null +++ b/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration2.js @@ -0,0 +1,41 @@ +//// [duplicateIdentifierBindingElementInParameterDeclaration2.ts] + +"use strict" +function f0(a, [a, [b]], {b}) { } +function f1([a, a]) { } +function f2({b}, {b}) { } +function f3([c, [c], [[c]]]) { } +function f4({d, d: {d}}) { } +function f5({e, e: {e}}, {e}, [d, e, [[e]]], ...e) { } + + + + +//// [duplicateIdentifierBindingElementInParameterDeclaration2.js] +"use strict"; +function f0(a, _a, _b) { + var a = _a[0], b = _a[1][0]; + var b = _b.b; +} +function f1(_a) { + var a = _a[0], a = _a[1]; +} +function f2(_a, _b) { + var b = _a.b; + var b = _b.b; +} +function f3(_a) { + var c = _a[0], c = _a[1][0], c = _a[2][0][0]; +} +function f4(_a) { + var d = _a.d, d = _a.d.d; +} +function f5(_a, _b, _c) { + var e = _a.e, e = _a.e.e; + var e = _b.e; + var d = _c[0], e = _c[1], e = _c[2][0][0]; + var e = []; + for (var _i = 3; _i < arguments.length; _i++) { + e[_i - 3] = arguments[_i]; + } +} diff --git a/tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts b/tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts new file mode 100644 index 00000000000..e5c5965301e --- /dev/null +++ b/tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts @@ -0,0 +1,10 @@ +// @target: es5 + +function f0(a, [a, [b]], {b}) { } +function f1([a, a]) { } +function f2({b}, {b}) { } +function f3([c,[c],[[c]]]) { } +function f4({d, d:{d}}) { } +function f5({e, e: {e}}, {e}, [d,e, [[e]]], ...e) { } + + diff --git a/tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts b/tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts new file mode 100644 index 00000000000..0ed6100ca34 --- /dev/null +++ b/tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts @@ -0,0 +1,11 @@ +// @target: es5 + +"use strict" +function f0(a, [a, [b]], {b}) { } +function f1([a, a]) { } +function f2({b}, {b}) { } +function f3([c, [c], [[c]]]) { } +function f4({d, d: {d}}) { } +function f5({e, e: {e}}, {e}, [d, e, [[e]]], ...e) { } + + From 0bd0b2798c53f23e1a37b2b7aa30937ef9fed5d1 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 5 May 2015 15:11:14 -0700 Subject: [PATCH 08/33] Update comment --- src/compiler/binder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 12c8b3e409c..eddd0c3178c 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -445,7 +445,7 @@ module ts { // Using ParameterExcludes flag allows the compiler to report an error on duplicate identifiers in Parameter Declaration // For example: // function foo([a,a]) {} // Duplicate Identifier error - // function bar(a,a) {} // Duplicate Identifier error, binding parameter declaration in this case is handled in bindParameter + // function bar(a,a) {} // Duplicate Identifier error, parameter declaration in this case is handled in bindParameter // // which correctly set excluded symbols bindDeclaration(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.ParameterExcludes, /*isBlockScopeContainer*/ false); } From ac9b16cff351909866c23155f2d6c4b9d8f534c1 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 6 May 2015 20:11:31 -0700 Subject: [PATCH 09/33] refactor narrowTypeByInstanceof --- src/compiler/checker.ts | 54 ++++++++++--------- ...nstanceOfByConstructorSignature.errors.txt | 16 ++++-- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4c5712299da..d43661c97b6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5384,38 +5384,42 @@ module ts { if (!isTypeSubtypeOf(rightType, globalFunctionType)) { return type; } - // Target type is type of prototype property + + let targetType: Type; let prototypeProperty = getPropertyOfType(rightType, "prototype"); if (prototypeProperty) { - let targetType = getTypeOfSymbol(prototypeProperty); - if (targetType !== anyType) { - // Narrow to the target type if it's a subtype of the current type - if (isTypeSubtypeOf(targetType, type)) { - return targetType; - } - // If the current type is a union type, remove all constituents that aren't subtypes of the target. - if (type.flags & TypeFlags.Union) { - return getUnionType(filter((type).types, t => isTypeSubtypeOf(t, targetType))); - } + // Target type is type of the protoype property + let prototypePropertyType = getTypeOfSymbol(prototypeProperty); + if (prototypePropertyType !== anyType) { + targetType = prototypePropertyType; } } - // Target type is type of construct signature - let constructSignatures: Signature[]; - if (rightType.flags & TypeFlags.Interface) { - constructSignatures = resolveDeclaredMembers(rightType).declaredConstructSignatures; - } - else if (rightType.flags & TypeFlags.Anonymous) { - constructSignatures = getSignaturesOfType(rightType, SignatureKind.Construct); - } - if (constructSignatures && constructSignatures.length !== 0) { - let instanceType = getUnionType(map(constructSignatures, signature => getReturnTypeOfSignature(getErasedSignature(signature)))); - // Pickup type from union types - if (type.flags & TypeFlags.Union) { - return getUnionType(filter((type).types, t => isTypeSubtypeOf(t, instanceType))); + if (!targetType) { + // Target type is type of construct signature + let constructSignatures: Signature[]; + if (rightType.flags & TypeFlags.Interface) { + constructSignatures = resolveDeclaredMembers(rightType).declaredConstructSignatures; + } + else if (rightType.flags & TypeFlags.Anonymous) { + constructSignatures = getSignaturesOfType(rightType, SignatureKind.Construct); + } + if (constructSignatures && constructSignatures.length) { + targetType = getUnionType(map(constructSignatures, signature => getReturnTypeOfSignature(getErasedSignature(signature)))); } - return instanceType; } + + if (targetType) { + // Narrow to the target type if it's a subtype of the current type + if (isTypeSubtypeOf(targetType, type)) { + return targetType; + } + // If the current type is a union type, remove all constituents that aren't subtypes of the target. + if (type.flags & TypeFlags.Union) { + return getUnionType(filter((type).types, t => isTypeSubtypeOf(t, targetType))); + } + } + return type; } diff --git a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt index b963b2c33ae..be1a0e5a2c3 100644 --- a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt +++ b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt @@ -1,16 +1,18 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(12,10): error TS2339: Property 'bar' does not exist on type 'A'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(33,5): error TS2322: Type 'string' is not assignable to type 'number'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(34,10): error TS2339: Property 'bar' does not exist on type 'B'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(63,10): error TS2339: Property 'bar2' does not exist on type 'C1'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(62,10): error TS2339: Property 'bar1' does not exist on type 'C1 | C2'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(63,10): error TS2339: Property 'bar2' does not exist on type 'C1 | C2'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(82,10): error TS2339: Property 'bar' does not exist on type 'D'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(109,10): error TS2339: Property 'bar2' does not exist on type 'E1'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(108,10): error TS2339: Property 'bar1' does not exist on type 'E1 | E2'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(109,10): error TS2339: Property 'bar2' does not exist on type 'E1 | E2'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(131,11): error TS2339: Property 'foo' does not exist on type 'string | F'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(132,11): error TS2339: Property 'bar' does not exist on type 'string | F'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(157,11): error TS2339: Property 'foo2' does not exist on type 'G1'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(179,11): error TS2339: Property 'bar' does not exist on type 'H'. -==== tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts (10 errors) ==== +==== tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts (12 errors) ==== interface AConstructor { new (): A; } @@ -79,9 +81,11 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru if (obj5 instanceof C) { // narrowed to C1. obj5.foo; obj5.bar1; + ~~~~ +!!! error TS2339: Property 'bar1' does not exist on type 'C1 | C2'. obj5.bar2; ~~~~ -!!! error TS2339: Property 'bar2' does not exist on type 'C1'. +!!! error TS2339: Property 'bar2' does not exist on type 'C1 | C2'. } var obj6: any; @@ -129,9 +133,11 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru if (obj9 instanceof E) { // narrowed to E1. obj9.foo; obj9.bar1; + ~~~~ +!!! error TS2339: Property 'bar1' does not exist on type 'E1 | E2'. obj9.bar2; ~~~~ -!!! error TS2339: Property 'bar2' does not exist on type 'E1'. +!!! error TS2339: Property 'bar2' does not exist on type 'E1 | E2'. } var obj10: any; From 8b43b3d18c65a355c2e54d76cf20ccb424bd156e Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 6 May 2015 20:18:32 -0700 Subject: [PATCH 10/33] Update test --- ...nstanceOfByConstructorSignature.errors.txt | 25 +++++++++++-------- ...rdsWithInstanceOfByConstructorSignature.js | 8 ++++-- ...rdsWithInstanceOfByConstructorSignature.ts | 7 ++++-- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt index be1a0e5a2c3..4960940d3ab 100644 --- a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt +++ b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt @@ -1,15 +1,15 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(12,10): error TS2339: Property 'bar' does not exist on type 'A'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(33,5): error TS2322: Type 'string' is not assignable to type 'number'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(34,10): error TS2339: Property 'bar' does not exist on type 'B'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(62,10): error TS2339: Property 'bar1' does not exist on type 'C1 | C2'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(63,10): error TS2339: Property 'bar2' does not exist on type 'C1 | C2'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(82,10): error TS2339: Property 'bar' does not exist on type 'D'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(108,10): error TS2339: Property 'bar1' does not exist on type 'E1 | E2'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(109,10): error TS2339: Property 'bar2' does not exist on type 'E1 | E2'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(131,11): error TS2339: Property 'foo' does not exist on type 'string | F'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(132,11): error TS2339: Property 'bar' does not exist on type 'string | F'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(157,11): error TS2339: Property 'foo2' does not exist on type 'G1'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(179,11): error TS2339: Property 'bar' does not exist on type 'H'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(65,10): error TS2339: Property 'bar1' does not exist on type 'C1 | C2'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(66,10): error TS2339: Property 'bar2' does not exist on type 'C1 | C2'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(85,10): error TS2339: Property 'bar' does not exist on type 'D'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(111,10): error TS2339: Property 'bar1' does not exist on type 'E1 | E2'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(112,10): error TS2339: Property 'bar2' does not exist on type 'E1 | E2'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(134,11): error TS2339: Property 'foo' does not exist on type 'string | F'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(135,11): error TS2339: Property 'bar' does not exist on type 'string | F'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(160,11): error TS2339: Property 'foo2' does not exist on type 'G1'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(182,11): error TS2339: Property 'bar' does not exist on type 'H'. ==== tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts (12 errors) ==== @@ -69,17 +69,20 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru } interface C1 { foo: string; + c: string; bar1: number; } interface C2 { foo: string; + c: string; bar2: number; } declare var C: CConstructor; var obj5: C1 | A; - if (obj5 instanceof C) { // narrowed to C1. + if (obj5 instanceof C) { // narrowed to C1|C2. obj5.foo; + obj5.c; obj5.bar1; ~~~~ !!! error TS2339: Property 'bar1' does not exist on type 'C1 | C2'. @@ -130,7 +133,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru declare var E: EConstructor; var obj9: E1 | A; - if (obj9 instanceof E) { // narrowed to E1. + if (obj9 instanceof E) { // narrowed to E1 | E2 obj9.foo; obj9.bar1; ~~~~ diff --git a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.js b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.js index e5b12bacb1f..7e6b3324470 100644 --- a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.js +++ b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.js @@ -49,17 +49,20 @@ interface CConstructor { } interface C1 { foo: string; + c: string; bar1: number; } interface C2 { foo: string; + c: string; bar2: number; } declare var C: CConstructor; var obj5: C1 | A; -if (obj5 instanceof C) { // narrowed to C1. +if (obj5 instanceof C) { // narrowed to C1|C2. obj5.foo; + obj5.c; obj5.bar1; obj5.bar2; } @@ -104,7 +107,7 @@ interface E2 { declare var E: EConstructor; var obj9: E1 | A; -if (obj9 instanceof E) { // narrowed to E1. +if (obj9 instanceof E) { // narrowed to E1 | E2 obj9.foo; obj9.bar1; obj9.bar2; @@ -213,6 +216,7 @@ if (obj4 instanceof B) { var obj5; if (obj5 instanceof C) { obj5.foo; + obj5.c; obj5.bar1; obj5.bar2; } diff --git a/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts b/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts index fee92ff10ca..b81dd26652b 100644 --- a/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts +++ b/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts @@ -48,17 +48,20 @@ interface CConstructor { } interface C1 { foo: string; + c: string; bar1: number; } interface C2 { foo: string; + c: string; bar2: number; } declare var C: CConstructor; var obj5: C1 | A; -if (obj5 instanceof C) { // narrowed to C1. +if (obj5 instanceof C) { // narrowed to C1|C2. obj5.foo; + obj5.c; obj5.bar1; obj5.bar2; } @@ -103,7 +106,7 @@ interface E2 { declare var E: EConstructor; var obj9: E1 | A; -if (obj9 instanceof E) { // narrowed to E1. +if (obj9 instanceof E) { // narrowed to E1 | E2 obj9.foo; obj9.bar1; obj9.bar2; From 42b56cf671030a552e5f68c906fca7c07800cf2c Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 6 May 2015 20:25:12 -0700 Subject: [PATCH 11/33] Add a regression test --- .../reference/narrowTypeByInstanceof.js | 53 ++++++++++++ .../reference/narrowTypeByInstanceof.symbols | 72 ++++++++++++++++ .../reference/narrowTypeByInstanceof.types | 86 +++++++++++++++++++ .../cases/compiler/narrowTypeByInstanceof.ts | 24 ++++++ 4 files changed, 235 insertions(+) create mode 100644 tests/baselines/reference/narrowTypeByInstanceof.js create mode 100644 tests/baselines/reference/narrowTypeByInstanceof.symbols create mode 100644 tests/baselines/reference/narrowTypeByInstanceof.types create mode 100644 tests/cases/compiler/narrowTypeByInstanceof.ts diff --git a/tests/baselines/reference/narrowTypeByInstanceof.js b/tests/baselines/reference/narrowTypeByInstanceof.js new file mode 100644 index 00000000000..11f55089bda --- /dev/null +++ b/tests/baselines/reference/narrowTypeByInstanceof.js @@ -0,0 +1,53 @@ +//// [narrowTypeByInstanceof.ts] + class Match { + public range(): any { + return undefined; + } + } + + class FileMatch { + public resource(): any { + return undefined; + } + } + +type FileMatchOrMatch = FileMatch | Match; + + +let elementA: FileMatchOrMatch, elementB: FileMatchOrMatch; + +if (elementA instanceof FileMatch && elementB instanceof FileMatch) { + let a = elementA.resource().path; + let b = elementB.resource().path; +} else if (elementA instanceof Match && elementB instanceof Match) { + let a = elementA.range(); + let b = elementB.range(); +} + + +//// [narrowTypeByInstanceof.js] +var Match = (function () { + function Match() { + } + Match.prototype.range = function () { + return undefined; + }; + return Match; +})(); +var FileMatch = (function () { + function FileMatch() { + } + FileMatch.prototype.resource = function () { + return undefined; + }; + return FileMatch; +})(); +var elementA, elementB; +if (elementA instanceof FileMatch && elementB instanceof FileMatch) { + var a = elementA.resource().path; + var b = elementB.resource().path; +} +else if (elementA instanceof Match && elementB instanceof Match) { + var a = elementA.range(); + var b = elementB.range(); +} diff --git a/tests/baselines/reference/narrowTypeByInstanceof.symbols b/tests/baselines/reference/narrowTypeByInstanceof.symbols new file mode 100644 index 00000000000..3e620fd105c --- /dev/null +++ b/tests/baselines/reference/narrowTypeByInstanceof.symbols @@ -0,0 +1,72 @@ +=== tests/cases/compiler/narrowTypeByInstanceof.ts === + class Match { +>Match : Symbol(Match, Decl(narrowTypeByInstanceof.ts, 0, 0)) + + public range(): any { +>range : Symbol(range, Decl(narrowTypeByInstanceof.ts, 0, 17)) + + return undefined; +>undefined : Symbol(undefined) + } + } + + class FileMatch { +>FileMatch : Symbol(FileMatch, Decl(narrowTypeByInstanceof.ts, 4, 5)) + + public resource(): any { +>resource : Symbol(resource, Decl(narrowTypeByInstanceof.ts, 6, 21)) + + return undefined; +>undefined : Symbol(undefined) + } + } + +type FileMatchOrMatch = FileMatch | Match; +>FileMatchOrMatch : Symbol(FileMatchOrMatch, Decl(narrowTypeByInstanceof.ts, 10, 5)) +>FileMatch : Symbol(FileMatch, Decl(narrowTypeByInstanceof.ts, 4, 5)) +>Match : Symbol(Match, Decl(narrowTypeByInstanceof.ts, 0, 0)) + + +let elementA: FileMatchOrMatch, elementB: FileMatchOrMatch; +>elementA : Symbol(elementA, Decl(narrowTypeByInstanceof.ts, 15, 3)) +>FileMatchOrMatch : Symbol(FileMatchOrMatch, Decl(narrowTypeByInstanceof.ts, 10, 5)) +>elementB : Symbol(elementB, Decl(narrowTypeByInstanceof.ts, 15, 31)) +>FileMatchOrMatch : Symbol(FileMatchOrMatch, Decl(narrowTypeByInstanceof.ts, 10, 5)) + +if (elementA instanceof FileMatch && elementB instanceof FileMatch) { +>elementA : Symbol(elementA, Decl(narrowTypeByInstanceof.ts, 15, 3)) +>FileMatch : Symbol(FileMatch, Decl(narrowTypeByInstanceof.ts, 4, 5)) +>elementB : Symbol(elementB, Decl(narrowTypeByInstanceof.ts, 15, 31)) +>FileMatch : Symbol(FileMatch, Decl(narrowTypeByInstanceof.ts, 4, 5)) + + let a = elementA.resource().path; +>a : Symbol(a, Decl(narrowTypeByInstanceof.ts, 18, 7)) +>elementA.resource : Symbol(FileMatch.resource, Decl(narrowTypeByInstanceof.ts, 6, 21)) +>elementA : Symbol(elementA, Decl(narrowTypeByInstanceof.ts, 15, 3)) +>resource : Symbol(FileMatch.resource, Decl(narrowTypeByInstanceof.ts, 6, 21)) + + let b = elementB.resource().path; +>b : Symbol(b, Decl(narrowTypeByInstanceof.ts, 19, 7)) +>elementB.resource : Symbol(FileMatch.resource, Decl(narrowTypeByInstanceof.ts, 6, 21)) +>elementB : Symbol(elementB, Decl(narrowTypeByInstanceof.ts, 15, 31)) +>resource : Symbol(FileMatch.resource, Decl(narrowTypeByInstanceof.ts, 6, 21)) + +} else if (elementA instanceof Match && elementB instanceof Match) { +>elementA : Symbol(elementA, Decl(narrowTypeByInstanceof.ts, 15, 3)) +>Match : Symbol(Match, Decl(narrowTypeByInstanceof.ts, 0, 0)) +>elementB : Symbol(elementB, Decl(narrowTypeByInstanceof.ts, 15, 31)) +>Match : Symbol(Match, Decl(narrowTypeByInstanceof.ts, 0, 0)) + + let a = elementA.range(); +>a : Symbol(a, Decl(narrowTypeByInstanceof.ts, 21, 7)) +>elementA.range : Symbol(Match.range, Decl(narrowTypeByInstanceof.ts, 0, 17)) +>elementA : Symbol(elementA, Decl(narrowTypeByInstanceof.ts, 15, 3)) +>range : Symbol(Match.range, Decl(narrowTypeByInstanceof.ts, 0, 17)) + + let b = elementB.range(); +>b : Symbol(b, Decl(narrowTypeByInstanceof.ts, 22, 7)) +>elementB.range : Symbol(Match.range, Decl(narrowTypeByInstanceof.ts, 0, 17)) +>elementB : Symbol(elementB, Decl(narrowTypeByInstanceof.ts, 15, 31)) +>range : Symbol(Match.range, Decl(narrowTypeByInstanceof.ts, 0, 17)) +} + diff --git a/tests/baselines/reference/narrowTypeByInstanceof.types b/tests/baselines/reference/narrowTypeByInstanceof.types new file mode 100644 index 00000000000..b98b1e4d234 --- /dev/null +++ b/tests/baselines/reference/narrowTypeByInstanceof.types @@ -0,0 +1,86 @@ +=== tests/cases/compiler/narrowTypeByInstanceof.ts === + class Match { +>Match : Match + + public range(): any { +>range : () => any + + return undefined; +>undefined : undefined + } + } + + class FileMatch { +>FileMatch : FileMatch + + public resource(): any { +>resource : () => any + + return undefined; +>undefined : undefined + } + } + +type FileMatchOrMatch = FileMatch | Match; +>FileMatchOrMatch : Match | FileMatch +>FileMatch : FileMatch +>Match : Match + + +let elementA: FileMatchOrMatch, elementB: FileMatchOrMatch; +>elementA : Match | FileMatch +>FileMatchOrMatch : Match | FileMatch +>elementB : Match | FileMatch +>FileMatchOrMatch : Match | FileMatch + +if (elementA instanceof FileMatch && elementB instanceof FileMatch) { +>elementA instanceof FileMatch && elementB instanceof FileMatch : boolean +>elementA instanceof FileMatch : boolean +>elementA : Match | FileMatch +>FileMatch : typeof FileMatch +>elementB instanceof FileMatch : boolean +>elementB : Match | FileMatch +>FileMatch : typeof FileMatch + + let a = elementA.resource().path; +>a : any +>elementA.resource().path : any +>elementA.resource() : any +>elementA.resource : () => any +>elementA : FileMatch +>resource : () => any +>path : any + + let b = elementB.resource().path; +>b : any +>elementB.resource().path : any +>elementB.resource() : any +>elementB.resource : () => any +>elementB : FileMatch +>resource : () => any +>path : any + +} else if (elementA instanceof Match && elementB instanceof Match) { +>elementA instanceof Match && elementB instanceof Match : boolean +>elementA instanceof Match : boolean +>elementA : Match | FileMatch +>Match : typeof Match +>elementB instanceof Match : boolean +>elementB : Match | FileMatch +>Match : typeof Match + + let a = elementA.range(); +>a : any +>elementA.range() : any +>elementA.range : () => any +>elementA : Match +>range : () => any + + let b = elementB.range(); +>b : any +>elementB.range() : any +>elementB.range : () => any +>elementB : Match +>range : () => any +} + diff --git a/tests/cases/compiler/narrowTypeByInstanceof.ts b/tests/cases/compiler/narrowTypeByInstanceof.ts new file mode 100644 index 00000000000..6fe6693dd96 --- /dev/null +++ b/tests/cases/compiler/narrowTypeByInstanceof.ts @@ -0,0 +1,24 @@ + class Match { + public range(): any { + return undefined; + } + } + + class FileMatch { + public resource(): any { + return undefined; + } + } + +type FileMatchOrMatch = FileMatch | Match; + + +let elementA: FileMatchOrMatch, elementB: FileMatchOrMatch; + +if (elementA instanceof FileMatch && elementB instanceof FileMatch) { + let a = elementA.resource().path; + let b = elementB.resource().path; +} else if (elementA instanceof Match && elementB instanceof Match) { + let a = elementA.range(); + let b = elementB.range(); +} From 4381d1655d4b72db4f93b4b915999e62102b04b1 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 7 May 2015 11:27:38 -0700 Subject: [PATCH 12/33] Add new line --- src/compiler/checker.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d43661c97b6..79ef7612059 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5404,6 +5404,7 @@ module ts { else if (rightType.flags & TypeFlags.Anonymous) { constructSignatures = getSignaturesOfType(rightType, SignatureKind.Construct); } + if (constructSignatures && constructSignatures.length) { targetType = getUnionType(map(constructSignatures, signature => getReturnTypeOfSignature(getErasedSignature(signature)))); } From 05892b1993f691bfbdb5227f872a72e0adebc5a3 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 7 May 2015 12:29:47 -0700 Subject: [PATCH 13/33] remove duplicate case labels --- src/compiler/utilities.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 0bb0065d1b0..f63007bddba 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -484,9 +484,6 @@ module ts { case SyntaxKind.IndexSignature: case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: - case SyntaxKind.FunctionExpression: - case SyntaxKind.ArrowFunction: - case SyntaxKind.FunctionDeclaration: return true; } } From 4c809eddfb7ffaca8c3c64d2b1cdd160a81baa21 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 8 May 2015 09:55:59 -0700 Subject: [PATCH 14/33] Don't wrap an array of errors in an additional array. --- src/services/shims.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/shims.ts b/src/services/shims.ts index dc19b8eb79b..869c707d175 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -883,7 +883,7 @@ module ts { return { options: configFile.options, files: configFile.fileNames, - errors: [realizeDiagnostics(configFile.errors, '\r\n')] + errors: realizeDiagnostics(configFile.errors, '\r\n') }; }); } From 286f0150a6d2e819950ca80145945cf61232c166 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 8 May 2015 10:54:00 -0700 Subject: [PATCH 15/33] Prevent infinite loop when classifying. --- src/services/services.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index ede6fb8ca7b..bec00b9a66a 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -6039,11 +6039,13 @@ module ts { let end = triviaScanner.getTextPos(); let width = end - start; - if (textSpanIntersectsWith(span, start, width)) { - if (!isTrivia(kind)) { - return; - } + // The moment we get something that isn't trivia, then stop processing. + if (!isTrivia(kind)) { + return; + } + // Only bother with the trivia if it at least intersects the span of interest. + if (textSpanIntersectsWith(span, start, width)) { if (isComment(kind)) { // Simple comment. Just add as is. pushClassification(start, width, ClassificationType.comment); From 80f33dd3eaab28d2cae996e04998725dd32c4818 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Fri, 8 May 2015 13:43:13 -0700 Subject: [PATCH 16/33] Make boolean compiler options in harness true only if they say 'true' --- src/harness/fourslash.ts | 10 +- src/harness/harness.ts | 16 +- .../reference/emptyFile-declaration.js | 2 +- .../reference/emptyFile-declaration.js.map | 2 - .../emptyFile-declaration.sourcemap.txt | 7 - .../baselines/reference/emptyFile-souremap.js | 4 +- tests/baselines/reference/es3-amd.js | 7 - tests/baselines/reference/es3-amd.js.map | 2 - .../baselines/reference/es3-amd.sourcemap.txt | 115 -------------- .../reference/es3-declaration-amd.js | 2 +- .../reference/es3-declaration-amd.js.map | 2 - .../es3-declaration-amd.sourcemap.txt | 115 -------------- tests/baselines/reference/es5-amd.js | 7 - tests/baselines/reference/es5-amd.js.map | 2 - .../baselines/reference/es5-amd.sourcemap.txt | 115 -------------- .../reference/es5-declaration-amd.js | 2 +- .../reference/es5-declaration-amd.js.map | 2 - .../es5-declaration-amd.sourcemap.txt | 115 -------------- tests/baselines/reference/es5-umd.js | 7 - tests/baselines/reference/es5-umd.js.map | 2 - .../baselines/reference/es5-umd.sourcemap.txt | 115 -------------- tests/baselines/reference/es5-umd2.js | 7 - tests/baselines/reference/es5-umd2.js.map | 2 - .../reference/es5-umd2.sourcemap.txt | 149 ------------------ tests/baselines/reference/es5-umd3.js | 7 - tests/baselines/reference/es5-umd3.js.map | 2 - .../reference/es5-umd3.sourcemap.txt | 146 ----------------- tests/baselines/reference/es5-umd4.js | 8 - tests/baselines/reference/es5-umd4.js.map | 2 - .../reference/es5-umd4.sourcemap.txt | 143 ----------------- tests/baselines/reference/es6-amd.js | 7 - tests/baselines/reference/es6-amd.js.map | 2 - .../baselines/reference/es6-amd.sourcemap.txt | 91 ----------- .../reference/es6-declaration-amd.js | 2 +- .../reference/es6-declaration-amd.js.map | 2 - .../es6-declaration-amd.sourcemap.txt | 91 ----------- tests/baselines/reference/es6-umd.js | 7 - tests/baselines/reference/es6-umd.js.map | 2 - .../baselines/reference/es6-umd.sourcemap.txt | 91 ----------- tests/baselines/reference/es6-umd2.js | 7 - tests/baselines/reference/es6-umd2.js.map | 2 - .../reference/es6-umd2.sourcemap.txt | 91 ----------- .../compiler/separateCompilationSourceMap.ts | 2 +- 43 files changed, 19 insertions(+), 1495 deletions(-) delete mode 100644 tests/baselines/reference/emptyFile-declaration.js.map delete mode 100644 tests/baselines/reference/emptyFile-declaration.sourcemap.txt delete mode 100644 tests/baselines/reference/es3-amd.js.map delete mode 100644 tests/baselines/reference/es3-amd.sourcemap.txt delete mode 100644 tests/baselines/reference/es3-declaration-amd.js.map delete mode 100644 tests/baselines/reference/es3-declaration-amd.sourcemap.txt delete mode 100644 tests/baselines/reference/es5-amd.js.map delete mode 100644 tests/baselines/reference/es5-amd.sourcemap.txt delete mode 100644 tests/baselines/reference/es5-declaration-amd.js.map delete mode 100644 tests/baselines/reference/es5-declaration-amd.sourcemap.txt delete mode 100644 tests/baselines/reference/es5-umd.js.map delete mode 100644 tests/baselines/reference/es5-umd.sourcemap.txt delete mode 100644 tests/baselines/reference/es5-umd2.js.map delete mode 100644 tests/baselines/reference/es5-umd2.sourcemap.txt delete mode 100644 tests/baselines/reference/es5-umd3.js.map delete mode 100644 tests/baselines/reference/es5-umd3.sourcemap.txt delete mode 100644 tests/baselines/reference/es5-umd4.js.map delete mode 100644 tests/baselines/reference/es5-umd4.sourcemap.txt delete mode 100644 tests/baselines/reference/es6-amd.js.map delete mode 100644 tests/baselines/reference/es6-amd.sourcemap.txt delete mode 100644 tests/baselines/reference/es6-declaration-amd.js.map delete mode 100644 tests/baselines/reference/es6-declaration-amd.sourcemap.txt delete mode 100644 tests/baselines/reference/es6-umd.js.map delete mode 100644 tests/baselines/reference/es6-umd.sourcemap.txt delete mode 100644 tests/baselines/reference/es6-umd2.js.map delete mode 100644 tests/baselines/reference/es6-umd2.sourcemap.txt diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 1f5807c1249..ef4410b3e33 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -144,10 +144,10 @@ module FourSlash { if (globalOptions.hasOwnProperty(prop)) { switch (prop) { case metadataOptionNames.allowNonTsExtensions: - settings.allowNonTsExtensions = true; + settings.allowNonTsExtensions = globalOptions[prop] === "true"; break; case metadataOptionNames.declaration: - settings.declaration = true; + settings.declaration = globalOptions[prop] === "true"; break; case metadataOptionNames.mapRoot: settings.mapRoot = globalOptions[prop]; @@ -174,7 +174,7 @@ module FourSlash { settings.outDir = globalOptions[prop]; break; case metadataOptionNames.sourceMap: - settings.sourceMap = true; + settings.sourceMap = globalOptions[prop] === "true"; break; case metadataOptionNames.sourceRoot: settings.sourceRoot = globalOptions[prop]; @@ -308,7 +308,7 @@ module FourSlash { ts.forEach(testData.files, file => { // Create map between fileName and its content for easily looking up when resolveReference flag is specified this.inputFiles[file.fileName] = file.content; - if (!startResolveFileRef && file.fileOptions[metadataOptionNames.resolveReference]) { + if (!startResolveFileRef && file.fileOptions[metadataOptionNames.resolveReference] === "true") { startResolveFileRef = file; } else if (startResolveFileRef) { // If entry point for resolving file references is already specified, report duplication error @@ -1158,7 +1158,7 @@ module FourSlash { var allFourSlashFiles = this.testData.files; for (var idx = 0; idx < allFourSlashFiles.length; ++idx) { var file = allFourSlashFiles[idx]; - if (file.fileOptions[metadataOptionNames.emitThisFile]) { + if (file.fileOptions[metadataOptionNames.emitThisFile] === "true") { // Find a file with the flag emitThisFile turned on emitFiles.push(file); } diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 97d53a6b75e..9ed515eb5b6 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1008,19 +1008,19 @@ module Harness { break; case 'noemitonerror': - options.noEmitOnError = !!setting.value; + options.noEmitOnError = setting.value === 'true'; break; case 'noresolve': - options.noResolve = !!setting.value; + options.noResolve = setting.value === 'true'; break; case 'noimplicitany': - options.noImplicitAny = !!setting.value; + options.noImplicitAny = setting.value === 'true'; break; case 'nolib': - options.noLib = !!setting.value; + options.noLib = setting.value === 'true'; break; case 'out': @@ -1042,11 +1042,11 @@ module Harness { break; case 'sourcemap': - options.sourceMap = !!setting.value; + options.sourceMap = setting.value === 'true'; break; case 'declaration': - options.declaration = !!setting.value; + options.declaration = setting.value === 'true'; break; case 'newline': @@ -1070,7 +1070,7 @@ module Harness { break; case 'stripinternal': - options.stripInternal = !!setting.value; + options.stripInternal = setting.value === 'true'; case 'usecasesensitivefilenames': useCaseSensitiveFileNames = setting.value === 'true'; @@ -1081,7 +1081,7 @@ module Harness { break; case 'emitbom': - options.emitBOM = !!setting.value; + options.emitBOM = setting.value === 'true'; break; case 'errortruncation': diff --git a/tests/baselines/reference/emptyFile-declaration.js b/tests/baselines/reference/emptyFile-declaration.js index 83f47258925..f395099d73c 100644 --- a/tests/baselines/reference/emptyFile-declaration.js +++ b/tests/baselines/reference/emptyFile-declaration.js @@ -2,6 +2,6 @@ //// [emptyFile-declaration.js] -//# sourceMappingURL=emptyFile-declaration.js.map + //// [emptyFile-declaration.d.ts] diff --git a/tests/baselines/reference/emptyFile-declaration.js.map b/tests/baselines/reference/emptyFile-declaration.js.map deleted file mode 100644 index 2b96d268327..00000000000 --- a/tests/baselines/reference/emptyFile-declaration.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [emptyFile-declaration.js.map] -{"version":3,"file":"emptyFile-declaration.js","sourceRoot":"","sources":["emptyFile-declaration.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/tests/baselines/reference/emptyFile-declaration.sourcemap.txt b/tests/baselines/reference/emptyFile-declaration.sourcemap.txt deleted file mode 100644 index 027af4c7ba0..00000000000 --- a/tests/baselines/reference/emptyFile-declaration.sourcemap.txt +++ /dev/null @@ -1,7 +0,0 @@ -=================================================================== -JsFile: emptyFile-declaration.js -mapUrl: emptyFile-declaration.js.map -sourceRoot: -sources: emptyFile-declaration.ts -=================================================================== ->>>//# sourceMappingURL=emptyFile-declaration.js.map \ No newline at end of file diff --git a/tests/baselines/reference/emptyFile-souremap.js b/tests/baselines/reference/emptyFile-souremap.js index 677037d8689..6de7361731a 100644 --- a/tests/baselines/reference/emptyFile-souremap.js +++ b/tests/baselines/reference/emptyFile-souremap.js @@ -2,6 +2,4 @@ //// [emptyFile-souremap.js] -//# sourceMappingURL=emptyFile-souremap.js.map - -//// [emptyFile-souremap.d.ts] +//# sourceMappingURL=emptyFile-souremap.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es3-amd.js b/tests/baselines/reference/es3-amd.js index 4e9fcdf7a9e..03d4a53e9c5 100644 --- a/tests/baselines/reference/es3-amd.js +++ b/tests/baselines/reference/es3-amd.js @@ -22,10 +22,3 @@ var A = (function () { }; return A; })(); -//# sourceMappingURL=es3-amd.js.map - -//// [es3-amd.d.ts] -declare class A { - constructor(); - B(): number; -} diff --git a/tests/baselines/reference/es3-amd.js.map b/tests/baselines/reference/es3-amd.js.map deleted file mode 100644 index a1ccff476c6..00000000000 --- a/tests/baselines/reference/es3-amd.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es3-amd.js.map] -{"version":3,"file":"es3-amd.js","sourceRoot":"","sources":["es3-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/es3-amd.sourcemap.txt b/tests/baselines/reference/es3-amd.sourcemap.txt deleted file mode 100644 index 86ef55a1f58..00000000000 --- a/tests/baselines/reference/es3-amd.sourcemap.txt +++ /dev/null @@ -1,115 +0,0 @@ -=================================================================== -JsFile: es3-amd.js -mapUrl: es3-amd.js.map -sourceRoot: -sources: es3-amd.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es3-amd.js -sourceFile:es3-amd.ts -------------------------------------------------------------------- ->>>var A = (function () { -1 > -2 >^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) ---- ->>> function A() { -1->^^^^ -2 > ^^-> -1->class A - >{ - > -1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> A.prototype.B = function () { -1->^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ -1-> - > - > public -2 > B -3 > -1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) ---- ->>> return 42; -1 >^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1 >public B() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> }; -1 >^^^^ -2 > ^ -3 > ^^^^^^^^^-> -1 > - > -2 > } -1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>> return A; -1->^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>})(); -1 > -2 >^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > -2 >} -3 > -4 > class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) -4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) ---- ->>>//# sourceMappingURL=es3-amd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es3-declaration-amd.js b/tests/baselines/reference/es3-declaration-amd.js index 2b4995d8544..12dd009cc0e 100644 --- a/tests/baselines/reference/es3-declaration-amd.js +++ b/tests/baselines/reference/es3-declaration-amd.js @@ -22,7 +22,7 @@ var A = (function () { }; return A; })(); -//# sourceMappingURL=es3-declaration-amd.js.map + //// [es3-declaration-amd.d.ts] declare class A { diff --git a/tests/baselines/reference/es3-declaration-amd.js.map b/tests/baselines/reference/es3-declaration-amd.js.map deleted file mode 100644 index 612763299c9..00000000000 --- a/tests/baselines/reference/es3-declaration-amd.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es3-declaration-amd.js.map] -{"version":3,"file":"es3-declaration-amd.js","sourceRoot":"","sources":["es3-declaration-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/es3-declaration-amd.sourcemap.txt b/tests/baselines/reference/es3-declaration-amd.sourcemap.txt deleted file mode 100644 index 7ad6f48d3ad..00000000000 --- a/tests/baselines/reference/es3-declaration-amd.sourcemap.txt +++ /dev/null @@ -1,115 +0,0 @@ -=================================================================== -JsFile: es3-declaration-amd.js -mapUrl: es3-declaration-amd.js.map -sourceRoot: -sources: es3-declaration-amd.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es3-declaration-amd.js -sourceFile:es3-declaration-amd.ts -------------------------------------------------------------------- ->>>var A = (function () { -1 > -2 >^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) ---- ->>> function A() { -1->^^^^ -2 > ^^-> -1->class A - >{ - > -1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> A.prototype.B = function () { -1->^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ -1-> - > - > public -2 > B -3 > -1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) ---- ->>> return 42; -1 >^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1 >public B() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> }; -1 >^^^^ -2 > ^ -3 > ^^^^^^^^^-> -1 > - > -2 > } -1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>> return A; -1->^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>})(); -1 > -2 >^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > -2 >} -3 > -4 > class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) -4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) ---- ->>>//# sourceMappingURL=es3-declaration-amd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es5-amd.js b/tests/baselines/reference/es5-amd.js index cef85a00744..e33fecaed64 100644 --- a/tests/baselines/reference/es5-amd.js +++ b/tests/baselines/reference/es5-amd.js @@ -22,10 +22,3 @@ var A = (function () { }; return A; })(); -//# sourceMappingURL=es5-amd.js.map - -//// [es5-amd.d.ts] -declare class A { - constructor(); - B(): number; -} diff --git a/tests/baselines/reference/es5-amd.js.map b/tests/baselines/reference/es5-amd.js.map deleted file mode 100644 index 6201673cb34..00000000000 --- a/tests/baselines/reference/es5-amd.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es5-amd.js.map] -{"version":3,"file":"es5-amd.js","sourceRoot":"","sources":["es5-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/es5-amd.sourcemap.txt b/tests/baselines/reference/es5-amd.sourcemap.txt deleted file mode 100644 index a5902f03982..00000000000 --- a/tests/baselines/reference/es5-amd.sourcemap.txt +++ /dev/null @@ -1,115 +0,0 @@ -=================================================================== -JsFile: es5-amd.js -mapUrl: es5-amd.js.map -sourceRoot: -sources: es5-amd.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es5-amd.js -sourceFile:es5-amd.ts -------------------------------------------------------------------- ->>>var A = (function () { -1 > -2 >^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) ---- ->>> function A() { -1->^^^^ -2 > ^^-> -1->class A - >{ - > -1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> A.prototype.B = function () { -1->^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ -1-> - > - > public -2 > B -3 > -1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) ---- ->>> return 42; -1 >^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1 >public B() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> }; -1 >^^^^ -2 > ^ -3 > ^^^^^^^^^-> -1 > - > -2 > } -1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>> return A; -1->^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>})(); -1 > -2 >^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > -2 >} -3 > -4 > class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) -4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) ---- ->>>//# sourceMappingURL=es5-amd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es5-declaration-amd.js b/tests/baselines/reference/es5-declaration-amd.js index d942382ff2e..e180e88d514 100644 --- a/tests/baselines/reference/es5-declaration-amd.js +++ b/tests/baselines/reference/es5-declaration-amd.js @@ -22,7 +22,7 @@ var A = (function () { }; return A; })(); -//# sourceMappingURL=es5-declaration-amd.js.map + //// [es5-declaration-amd.d.ts] declare class A { diff --git a/tests/baselines/reference/es5-declaration-amd.js.map b/tests/baselines/reference/es5-declaration-amd.js.map deleted file mode 100644 index d4dfe8ac244..00000000000 --- a/tests/baselines/reference/es5-declaration-amd.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es5-declaration-amd.js.map] -{"version":3,"file":"es5-declaration-amd.js","sourceRoot":"","sources":["es5-declaration-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/es5-declaration-amd.sourcemap.txt b/tests/baselines/reference/es5-declaration-amd.sourcemap.txt deleted file mode 100644 index 59b6ba6bb0a..00000000000 --- a/tests/baselines/reference/es5-declaration-amd.sourcemap.txt +++ /dev/null @@ -1,115 +0,0 @@ -=================================================================== -JsFile: es5-declaration-amd.js -mapUrl: es5-declaration-amd.js.map -sourceRoot: -sources: es5-declaration-amd.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es5-declaration-amd.js -sourceFile:es5-declaration-amd.ts -------------------------------------------------------------------- ->>>var A = (function () { -1 > -2 >^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) ---- ->>> function A() { -1->^^^^ -2 > ^^-> -1->class A - >{ - > -1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> A.prototype.B = function () { -1->^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ -1-> - > - > public -2 > B -3 > -1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) ---- ->>> return 42; -1 >^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1 >public B() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> }; -1 >^^^^ -2 > ^ -3 > ^^^^^^^^^-> -1 > - > -2 > } -1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>> return A; -1->^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>})(); -1 > -2 >^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > -2 >} -3 > -4 > class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) -4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) ---- ->>>//# sourceMappingURL=es5-declaration-amd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd.js b/tests/baselines/reference/es5-umd.js index 0175e8e9fe8..8c68092cbc6 100644 --- a/tests/baselines/reference/es5-umd.js +++ b/tests/baselines/reference/es5-umd.js @@ -23,10 +23,3 @@ var A = (function () { }; return A; })(); -//# sourceMappingURL=es5-umd.js.map - -//// [es5-umd.d.ts] -declare class A { - constructor(); - B(): number; -} diff --git a/tests/baselines/reference/es5-umd.js.map b/tests/baselines/reference/es5-umd.js.map deleted file mode 100644 index 5e29a48796e..00000000000 --- a/tests/baselines/reference/es5-umd.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es5-umd.js.map] -{"version":3,"file":"es5-umd.js","sourceRoot":"","sources":["es5-umd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd.sourcemap.txt b/tests/baselines/reference/es5-umd.sourcemap.txt deleted file mode 100644 index bdbdec5fa9e..00000000000 --- a/tests/baselines/reference/es5-umd.sourcemap.txt +++ /dev/null @@ -1,115 +0,0 @@ -=================================================================== -JsFile: es5-umd.js -mapUrl: es5-umd.js.map -sourceRoot: -sources: es5-umd.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es5-umd.js -sourceFile:es5-umd.ts -------------------------------------------------------------------- ->>>var A = (function () { -1 > -2 >^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) ---- ->>> function A() { -1->^^^^ -2 > ^^-> -1->class A - >{ - > -1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> A.prototype.B = function () { -1->^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ -1-> - > - > public -2 > B -3 > -1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) ---- ->>> return 42; -1 >^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1 >public B() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> }; -1 >^^^^ -2 > ^ -3 > ^^^^^^^^^-> -1 > - > -2 > } -1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>> return A; -1->^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>})(); -1 > -2 >^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > -2 >} -3 > -4 > class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) -4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) ---- ->>>//# sourceMappingURL=es5-umd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd2.js b/tests/baselines/reference/es5-umd2.js index cb0265bf92f..4267e7a3331 100644 --- a/tests/baselines/reference/es5-umd2.js +++ b/tests/baselines/reference/es5-umd2.js @@ -33,10 +33,3 @@ export class A })(); exports.A = A; }); -//# sourceMappingURL=es5-umd2.js.map - -//// [es5-umd2.d.ts] -export declare class A { - constructor(); - B(): number; -} diff --git a/tests/baselines/reference/es5-umd2.js.map b/tests/baselines/reference/es5-umd2.js.map deleted file mode 100644 index 13a785b2edc..00000000000 --- a/tests/baselines/reference/es5-umd2.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es5-umd2.js.map] -{"version":3,"file":"es5-umd2.js","sourceRoot":"","sources":["es5-umd2.ts"],"names":["A","A.constructor","A.B"],"mappings":";;;;;;;;IACA;QAEIA;QAGAC,CAACA;QAEMD,aAACA,GAARA;YAEIE,MAAMA,CAACA,EAAEA,CAACA;QACdA,CAACA;QACLF,QAACA;IAADA,CAACA,AAXD,IAWC;IAXY,SAAC,IAWb,CAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd2.sourcemap.txt b/tests/baselines/reference/es5-umd2.sourcemap.txt deleted file mode 100644 index bfadd9615f3..00000000000 --- a/tests/baselines/reference/es5-umd2.sourcemap.txt +++ /dev/null @@ -1,149 +0,0 @@ -=================================================================== -JsFile: es5-umd2.js -mapUrl: es5-umd2.js.map -sourceRoot: -sources: es5-umd2.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es5-umd2.js -sourceFile:es5-umd2.ts -------------------------------------------------------------------- ->>>(function (deps, factory) { ->>> if (typeof module === 'object' && typeof module.exports === 'object') { ->>> var v = factory(require, exports); if (v !== undefined) module.exports = v; ->>> } ->>> else if (typeof define === 'function' && define.amd) { ->>> define(deps, factory); ->>> } ->>>})(["require", "exports"], function (require, exports) { ->>> var A = (function () { -1 >^^^^ -2 > ^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(9, 5) Source(2, 1) + SourceIndex(0) ---- ->>> function A() { -1->^^^^^^^^ -2 > ^^-> -1->export class A - >{ - > -1->Emitted(10, 9) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(11, 9) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(11, 10) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> A.prototype.B = function () { -1->^^^^^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ -1-> - > - > public -2 > B -3 > -1->Emitted(12, 9) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(12, 22) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(12, 25) Source(9, 5) + SourceIndex(0) name (A) ---- ->>> return 42; -1 >^^^^^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1 >public B() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1 >Emitted(13, 13) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(13, 19) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(13, 20) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(13, 22) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(13, 23) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> }; -1 >^^^^^^^^ -2 > ^ -3 > ^^^^^^^^^-> -1 > - > -2 > } -1 >Emitted(14, 9) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(14, 10) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>> return A; -1->^^^^^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(15, 9) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(15, 17) Source(13, 2) + SourceIndex(0) name (A) ---- ->>> })(); -1 >^^^^ -2 > ^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^-> -1 > -2 > } -3 > -4 > export class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(16, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(16, 6) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(16, 6) Source(2, 1) + SourceIndex(0) -4 >Emitted(16, 10) Source(13, 2) + SourceIndex(0) ---- ->>> exports.A = A; -1->^^^^ -2 > ^^^^^^^^^ -3 > ^^^^ -4 > ^ -1-> -2 > A -3 > - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -4 > -1->Emitted(17, 5) Source(2, 14) + SourceIndex(0) -2 >Emitted(17, 14) Source(2, 15) + SourceIndex(0) -3 >Emitted(17, 18) Source(13, 2) + SourceIndex(0) -4 >Emitted(17, 19) Source(13, 2) + SourceIndex(0) ---- ->>>}); ->>>//# sourceMappingURL=es5-umd2.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd3.js b/tests/baselines/reference/es5-umd3.js index 2d18e2eecc3..3abb92f816f 100644 --- a/tests/baselines/reference/es5-umd3.js +++ b/tests/baselines/reference/es5-umd3.js @@ -33,10 +33,3 @@ export default class A })(); exports.default = A; }); -//# sourceMappingURL=es5-umd3.js.map - -//// [es5-umd3.d.ts] -export default class A { - constructor(); - B(): number; -} diff --git a/tests/baselines/reference/es5-umd3.js.map b/tests/baselines/reference/es5-umd3.js.map deleted file mode 100644 index 8b955f11936..00000000000 --- a/tests/baselines/reference/es5-umd3.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es5-umd3.js.map] -{"version":3,"file":"es5-umd3.js","sourceRoot":"","sources":["es5-umd3.ts"],"names":["A","A.constructor","A.B"],"mappings":";;;;;;;;IACA;QAEIA;QAGAC,CAACA;QAEMD,aAACA,GAARA;YAEIE,MAAMA,CAACA,EAAEA,CAACA;QACdA,CAACA;QACLF,QAACA;IAADA,CAACA,AAXD,IAWC;IAXD,mBAWC,CAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd3.sourcemap.txt b/tests/baselines/reference/es5-umd3.sourcemap.txt deleted file mode 100644 index afb879ac713..00000000000 --- a/tests/baselines/reference/es5-umd3.sourcemap.txt +++ /dev/null @@ -1,146 +0,0 @@ -=================================================================== -JsFile: es5-umd3.js -mapUrl: es5-umd3.js.map -sourceRoot: -sources: es5-umd3.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es5-umd3.js -sourceFile:es5-umd3.ts -------------------------------------------------------------------- ->>>(function (deps, factory) { ->>> if (typeof module === 'object' && typeof module.exports === 'object') { ->>> var v = factory(require, exports); if (v !== undefined) module.exports = v; ->>> } ->>> else if (typeof define === 'function' && define.amd) { ->>> define(deps, factory); ->>> } ->>>})(["require", "exports"], function (require, exports) { ->>> var A = (function () { -1 >^^^^ -2 > ^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(9, 5) Source(2, 1) + SourceIndex(0) ---- ->>> function A() { -1->^^^^^^^^ -2 > ^^-> -1->export default class A - >{ - > -1->Emitted(10, 9) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(11, 9) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(11, 10) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> A.prototype.B = function () { -1->^^^^^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ -1-> - > - > public -2 > B -3 > -1->Emitted(12, 9) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(12, 22) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(12, 25) Source(9, 5) + SourceIndex(0) name (A) ---- ->>> return 42; -1 >^^^^^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1 >public B() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1 >Emitted(13, 13) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(13, 19) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(13, 20) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(13, 22) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(13, 23) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> }; -1 >^^^^^^^^ -2 > ^ -3 > ^^^^^^^^^-> -1 > - > -2 > } -1 >Emitted(14, 9) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(14, 10) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>> return A; -1->^^^^^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(15, 9) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(15, 17) Source(13, 2) + SourceIndex(0) name (A) ---- ->>> })(); -1 >^^^^ -2 > ^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^-> -1 > -2 > } -3 > -4 > export default class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(16, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(16, 6) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(16, 6) Source(2, 1) + SourceIndex(0) -4 >Emitted(16, 10) Source(13, 2) + SourceIndex(0) ---- ->>> exports.default = A; -1->^^^^ -2 > ^^^^^^^^^^^^^^^^^^^ -3 > ^ -1-> -2 > export default class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -3 > -1->Emitted(17, 5) Source(2, 1) + SourceIndex(0) -2 >Emitted(17, 24) Source(13, 2) + SourceIndex(0) -3 >Emitted(17, 25) Source(13, 2) + SourceIndex(0) ---- ->>>}); ->>>//# sourceMappingURL=es5-umd3.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd4.js b/tests/baselines/reference/es5-umd4.js index 85683f8f3c2..058ad545f42 100644 --- a/tests/baselines/reference/es5-umd4.js +++ b/tests/baselines/reference/es5-umd4.js @@ -35,11 +35,3 @@ export = A; })(); return A; }); -//# sourceMappingURL=es5-umd4.js.map - -//// [es5-umd4.d.ts] -declare class A { - constructor(); - B(): number; -} -export = A; diff --git a/tests/baselines/reference/es5-umd4.js.map b/tests/baselines/reference/es5-umd4.js.map deleted file mode 100644 index 0a47d679ed9..00000000000 --- a/tests/baselines/reference/es5-umd4.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es5-umd4.js.map] -{"version":3,"file":"es5-umd4.js","sourceRoot":"","sources":["es5-umd4.ts"],"names":["A","A.constructor","A.B"],"mappings":";;;;;;;;IACA;QAEIA;QAGAC,CAACA;QAEMD,aAACA,GAARA;YAEIE,MAAMA,CAACA,EAAEA,CAACA;QACdA,CAACA;QACLF,QAACA;IAADA,CAACA,AAXD,IAWC;IAEU,AAAX,OAAS,CAAC,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd4.sourcemap.txt b/tests/baselines/reference/es5-umd4.sourcemap.txt deleted file mode 100644 index 9afd8effecf..00000000000 --- a/tests/baselines/reference/es5-umd4.sourcemap.txt +++ /dev/null @@ -1,143 +0,0 @@ -=================================================================== -JsFile: es5-umd4.js -mapUrl: es5-umd4.js.map -sourceRoot: -sources: es5-umd4.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es5-umd4.js -sourceFile:es5-umd4.ts -------------------------------------------------------------------- ->>>(function (deps, factory) { ->>> if (typeof module === 'object' && typeof module.exports === 'object') { ->>> var v = factory(require, exports); if (v !== undefined) module.exports = v; ->>> } ->>> else if (typeof define === 'function' && define.amd) { ->>> define(deps, factory); ->>> } ->>>})(["require", "exports"], function (require, exports) { ->>> var A = (function () { -1 >^^^^ -2 > ^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(9, 5) Source(2, 1) + SourceIndex(0) ---- ->>> function A() { -1->^^^^^^^^ -2 > ^^-> -1->class A - >{ - > -1->Emitted(10, 9) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(11, 9) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(11, 10) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> A.prototype.B = function () { -1->^^^^^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ -1-> - > - > public -2 > B -3 > -1->Emitted(12, 9) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(12, 22) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(12, 25) Source(9, 5) + SourceIndex(0) name (A) ---- ->>> return 42; -1 >^^^^^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1 >public B() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1 >Emitted(13, 13) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(13, 19) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(13, 20) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(13, 22) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(13, 23) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> }; -1 >^^^^^^^^ -2 > ^ -3 > ^^^^^^^^^-> -1 > - > -2 > } -1 >Emitted(14, 9) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(14, 10) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>> return A; -1->^^^^^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(15, 9) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(15, 17) Source(13, 2) + SourceIndex(0) name (A) ---- ->>> })(); -1 >^^^^ -2 > ^ -3 > -4 > ^^^^ -5 > ^^^^^-> -1 > -2 > } -3 > -4 > class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(16, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(16, 6) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(16, 6) Source(2, 1) + SourceIndex(0) -4 >Emitted(16, 10) Source(13, 2) + SourceIndex(0) ---- ->>> return A; -1->^^^^ -2 > -3 > ^^^^^^^ -4 > ^ -5 > ^ -1-> - > - >export = A; -2 > -3 > export = -4 > A -5 > ; -1->Emitted(17, 5) Source(15, 12) + SourceIndex(0) -2 >Emitted(17, 5) Source(15, 1) + SourceIndex(0) -3 >Emitted(17, 12) Source(15, 10) + SourceIndex(0) -4 >Emitted(17, 13) Source(15, 11) + SourceIndex(0) -5 >Emitted(17, 14) Source(15, 12) + SourceIndex(0) ---- ->>>}); ->>>//# sourceMappingURL=es5-umd4.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es6-amd.js b/tests/baselines/reference/es6-amd.js index 74f3037303e..b09f074e59f 100644 --- a/tests/baselines/reference/es6-amd.js +++ b/tests/baselines/reference/es6-amd.js @@ -21,10 +21,3 @@ class A { return 42; } } -//# sourceMappingURL=es6-amd.js.map - -//// [es6-amd.d.ts] -declare class A { - constructor(); - B(): number; -} diff --git a/tests/baselines/reference/es6-amd.js.map b/tests/baselines/reference/es6-amd.js.map deleted file mode 100644 index fe234f8424b..00000000000 --- a/tests/baselines/reference/es6-amd.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es6-amd.js.map] -{"version":3,"file":"es6-amd.js","sourceRoot":"","sources":["es6-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,CAACA;QAEJE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;AACLF,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-amd.sourcemap.txt b/tests/baselines/reference/es6-amd.sourcemap.txt deleted file mode 100644 index 1ab547073c6..00000000000 --- a/tests/baselines/reference/es6-amd.sourcemap.txt +++ /dev/null @@ -1,91 +0,0 @@ -=================================================================== -JsFile: es6-amd.js -mapUrl: es6-amd.js.map -sourceRoot: -sources: es6-amd.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es6-amd.js -sourceFile:es6-amd.ts -------------------------------------------------------------------- ->>>class A { -1 > -2 >^^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) ---- ->>> constructor() { -1->^^^^ -2 > ^^-> -1->class A - >{ - > -1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^ -2 > ^ -3 > ^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> B() { -1->^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^-> -1-> - > - > public -2 > B -1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 6) Source(9, 13) + SourceIndex(0) name (A) ---- ->>> return 42; -1->^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1->() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1->Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> } -1 >^^^^ -2 > ^ -1 > - > -2 > } -1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>>} -1 > -2 >^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > - > -2 >} -1 >Emitted(7, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 2) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>//# sourceMappingURL=es6-amd.js.map1-> -2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1-> -1->Emitted(8, 1) Source(13, 2) + SourceIndex(0) ---- \ No newline at end of file diff --git a/tests/baselines/reference/es6-declaration-amd.js b/tests/baselines/reference/es6-declaration-amd.js index aeba23e0b6e..b1f54086969 100644 --- a/tests/baselines/reference/es6-declaration-amd.js +++ b/tests/baselines/reference/es6-declaration-amd.js @@ -21,7 +21,7 @@ class A { return 42; } } -//# sourceMappingURL=es6-declaration-amd.js.map + //// [es6-declaration-amd.d.ts] declare class A { diff --git a/tests/baselines/reference/es6-declaration-amd.js.map b/tests/baselines/reference/es6-declaration-amd.js.map deleted file mode 100644 index ca1899e03f5..00000000000 --- a/tests/baselines/reference/es6-declaration-amd.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es6-declaration-amd.js.map] -{"version":3,"file":"es6-declaration-amd.js","sourceRoot":"","sources":["es6-declaration-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,CAACA;QAEJE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;AACLF,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-declaration-amd.sourcemap.txt b/tests/baselines/reference/es6-declaration-amd.sourcemap.txt deleted file mode 100644 index 9061bc1ed7c..00000000000 --- a/tests/baselines/reference/es6-declaration-amd.sourcemap.txt +++ /dev/null @@ -1,91 +0,0 @@ -=================================================================== -JsFile: es6-declaration-amd.js -mapUrl: es6-declaration-amd.js.map -sourceRoot: -sources: es6-declaration-amd.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es6-declaration-amd.js -sourceFile:es6-declaration-amd.ts -------------------------------------------------------------------- ->>>class A { -1 > -2 >^^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) ---- ->>> constructor() { -1->^^^^ -2 > ^^-> -1->class A - >{ - > -1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^ -2 > ^ -3 > ^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> B() { -1->^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^-> -1-> - > - > public -2 > B -1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 6) Source(9, 13) + SourceIndex(0) name (A) ---- ->>> return 42; -1->^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1->() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1->Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> } -1 >^^^^ -2 > ^ -1 > - > -2 > } -1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>>} -1 > -2 >^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > - > -2 >} -1 >Emitted(7, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 2) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>//# sourceMappingURL=es6-declaration-amd.js.map1-> -2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1-> -1->Emitted(8, 1) Source(13, 2) + SourceIndex(0) ---- \ No newline at end of file diff --git a/tests/baselines/reference/es6-umd.js b/tests/baselines/reference/es6-umd.js index 74cd671f5ef..af8159eeb3e 100644 --- a/tests/baselines/reference/es6-umd.js +++ b/tests/baselines/reference/es6-umd.js @@ -21,10 +21,3 @@ class A { return 42; } } -//# sourceMappingURL=es6-umd.js.map - -//// [es6-umd.d.ts] -declare class A { - constructor(); - B(): number; -} diff --git a/tests/baselines/reference/es6-umd.js.map b/tests/baselines/reference/es6-umd.js.map deleted file mode 100644 index a5e82f7ccfd..00000000000 --- a/tests/baselines/reference/es6-umd.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es6-umd.js.map] -{"version":3,"file":"es6-umd.js","sourceRoot":"","sources":["es6-umd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,CAACA;QAEJE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;AACLF,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-umd.sourcemap.txt b/tests/baselines/reference/es6-umd.sourcemap.txt deleted file mode 100644 index bb8281ce741..00000000000 --- a/tests/baselines/reference/es6-umd.sourcemap.txt +++ /dev/null @@ -1,91 +0,0 @@ -=================================================================== -JsFile: es6-umd.js -mapUrl: es6-umd.js.map -sourceRoot: -sources: es6-umd.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es6-umd.js -sourceFile:es6-umd.ts -------------------------------------------------------------------- ->>>class A { -1 > -2 >^^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) ---- ->>> constructor() { -1->^^^^ -2 > ^^-> -1->class A - >{ - > -1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^ -2 > ^ -3 > ^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> B() { -1->^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^-> -1-> - > - > public -2 > B -1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 6) Source(9, 13) + SourceIndex(0) name (A) ---- ->>> return 42; -1->^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1->() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1->Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> } -1 >^^^^ -2 > ^ -1 > - > -2 > } -1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>>} -1 > -2 >^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > - > -2 >} -1 >Emitted(7, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 2) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>//# sourceMappingURL=es6-umd.js.map1-> -2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1-> -1->Emitted(8, 1) Source(13, 2) + SourceIndex(0) ---- \ No newline at end of file diff --git a/tests/baselines/reference/es6-umd2.js b/tests/baselines/reference/es6-umd2.js index b12d35aacf8..416932d89bc 100644 --- a/tests/baselines/reference/es6-umd2.js +++ b/tests/baselines/reference/es6-umd2.js @@ -21,10 +21,3 @@ export class A { return 42; } } -//# sourceMappingURL=es6-umd2.js.map - -//// [es6-umd2.d.ts] -export declare class A { - constructor(); - B(): number; -} diff --git a/tests/baselines/reference/es6-umd2.js.map b/tests/baselines/reference/es6-umd2.js.map deleted file mode 100644 index 81f3d85a6cd..00000000000 --- a/tests/baselines/reference/es6-umd2.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es6-umd2.js.map] -{"version":3,"file":"es6-umd2.js","sourceRoot":"","sources":["es6-umd2.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,CAACA;QAEJE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;AACLF,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-umd2.sourcemap.txt b/tests/baselines/reference/es6-umd2.sourcemap.txt deleted file mode 100644 index d032aa3d6c7..00000000000 --- a/tests/baselines/reference/es6-umd2.sourcemap.txt +++ /dev/null @@ -1,91 +0,0 @@ -=================================================================== -JsFile: es6-umd2.js -mapUrl: es6-umd2.js.map -sourceRoot: -sources: es6-umd2.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es6-umd2.js -sourceFile:es6-umd2.ts -------------------------------------------------------------------- ->>>export class A { -1 > -2 >^^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) ---- ->>> constructor() { -1->^^^^ -2 > ^^-> -1->export class A - >{ - > -1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^ -2 > ^ -3 > ^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> B() { -1->^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^-> -1-> - > - > public -2 > B -1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 6) Source(9, 13) + SourceIndex(0) name (A) ---- ->>> return 42; -1->^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1->() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1->Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> } -1 >^^^^ -2 > ^ -1 > - > -2 > } -1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>>} -1 > -2 >^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > - > -2 >} -1 >Emitted(7, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 2) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>//# sourceMappingURL=es6-umd2.js.map1-> -2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1-> -1->Emitted(8, 1) Source(13, 2) + SourceIndex(0) ---- \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationSourceMap.ts b/tests/cases/compiler/separateCompilationSourceMap.ts index 7becf7cbdaf..84c6290caf5 100644 --- a/tests/cases/compiler/separateCompilationSourceMap.ts +++ b/tests/cases/compiler/separateCompilationSourceMap.ts @@ -1,5 +1,5 @@ // @separateCompilation: true -// @sourceMap:sourcemap.map +// @sourceMap:true // @target: es6 // @filename: file1.ts From e0931d8629880e6f4bc4639bd0daee468a89a7a1 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Fri, 8 May 2015 13:58:20 -0700 Subject: [PATCH 17/33] Type check all files when emitting a file under -out --- src/compiler/program.ts | 7 +++++- .../reference/getEmitOutputOut.baseline | 12 ++++++++++ tests/cases/fourslash/getEmitOutputOut.ts | 23 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/getEmitOutputOut.baseline create mode 100644 tests/cases/fourslash/getEmitOutputOut.ts diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 98b6927fc4c..29dcd1d4932 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -219,7 +219,12 @@ module ts { // Create the emit resolver outside of the "emitTime" tracking code below. That way // any cost associated with it (like type checking) are appropriate associated with // the type-checking counter. - let emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile); + // + // If the -out option is specified, we should not pass the source file to getEmitResolver. + // This is because in the -out scenario all files need to be emitted, and therefore all + // files need to be type checked. And the way to specify that all files need to be type + // checked is to not pass the file to getEmitResolver. + let emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(options.out ? undefined : sourceFile); let start = new Date().getTime(); diff --git a/tests/baselines/reference/getEmitOutputOut.baseline b/tests/baselines/reference/getEmitOutputOut.baseline new file mode 100644 index 00000000000..9508b6d5570 --- /dev/null +++ b/tests/baselines/reference/getEmitOutputOut.baseline @@ -0,0 +1,12 @@ +EmitSkipped: false +FileName : out.js +/// +var foo; +(function (foo) { + var bar; + (function (bar) { + var baz1 = bar.Baz.prototype; // Should emit as bar.Baz.prototype + })(bar = foo.bar || (foo.bar = {})); +})(foo || (foo = {})); +var x; + diff --git a/tests/cases/fourslash/getEmitOutputOut.ts b/tests/cases/fourslash/getEmitOutputOut.ts new file mode 100644 index 00000000000..077b257e4de --- /dev/null +++ b/tests/cases/fourslash/getEmitOutputOut.ts @@ -0,0 +1,23 @@ +/// + +// @BaselineFile: getEmitOutputOut.baseline +// @out: out.js + +// @Filename: my.d.ts +// @emitThisFile: false +////declare module foo.bar { +//// class Baz { } +////} + +// @Filename: input0.ts +// @emitThisFile: false +/////// +////module foo.bar { +//// var baz1 = Baz.prototype; // Should emit as bar.Baz.prototype +////} + +// @Filename: input1.ts +// @emitThisFile: true +////var x; + +verify.baselineGetEmitOutput(); \ No newline at end of file From 853edde5217ae5f20b5883674c868122fe842956 Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 8 May 2015 17:51:20 -0700 Subject: [PATCH 18/33] Address code review --- src/compiler/binder.ts | 3 +++ src/compiler/checker.ts | 7 ------- src/compiler/utilities.ts | 9 +++++++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index eddd0c3178c..b66497fc40d 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -441,6 +441,9 @@ module ts { bindBlockScopedVariableDeclaration(node); } else if (isParameterDeclaration(node)) { + // It is safe to walk up parent chain to find whether the node is a destructing parameter declaration + // because its parent chain has already been set up, since parents are set before descending into children. + // // If node is a binding element in parameter declaration, we need to use ParameterExcludes. // Using ParameterExcludes flag allows the compiler to report an error on duplicate identifiers in Parameter Declaration // For example: diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0e56b53b13f..e69a30e1289 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2048,13 +2048,6 @@ module ts { return resolutionResults.pop(); } - function getRootDeclaration(node: Node): Node { - while (node.kind === SyntaxKind.BindingElement) { - node = node.parent.parent; - } - return node; - } - function getDeclarationContainer(node: Node): Node { node = getRootDeclaration(node); diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 5dc84d9bcd6..d4d20e5040f 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1151,10 +1151,15 @@ module ts { } export function isParameterDeclaration(node: VariableLikeDeclaration) { + let root = getRootDeclaration(node); + return root.kind === SyntaxKind.Parameter; + } + + export function getRootDeclaration(node: Node): Node { while (node.kind === SyntaxKind.BindingElement) { - node = node.parent.parent; + node = node.parent.parent; } - return node.kind === SyntaxKind.Parameter; + return node; } export function nodeStartsNewLexicalEnvironment(n: Node): boolean { From 38b1bb0bfa6fc6be63e9f6a9966041f38cbbb312 Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 8 May 2015 17:51:46 -0700 Subject: [PATCH 19/33] Add testcases --- ...BindingElementInParameterDeclaration1.errors.txt | 13 +++++++++---- ...entifierBindingElementInParameterDeclaration1.js | 11 ++++++++--- ...BindingElementInParameterDeclaration2.errors.txt | 13 +++++++++---- ...entifierBindingElementInParameterDeclaration2.js | 11 ++++++++--- ...entifierBindingElementInParameterDeclaration1.ts | 4 ++-- ...entifierBindingElementInParameterDeclaration2.ts | 4 ++-- 6 files changed, 38 insertions(+), 18 deletions(-) diff --git a/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration1.errors.txt b/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration1.errors.txt index 62872f6c806..d210588234d 100644 --- a/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration1.errors.txt +++ b/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration1.errors.txt @@ -17,9 +17,11 @@ tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(7,34): error TS2300: Duplicate identifier 'e'. tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(7,39): error TS2300: Duplicate identifier 'e'. tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(7,48): error TS2300: Duplicate identifier 'e'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(8,14): error TS2300: Duplicate identifier 'f'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts(8,20): error TS2300: Duplicate identifier 'f'. -==== tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts (19 errors) ==== +==== tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts (21 errors) ==== function f0(a, [a, [b]], {b}) { } ~ @@ -65,6 +67,9 @@ tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts !!! error TS2300: Duplicate identifier 'e'. ~ !!! error TS2300: Duplicate identifier 'e'. - - - \ No newline at end of file + function f6([f, ...f]) { } + ~ +!!! error TS2300: Duplicate identifier 'f'. + ~ +!!! error TS2300: Duplicate identifier 'f'. + function f7(a, func = (a) => { return 1 }) { } // not error \ No newline at end of file diff --git a/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration1.js b/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration1.js index cdf70b29835..0c1eb5f3210 100644 --- a/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration1.js +++ b/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration1.js @@ -6,9 +6,8 @@ function f2({b}, {b}) { } function f3([c,[c],[[c]]]) { } function f4({d, d:{d}}) { } function f5({e, e: {e}}, {e}, [d,e, [[e]]], ...e) { } - - - +function f6([f, ...f]) { } +function f7(a, func = (a) => { return 1 }) { } // not error //// [duplicateIdentifierBindingElementInParameterDeclaration1.js] function f0(a, _a, _b) { @@ -37,3 +36,9 @@ function f5(_a, _b, _c) { e[_i - 3] = arguments[_i]; } } +function f6(_a) { + var f = _a[0], f = _a.slice(1); +} +function f7(a, func) { + if (func === void 0) { func = function (a) { return 1; }; } +} // not error diff --git a/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration2.errors.txt b/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration2.errors.txt index 8a6df4b075b..e3d1dc621f8 100644 --- a/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration2.errors.txt +++ b/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration2.errors.txt @@ -17,9 +17,11 @@ tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(8,35): error TS2300: Duplicate identifier 'e'. tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(8,40): error TS2300: Duplicate identifier 'e'. tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(8,49): error TS2300: Duplicate identifier 'e'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(9,14): error TS2300: Duplicate identifier 'f'. +tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts(9,20): error TS2300: Duplicate identifier 'f'. -==== tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts (19 errors) ==== +==== tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts (21 errors) ==== "use strict" function f0(a, [a, [b]], {b}) { } @@ -66,6 +68,9 @@ tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts !!! error TS2300: Duplicate identifier 'e'. ~ !!! error TS2300: Duplicate identifier 'e'. - - - \ No newline at end of file + function f6([f, ...f]) { } + ~ +!!! error TS2300: Duplicate identifier 'f'. + ~ +!!! error TS2300: Duplicate identifier 'f'. + function f7(a, func = (a) => { return 1 }){ } // not error \ No newline at end of file diff --git a/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration2.js b/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration2.js index 46f59c6c96d..e423b035d9d 100644 --- a/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration2.js +++ b/tests/baselines/reference/duplicateIdentifierBindingElementInParameterDeclaration2.js @@ -7,9 +7,8 @@ function f2({b}, {b}) { } function f3([c, [c], [[c]]]) { } function f4({d, d: {d}}) { } function f5({e, e: {e}}, {e}, [d, e, [[e]]], ...e) { } - - - +function f6([f, ...f]) { } +function f7(a, func = (a) => { return 1 }){ } // not error //// [duplicateIdentifierBindingElementInParameterDeclaration2.js] "use strict"; @@ -39,3 +38,9 @@ function f5(_a, _b, _c) { e[_i - 3] = arguments[_i]; } } +function f6(_a) { + var f = _a[0], f = _a.slice(1); +} +function f7(a, func) { + if (func === void 0) { func = function (a) { return 1; }; } +} // not error diff --git a/tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts b/tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts index e5c5965301e..9d4a2331b45 100644 --- a/tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts +++ b/tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration1.ts @@ -6,5 +6,5 @@ function f2({b}, {b}) { } function f3([c,[c],[[c]]]) { } function f4({d, d:{d}}) { } function f5({e, e: {e}}, {e}, [d,e, [[e]]], ...e) { } - - +function f6([f, ...f]) { } +function f7(a, func = (a) => { return 1 }) { } // not error \ No newline at end of file diff --git a/tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts b/tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts index 0ed6100ca34..f42e490dae1 100644 --- a/tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts +++ b/tests/cases/compiler/duplicateIdentifierBindingElementInParameterDeclaration2.ts @@ -7,5 +7,5 @@ function f2({b}, {b}) { } function f3([c, [c], [[c]]]) { } function f4({d, d: {d}}) { } function f5({e, e: {e}}, {e}, [d, e, [[e]]], ...e) { } - - +function f6([f, ...f]) { } +function f7(a, func = (a) => { return 1 }){ } // not error \ No newline at end of file From 1a4df9ab7f9e0c830b69af25edcba8f2bf3d10a9 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Sun, 10 May 2015 22:23:12 -0700 Subject: [PATCH 20/33] do not hoist ambient declarations --- src/compiler/emitter.ts | 4 + .../systemModuleAmbientDeclarations.js | 84 +++++++++++++++++++ .../systemModuleAmbientDeclarations.symbols | 53 ++++++++++++ .../systemModuleAmbientDeclarations.types | 55 ++++++++++++ .../systemModuleAmbientDeclarations.ts | 28 +++++++ 5 files changed, 224 insertions(+) create mode 100644 tests/baselines/reference/systemModuleAmbientDeclarations.js create mode 100644 tests/baselines/reference/systemModuleAmbientDeclarations.symbols create mode 100644 tests/baselines/reference/systemModuleAmbientDeclarations.types create mode 100644 tests/cases/compiler/systemModuleAmbientDeclarations.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 6d5146a6801..c16daf298c1 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5143,6 +5143,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { return exportedDeclarations; function visit(node: Node): void { + if (node.flags & NodeFlags.Ambient) { + return; + } + if (node.kind === SyntaxKind.FunctionDeclaration) { if (!hoistedFunctionDeclarations) { hoistedFunctionDeclarations = []; diff --git a/tests/baselines/reference/systemModuleAmbientDeclarations.js b/tests/baselines/reference/systemModuleAmbientDeclarations.js new file mode 100644 index 00000000000..82c18cd7981 --- /dev/null +++ b/tests/baselines/reference/systemModuleAmbientDeclarations.js @@ -0,0 +1,84 @@ +//// [tests/cases/compiler/systemModuleAmbientDeclarations.ts] //// + +//// [file1.ts] + +declare class Promise { } +declare function Foo(): void; +declare class C {} +declare enum E {X = 1}; + +export var promise = Promise; +export var foo = Foo; +export var c = C; +export var e = E; + +//// [file2.ts] +export declare function foo(); + +//// [file3.ts] +export declare class C {} + +//// [file4.ts] +export declare var v: number; + +//// [file5.ts] +export declare enum E {X = 1} + +//// [file6.ts] +export declare module M { var v: number; } + + +//// [file1.js] +System.register([], function(exports_1) { + var promise, foo, c, e; + return { + setters:[], + execute: function() { + ; + exports_1("promise", promise = Promise); + exports_1("foo", foo = Foo); + exports_1("c", c = C); + exports_1("e", e = E); + } + } +}); +//// [file2.js] +System.register([], function(exports_1) { + return { + setters:[], + execute: function() { + } + } +}); +//// [file3.js] +System.register([], function(exports_1) { + return { + setters:[], + execute: function() { + } + } +}); +//// [file4.js] +System.register([], function(exports_1) { + return { + setters:[], + execute: function() { + } + } +}); +//// [file5.js] +System.register([], function(exports_1) { + return { + setters:[], + execute: function() { + } + } +}); +//// [file6.js] +System.register([], function(exports_1) { + return { + setters:[], + execute: function() { + } + } +}); diff --git a/tests/baselines/reference/systemModuleAmbientDeclarations.symbols b/tests/baselines/reference/systemModuleAmbientDeclarations.symbols new file mode 100644 index 00000000000..c2e8557270b --- /dev/null +++ b/tests/baselines/reference/systemModuleAmbientDeclarations.symbols @@ -0,0 +1,53 @@ +=== tests/cases/compiler/file1.ts === + +declare class Promise { } +>Promise : Symbol(Promise, Decl(file1.ts, 0, 0)) + +declare function Foo(): void; +>Foo : Symbol(Foo, Decl(file1.ts, 1, 25)) + +declare class C {} +>C : Symbol(C, Decl(file1.ts, 2, 29)) + +declare enum E {X = 1}; +>E : Symbol(E, Decl(file1.ts, 3, 18)) +>X : Symbol(E.X, Decl(file1.ts, 4, 16)) + +export var promise = Promise; +>promise : Symbol(promise, Decl(file1.ts, 6, 10)) +>Promise : Symbol(Promise, Decl(file1.ts, 0, 0)) + +export var foo = Foo; +>foo : Symbol(foo, Decl(file1.ts, 7, 10)) +>Foo : Symbol(Foo, Decl(file1.ts, 1, 25)) + +export var c = C; +>c : Symbol(c, Decl(file1.ts, 8, 10)) +>C : Symbol(C, Decl(file1.ts, 2, 29)) + +export var e = E; +>e : Symbol(e, Decl(file1.ts, 9, 10)) +>E : Symbol(E, Decl(file1.ts, 3, 18)) + +=== tests/cases/compiler/file2.ts === +export declare function foo(); +>foo : Symbol(foo, Decl(file2.ts, 0, 0)) + +=== tests/cases/compiler/file3.ts === +export declare class C {} +>C : Symbol(C, Decl(file3.ts, 0, 0)) + +=== tests/cases/compiler/file4.ts === +export declare var v: number; +>v : Symbol(v, Decl(file4.ts, 0, 18)) + +=== tests/cases/compiler/file5.ts === +export declare enum E {X = 1} +>E : Symbol(E, Decl(file5.ts, 0, 0)) +>X : Symbol(E.X, Decl(file5.ts, 0, 23)) + +=== tests/cases/compiler/file6.ts === +export declare module M { var v: number; } +>M : Symbol(M, Decl(file6.ts, 0, 0)) +>v : Symbol(v, Decl(file6.ts, 0, 29)) + diff --git a/tests/baselines/reference/systemModuleAmbientDeclarations.types b/tests/baselines/reference/systemModuleAmbientDeclarations.types new file mode 100644 index 00000000000..3633f922881 --- /dev/null +++ b/tests/baselines/reference/systemModuleAmbientDeclarations.types @@ -0,0 +1,55 @@ +=== tests/cases/compiler/file1.ts === + +declare class Promise { } +>Promise : Promise + +declare function Foo(): void; +>Foo : () => void + +declare class C {} +>C : C + +declare enum E {X = 1}; +>E : E +>X : E +>1 : number + +export var promise = Promise; +>promise : typeof Promise +>Promise : typeof Promise + +export var foo = Foo; +>foo : () => void +>Foo : () => void + +export var c = C; +>c : typeof C +>C : typeof C + +export var e = E; +>e : typeof E +>E : typeof E + +=== tests/cases/compiler/file2.ts === +export declare function foo(); +>foo : () => any + +=== tests/cases/compiler/file3.ts === +export declare class C {} +>C : C + +=== tests/cases/compiler/file4.ts === +export declare var v: number; +>v : number + +=== tests/cases/compiler/file5.ts === +export declare enum E {X = 1} +>E : E +>X : E +>1 : number + +=== tests/cases/compiler/file6.ts === +export declare module M { var v: number; } +>M : typeof M +>v : number + diff --git a/tests/cases/compiler/systemModuleAmbientDeclarations.ts b/tests/cases/compiler/systemModuleAmbientDeclarations.ts new file mode 100644 index 00000000000..05f78592780 --- /dev/null +++ b/tests/cases/compiler/systemModuleAmbientDeclarations.ts @@ -0,0 +1,28 @@ +// @module: system +// @separateCompilation: true + +// @filename: file1.ts +declare class Promise { } +declare function Foo(): void; +declare class C {} +declare enum E {X = 1}; + +export var promise = Promise; +export var foo = Foo; +export var c = C; +export var e = E; + +// @filename: file2.ts +export declare function foo(); + +// @filename: file3.ts +export declare class C {} + +// @filename: file4.ts +export declare var v: number; + +// @filename: file5.ts +export declare enum E {X = 1} + +// @filename: file6.ts +export declare module M { var v: number; } From cdbd6c68982e7db99680b7cc11a662602664a34f Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 11 May 2015 00:07:49 -0700 Subject: [PATCH 21/33] system: fix emit for exports of non-top level entities, fix emit for enums --- src/compiler/emitter.ts | 61 ++++++++++++++++--- .../systemModuleDeclarationMerging.js | 43 +++++++++++++ .../systemModuleDeclarationMerging.symbols | 23 +++++++ .../systemModuleDeclarationMerging.types | 23 +++++++ .../systemModuleNonTopLevelModuleMembers.js | 58 ++++++++++++++++++ ...stemModuleNonTopLevelModuleMembers.symbols | 33 ++++++++++ ...systemModuleNonTopLevelModuleMembers.types | 33 ++++++++++ .../systemModuleDeclarationMerging.ts | 11 ++++ .../systemModuleNonTopLevelModuleMembers.ts | 14 +++++ 9 files changed, 289 insertions(+), 10 deletions(-) create mode 100644 tests/baselines/reference/systemModuleDeclarationMerging.js create mode 100644 tests/baselines/reference/systemModuleDeclarationMerging.symbols create mode 100644 tests/baselines/reference/systemModuleDeclarationMerging.types create mode 100644 tests/baselines/reference/systemModuleNonTopLevelModuleMembers.js create mode 100644 tests/baselines/reference/systemModuleNonTopLevelModuleMembers.symbols create mode 100644 tests/baselines/reference/systemModuleNonTopLevelModuleMembers.types create mode 100644 tests/cases/compiler/systemModuleDeclarationMerging.ts create mode 100644 tests/cases/compiler/systemModuleNonTopLevelModuleMembers.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 6d5146a6801..44feeed0fa9 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2639,7 +2639,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { writeLine(); emitStart(node); - if (compilerOptions.module === ModuleKind.System) { + // emit call to exported only for top level nodes + if (compilerOptions.module === ModuleKind.System && node.parent === currentSourceFile) { // emit export default as // export("default", ) write(`${exportFunctionForFile}("`); @@ -4403,7 +4404,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { emitModuleMemberName(node); write(" = {}));"); emitEnd(node); - if (!isES6ExportedDeclaration(node) && node.flags & NodeFlags.Export) { + if (!isES6ExportedDeclaration(node) && node.flags & NodeFlags.Export && !shouldHoistDeclarationInSystemJsModule(node)) { + // do not emit var if variable was already hoisted writeLine(); emitStart(node); write("var "); @@ -4414,6 +4416,15 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { write(";"); } if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile) { + if (compilerOptions.module === ModuleKind.System && (node.flags & NodeFlags.Export)) { + // write the call to exported for enum + writeLine(); + write(`${exportFunctionForFile}("`); + emitDeclarationName(node); + write(`", `); + emitDeclarationName(node); + write(")"); + } emitExportMemberAssignments(node.name); } } @@ -5094,7 +5105,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { // in theory we should hoist only exported functions and its dependencies // in practice to simplify things we'll hoist all source level functions and variable declaration // including variables declarations for module and class declarations - let hoistedVars: (Identifier | ClassDeclaration | ModuleDeclaration)[]; + let hoistedVars: (Identifier | ClassDeclaration | ModuleDeclaration | EnumDeclaration)[]; let hoistedFunctionDeclarations: FunctionDeclaration[]; let exportedDeclarations: (Identifier | Declaration)[]; @@ -5103,13 +5114,30 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { if (hoistedVars) { writeLine(); write("var "); + let seen: Map = {}; for (let i = 0; i < hoistedVars.length; ++i) { let local = hoistedVars[i]; + let name = local.kind === SyntaxKind.Identifier + ? local + : (local).name; + + if (name) { + // do not emit duplicate entries (in case of declaration merging) in the list of hoisted variables + let text = unescapeIdentifier(name.text); + if (hasProperty(seen, text)) { + continue; + } + else { + seen[text] = text; + } + } + if (i !== 0) { write(", "); } - if (local.kind === SyntaxKind.ClassDeclaration || local.kind === SyntaxKind.ModuleDeclaration) { - emitDeclarationName(local); + + if (local.kind === SyntaxKind.ClassDeclaration || local.kind === SyntaxKind.ModuleDeclaration || local.kind === SyntaxKind.EnumDeclaration) { + emitDeclarationName(local); } else { emit(local); @@ -5153,7 +5181,6 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { } if (node.kind === SyntaxKind.ClassDeclaration) { - // TODO: rename block scoped classes if (!hoistedVars) { hoistedVars = []; } @@ -5162,12 +5189,26 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { return; } - if (node.kind === SyntaxKind.ModuleDeclaration && shouldEmitModuleDeclaration(node)) { - if (!hoistedVars) { - hoistedVars = []; + if (node.kind === SyntaxKind.EnumDeclaration) { + if (shouldEmitEnumDeclaration(node)) { + if (!hoistedVars) { + hoistedVars = []; + } + + hoistedVars.push(node); } - hoistedVars.push(node); + return; + } + + if (node.kind === SyntaxKind.ModuleDeclaration) { + if (shouldEmitModuleDeclaration(node)) { + if (!hoistedVars) { + hoistedVars = []; + } + + hoistedVars.push(node); + } return; } diff --git a/tests/baselines/reference/systemModuleDeclarationMerging.js b/tests/baselines/reference/systemModuleDeclarationMerging.js new file mode 100644 index 00000000000..b745ed04891 --- /dev/null +++ b/tests/baselines/reference/systemModuleDeclarationMerging.js @@ -0,0 +1,43 @@ +//// [systemModuleDeclarationMerging.ts] + +export function F() {} +export module F { var x; } + +export class C {} +export module C { var x; } + +export enum E {} +export module E { var x; } + +//// [systemModuleDeclarationMerging.js] +System.register([], function(exports_1) { + var F, C, E; + function F() { } + exports_1("F", F); + return { + setters:[], + execute: function() { + (function (F) { + var x; + })(F = F || (F = {})); + exports_1("F", F) + C = (function () { + function C() { + } + return C; + })(); + exports_1("C", C); + (function (C) { + var x; + })(C = C || (C = {})); + exports_1("C", C) + (function (E) { + })(E || (E = {})); + exports_1("E", E) + (function (E) { + var x; + })(E = E || (E = {})); + exports_1("E", E) + } + } +}); diff --git a/tests/baselines/reference/systemModuleDeclarationMerging.symbols b/tests/baselines/reference/systemModuleDeclarationMerging.symbols new file mode 100644 index 00000000000..8efce4022ba --- /dev/null +++ b/tests/baselines/reference/systemModuleDeclarationMerging.symbols @@ -0,0 +1,23 @@ +=== tests/cases/compiler/systemModuleDeclarationMerging.ts === + +export function F() {} +>F : Symbol(F, Decl(systemModuleDeclarationMerging.ts, 0, 0), Decl(systemModuleDeclarationMerging.ts, 1, 22)) + +export module F { var x; } +>F : Symbol(F, Decl(systemModuleDeclarationMerging.ts, 0, 0), Decl(systemModuleDeclarationMerging.ts, 1, 22)) +>x : Symbol(x, Decl(systemModuleDeclarationMerging.ts, 2, 21)) + +export class C {} +>C : Symbol(C, Decl(systemModuleDeclarationMerging.ts, 2, 26), Decl(systemModuleDeclarationMerging.ts, 4, 17)) + +export module C { var x; } +>C : Symbol(C, Decl(systemModuleDeclarationMerging.ts, 2, 26), Decl(systemModuleDeclarationMerging.ts, 4, 17)) +>x : Symbol(x, Decl(systemModuleDeclarationMerging.ts, 5, 21)) + +export enum E {} +>E : Symbol(E, Decl(systemModuleDeclarationMerging.ts, 5, 26), Decl(systemModuleDeclarationMerging.ts, 7, 16)) + +export module E { var x; } +>E : Symbol(E, Decl(systemModuleDeclarationMerging.ts, 5, 26), Decl(systemModuleDeclarationMerging.ts, 7, 16)) +>x : Symbol(x, Decl(systemModuleDeclarationMerging.ts, 8, 21)) + diff --git a/tests/baselines/reference/systemModuleDeclarationMerging.types b/tests/baselines/reference/systemModuleDeclarationMerging.types new file mode 100644 index 00000000000..20bf1e67f51 --- /dev/null +++ b/tests/baselines/reference/systemModuleDeclarationMerging.types @@ -0,0 +1,23 @@ +=== tests/cases/compiler/systemModuleDeclarationMerging.ts === + +export function F() {} +>F : typeof F + +export module F { var x; } +>F : typeof F +>x : any + +export class C {} +>C : C + +export module C { var x; } +>C : typeof C +>x : any + +export enum E {} +>E : E + +export module E { var x; } +>E : typeof E +>x : any + diff --git a/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.js b/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.js new file mode 100644 index 00000000000..87e96259bf1 --- /dev/null +++ b/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.js @@ -0,0 +1,58 @@ +//// [systemModuleNonTopLevelModuleMembers.ts] + +export class TopLevelClass {} +export module TopLevelModule {var v;} +export function TopLevelFunction(): void {} +export enum TopLevelEnum {E} + +export module TopLevelModule2 { + export class NonTopLevelClass {} + export module NonTopLevelModule {var v;} + export function NonTopLevelFunction(): void {} + export enum NonTopLevelEnum {E} +} + +//// [systemModuleNonTopLevelModuleMembers.js] +System.register([], function(exports_1) { + var TopLevelClass, TopLevelModule, TopLevelEnum, TopLevelModule2; + function TopLevelFunction() { } + exports_1("TopLevelFunction", TopLevelFunction); + return { + setters:[], + execute: function() { + TopLevelClass = (function () { + function TopLevelClass() { + } + return TopLevelClass; + })(); + exports_1("TopLevelClass", TopLevelClass); + (function (TopLevelModule) { + var v; + })(TopLevelModule = TopLevelModule || (TopLevelModule = {})); + exports_1("TopLevelModule", TopLevelModule) + (function (TopLevelEnum) { + TopLevelEnum[TopLevelEnum["E"] = 0] = "E"; + })(TopLevelEnum || (TopLevelEnum = {})); + exports_1("TopLevelEnum", TopLevelEnum) + (function (TopLevelModule2) { + var NonTopLevelClass = (function () { + function NonTopLevelClass() { + } + return NonTopLevelClass; + })(); + TopLevelModule2.NonTopLevelClass = NonTopLevelClass; + var NonTopLevelModule; + (function (NonTopLevelModule) { + var v; + })(NonTopLevelModule = TopLevelModule2.NonTopLevelModule || (TopLevelModule2.NonTopLevelModule = {})); + function NonTopLevelFunction() { } + TopLevelModule2.NonTopLevelFunction = NonTopLevelFunction; + (function (NonTopLevelEnum) { + NonTopLevelEnum[NonTopLevelEnum["E"] = 0] = "E"; + })(TopLevelModule2.NonTopLevelEnum || (TopLevelModule2.NonTopLevelEnum = {})); + var NonTopLevelEnum = TopLevelModule2.NonTopLevelEnum; + })(TopLevelModule2 = TopLevelModule2 || (TopLevelModule2 = {})); + exports_1("TopLevelModule2", TopLevelModule2) + } + } +}); diff --git a/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.symbols b/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.symbols new file mode 100644 index 00000000000..e0b69c71a2f --- /dev/null +++ b/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.symbols @@ -0,0 +1,33 @@ +=== tests/cases/compiler/systemModuleNonTopLevelModuleMembers.ts === + +export class TopLevelClass {} +>TopLevelClass : Symbol(TopLevelClass, Decl(systemModuleNonTopLevelModuleMembers.ts, 0, 0)) + +export module TopLevelModule {var v;} +>TopLevelModule : Symbol(TopLevelModule, Decl(systemModuleNonTopLevelModuleMembers.ts, 1, 29)) +>v : Symbol(v, Decl(systemModuleNonTopLevelModuleMembers.ts, 2, 33)) + +export function TopLevelFunction(): void {} +>TopLevelFunction : Symbol(TopLevelFunction, Decl(systemModuleNonTopLevelModuleMembers.ts, 2, 37)) + +export enum TopLevelEnum {E} +>TopLevelEnum : Symbol(TopLevelEnum, Decl(systemModuleNonTopLevelModuleMembers.ts, 3, 43)) +>E : Symbol(TopLevelEnum.E, Decl(systemModuleNonTopLevelModuleMembers.ts, 4, 26)) + +export module TopLevelModule2 { +>TopLevelModule2 : Symbol(TopLevelModule2, Decl(systemModuleNonTopLevelModuleMembers.ts, 4, 28)) + + export class NonTopLevelClass {} +>NonTopLevelClass : Symbol(NonTopLevelClass, Decl(systemModuleNonTopLevelModuleMembers.ts, 6, 31)) + + export module NonTopLevelModule {var v;} +>NonTopLevelModule : Symbol(NonTopLevelModule, Decl(systemModuleNonTopLevelModuleMembers.ts, 7, 36)) +>v : Symbol(v, Decl(systemModuleNonTopLevelModuleMembers.ts, 8, 40)) + + export function NonTopLevelFunction(): void {} +>NonTopLevelFunction : Symbol(NonTopLevelFunction, Decl(systemModuleNonTopLevelModuleMembers.ts, 8, 44)) + + export enum NonTopLevelEnum {E} +>NonTopLevelEnum : Symbol(NonTopLevelEnum, Decl(systemModuleNonTopLevelModuleMembers.ts, 9, 50)) +>E : Symbol(NonTopLevelEnum.E, Decl(systemModuleNonTopLevelModuleMembers.ts, 10, 33)) +} diff --git a/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.types b/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.types new file mode 100644 index 00000000000..ffe3d23f7a6 --- /dev/null +++ b/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.types @@ -0,0 +1,33 @@ +=== tests/cases/compiler/systemModuleNonTopLevelModuleMembers.ts === + +export class TopLevelClass {} +>TopLevelClass : TopLevelClass + +export module TopLevelModule {var v;} +>TopLevelModule : typeof TopLevelModule +>v : any + +export function TopLevelFunction(): void {} +>TopLevelFunction : () => void + +export enum TopLevelEnum {E} +>TopLevelEnum : TopLevelEnum +>E : TopLevelEnum + +export module TopLevelModule2 { +>TopLevelModule2 : typeof TopLevelModule2 + + export class NonTopLevelClass {} +>NonTopLevelClass : NonTopLevelClass + + export module NonTopLevelModule {var v;} +>NonTopLevelModule : typeof NonTopLevelModule +>v : any + + export function NonTopLevelFunction(): void {} +>NonTopLevelFunction : () => void + + export enum NonTopLevelEnum {E} +>NonTopLevelEnum : NonTopLevelEnum +>E : NonTopLevelEnum +} diff --git a/tests/cases/compiler/systemModuleDeclarationMerging.ts b/tests/cases/compiler/systemModuleDeclarationMerging.ts new file mode 100644 index 00000000000..45c59c5b5dc --- /dev/null +++ b/tests/cases/compiler/systemModuleDeclarationMerging.ts @@ -0,0 +1,11 @@ +// @module: system +// @separateCompilation: true + +export function F() {} +export module F { var x; } + +export class C {} +export module C { var x; } + +export enum E {} +export module E { var x; } \ No newline at end of file diff --git a/tests/cases/compiler/systemModuleNonTopLevelModuleMembers.ts b/tests/cases/compiler/systemModuleNonTopLevelModuleMembers.ts new file mode 100644 index 00000000000..756d430a2de --- /dev/null +++ b/tests/cases/compiler/systemModuleNonTopLevelModuleMembers.ts @@ -0,0 +1,14 @@ +// @module: system +// @separateCompilation: true + +export class TopLevelClass {} +export module TopLevelModule {var v;} +export function TopLevelFunction(): void {} +export enum TopLevelEnum {E} + +export module TopLevelModule2 { + export class NonTopLevelClass {} + export module NonTopLevelModule {var v;} + export function NonTopLevelFunction(): void {} + export enum NonTopLevelEnum {E} +} \ No newline at end of file From b534b5665c2a4246e52c2a1f5d92709e7a54c397 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 11 May 2015 00:09:06 -0700 Subject: [PATCH 22/33] correct typos --- src/compiler/emitter.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 44feeed0fa9..5e2ead605f9 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2639,7 +2639,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { writeLine(); emitStart(node); - // emit call to exported only for top level nodes + // emit call to exporter only for top level nodes if (compilerOptions.module === ModuleKind.System && node.parent === currentSourceFile) { // emit export default as // export("default", ) @@ -4417,7 +4417,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { } if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile) { if (compilerOptions.module === ModuleKind.System && (node.flags & NodeFlags.Export)) { - // write the call to exported for enum + // write the call to exporter for enum writeLine(); write(`${exportFunctionForFile}("`); emitDeclarationName(node); From 029fbb0d4f37ef2b90c1d6749030e03136db305d Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Mon, 11 May 2015 13:26:23 -0700 Subject: [PATCH 23/33] Remove nextTokenCanFollowContextualModifier --- src/compiler/parser.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 055fc1b6f74..af9b486a1da 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -957,15 +957,6 @@ module ts { } function nextTokenCanFollowModifier() { - nextToken(); - return canFollowModifier(); - } - - function parseAnyContextualModifier(): boolean { - return isModifier(token) && tryParse(nextTokenCanFollowContextualModifier); - } - - function nextTokenCanFollowContextualModifier() { if (token === SyntaxKind.ConstKeyword) { // 'const' is only a modifier if followed by 'enum'. return nextToken() === SyntaxKind.EnumKeyword; @@ -984,6 +975,10 @@ module ts { return canFollowModifier(); } + function parseAnyContextualModifier(): boolean { + return isModifier(token) && tryParse(nextTokenCanFollowModifier); + } + function canFollowModifier(): boolean { return token === SyntaxKind.OpenBracketToken || token === SyntaxKind.OpenBraceToken From 947d4a29c2aa1467e52617a9fe1c20cd8d442a7d Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 11 May 2015 14:01:46 -0700 Subject: [PATCH 24/33] program should store file names with normalized slashes --- src/compiler/program.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 29dcd1d4932..aa565404447 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -238,7 +238,7 @@ module ts { } function getSourceFile(fileName: string) { - fileName = host.getCanonicalFileName(fileName); + fileName = host.getCanonicalFileName(normalizeSlashes(fileName)); return hasProperty(filesByName, fileName) ? filesByName[fileName] : undefined; } @@ -357,7 +357,7 @@ module ts { // Get source file from normalized fileName function findSourceFile(fileName: string, isDefaultLib: boolean, refFile?: SourceFile, refStart?: number, refLength?: number): SourceFile { - let canonicalName = host.getCanonicalFileName(fileName); + let canonicalName = host.getCanonicalFileName(normalizeSlashes(fileName)); if (hasProperty(filesByName, canonicalName)) { // We've already looked for this file, use cached result return getSourceFileFromCache(fileName, canonicalName, /*useAbsolutePath*/ false); From 714b39a511b0a2940de7ae47e981f93f24855960 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 11 May 2015 14:17:34 -0700 Subject: [PATCH 25/33] addressed PR feedback --- src/compiler/emitter.ts | 19 +++--- .../reference/systemModuleConstEnums.js | 27 ++++++++ .../reference/systemModuleConstEnums.symbols | 35 ++++++++++ .../reference/systemModuleConstEnums.types | 37 ++++++++++ ...stemModuleConstEnumsSeparateCompilation.js | 37 ++++++++++ ...oduleConstEnumsSeparateCompilation.symbols | 35 ++++++++++ ...mModuleConstEnumsSeparateCompilation.types | 37 ++++++++++ .../reference/systemModuleExportDefault.js | 67 +++++++++++++++++++ .../systemModuleExportDefault.symbols | 16 +++++ .../reference/systemModuleExportDefault.types | 16 +++++ .../cases/compiler/systemModuleConstEnums.ts | 13 ++++ ...stemModuleConstEnumsSeparateCompilation.ts | 14 ++++ .../compiler/systemModuleExportDefault.ts | 14 ++++ 13 files changed, 359 insertions(+), 8 deletions(-) create mode 100644 tests/baselines/reference/systemModuleConstEnums.js create mode 100644 tests/baselines/reference/systemModuleConstEnums.symbols create mode 100644 tests/baselines/reference/systemModuleConstEnums.types create mode 100644 tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.js create mode 100644 tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.symbols create mode 100644 tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.types create mode 100644 tests/baselines/reference/systemModuleExportDefault.js create mode 100644 tests/baselines/reference/systemModuleExportDefault.symbols create mode 100644 tests/baselines/reference/systemModuleExportDefault.types create mode 100644 tests/cases/compiler/systemModuleConstEnums.ts create mode 100644 tests/cases/compiler/systemModuleConstEnumsSeparateCompilation.ts create mode 100644 tests/cases/compiler/systemModuleExportDefault.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 5e2ead605f9..bc65e892a42 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4374,15 +4374,18 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { return; } - if (!(node.flags & NodeFlags.Export) || isES6ExportedDeclaration(node)) { - emitStart(node); - if (isES6ExportedDeclaration(node)) { - write("export "); + if (!shouldHoistDeclarationInSystemJsModule(node)) { + // do not emit var if variable was already hoisted + if (!(node.flags & NodeFlags.Export) || isES6ExportedDeclaration(node)) { + emitStart(node); + if (isES6ExportedDeclaration(node)) { + write("export "); + } + write("var "); + emit(node.name); + emitEnd(node); + write(";"); } - write("var "); - emit(node.name); - emitEnd(node); - write(";"); } writeLine(); emitStart(node); diff --git a/tests/baselines/reference/systemModuleConstEnums.js b/tests/baselines/reference/systemModuleConstEnums.js new file mode 100644 index 00000000000..126e6266b2c --- /dev/null +++ b/tests/baselines/reference/systemModuleConstEnums.js @@ -0,0 +1,27 @@ +//// [systemModuleConstEnums.ts] + +declare function use(a: any); +const enum TopLevelConstEnum { X } + +export function foo() { + use(TopLevelConstEnum.X); + use(M.NonTopLevelConstEnum.X); +} + +module M { + export const enum NonTopLevelConstEnum { X } +} + +//// [systemModuleConstEnums.js] +System.register([], function(exports_1) { + function foo() { + use(0 /* X */); + use(0 /* X */); + } + exports_1("foo", foo); + return { + setters:[], + execute: function() { + } + } +}); diff --git a/tests/baselines/reference/systemModuleConstEnums.symbols b/tests/baselines/reference/systemModuleConstEnums.symbols new file mode 100644 index 00000000000..171f24628ec --- /dev/null +++ b/tests/baselines/reference/systemModuleConstEnums.symbols @@ -0,0 +1,35 @@ +=== tests/cases/compiler/systemModuleConstEnums.ts === + +declare function use(a: any); +>use : Symbol(use, Decl(systemModuleConstEnums.ts, 0, 0)) +>a : Symbol(a, Decl(systemModuleConstEnums.ts, 1, 21)) + +const enum TopLevelConstEnum { X } +>TopLevelConstEnum : Symbol(TopLevelConstEnum, Decl(systemModuleConstEnums.ts, 1, 29)) +>X : Symbol(TopLevelConstEnum.X, Decl(systemModuleConstEnums.ts, 2, 30)) + +export function foo() { +>foo : Symbol(foo, Decl(systemModuleConstEnums.ts, 2, 34)) + + use(TopLevelConstEnum.X); +>use : Symbol(use, Decl(systemModuleConstEnums.ts, 0, 0)) +>TopLevelConstEnum.X : Symbol(TopLevelConstEnum.X, Decl(systemModuleConstEnums.ts, 2, 30)) +>TopLevelConstEnum : Symbol(TopLevelConstEnum, Decl(systemModuleConstEnums.ts, 1, 29)) +>X : Symbol(TopLevelConstEnum.X, Decl(systemModuleConstEnums.ts, 2, 30)) + + use(M.NonTopLevelConstEnum.X); +>use : Symbol(use, Decl(systemModuleConstEnums.ts, 0, 0)) +>M.NonTopLevelConstEnum.X : Symbol(M.NonTopLevelConstEnum.X, Decl(systemModuleConstEnums.ts, 10, 44)) +>M.NonTopLevelConstEnum : Symbol(M.NonTopLevelConstEnum, Decl(systemModuleConstEnums.ts, 9, 10)) +>M : Symbol(M, Decl(systemModuleConstEnums.ts, 7, 1)) +>NonTopLevelConstEnum : Symbol(M.NonTopLevelConstEnum, Decl(systemModuleConstEnums.ts, 9, 10)) +>X : Symbol(M.NonTopLevelConstEnum.X, Decl(systemModuleConstEnums.ts, 10, 44)) +} + +module M { +>M : Symbol(M, Decl(systemModuleConstEnums.ts, 7, 1)) + + export const enum NonTopLevelConstEnum { X } +>NonTopLevelConstEnum : Symbol(NonTopLevelConstEnum, Decl(systemModuleConstEnums.ts, 9, 10)) +>X : Symbol(NonTopLevelConstEnum.X, Decl(systemModuleConstEnums.ts, 10, 44)) +} diff --git a/tests/baselines/reference/systemModuleConstEnums.types b/tests/baselines/reference/systemModuleConstEnums.types new file mode 100644 index 00000000000..193de0da3ab --- /dev/null +++ b/tests/baselines/reference/systemModuleConstEnums.types @@ -0,0 +1,37 @@ +=== tests/cases/compiler/systemModuleConstEnums.ts === + +declare function use(a: any); +>use : (a: any) => any +>a : any + +const enum TopLevelConstEnum { X } +>TopLevelConstEnum : TopLevelConstEnum +>X : TopLevelConstEnum + +export function foo() { +>foo : () => void + + use(TopLevelConstEnum.X); +>use(TopLevelConstEnum.X) : any +>use : (a: any) => any +>TopLevelConstEnum.X : TopLevelConstEnum +>TopLevelConstEnum : typeof TopLevelConstEnum +>X : TopLevelConstEnum + + use(M.NonTopLevelConstEnum.X); +>use(M.NonTopLevelConstEnum.X) : any +>use : (a: any) => any +>M.NonTopLevelConstEnum.X : M.NonTopLevelConstEnum +>M.NonTopLevelConstEnum : typeof M.NonTopLevelConstEnum +>M : typeof M +>NonTopLevelConstEnum : typeof M.NonTopLevelConstEnum +>X : M.NonTopLevelConstEnum +} + +module M { +>M : typeof M + + export const enum NonTopLevelConstEnum { X } +>NonTopLevelConstEnum : NonTopLevelConstEnum +>X : NonTopLevelConstEnum +} diff --git a/tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.js b/tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.js new file mode 100644 index 00000000000..381331a84db --- /dev/null +++ b/tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.js @@ -0,0 +1,37 @@ +//// [systemModuleConstEnumsSeparateCompilation.ts] + +declare function use(a: any); +const enum TopLevelConstEnum { X } + +export function foo() { + use(TopLevelConstEnum.X); + use(M.NonTopLevelConstEnum.X); +} + +module M { + export const enum NonTopLevelConstEnum { X } +} + +//// [systemModuleConstEnumsSeparateCompilation.js] +System.register([], function(exports_1) { + var TopLevelConstEnum, M; + function foo() { + use(TopLevelConstEnum.X); + use(M.NonTopLevelConstEnum.X); + } + exports_1("foo", foo); + return { + setters:[], + execute: function() { + (function (TopLevelConstEnum) { + TopLevelConstEnum[TopLevelConstEnum["X"] = 0] = "X"; + })(TopLevelConstEnum || (TopLevelConstEnum = {})); + (function (M) { + (function (NonTopLevelConstEnum) { + NonTopLevelConstEnum[NonTopLevelConstEnum["X"] = 0] = "X"; + })(M.NonTopLevelConstEnum || (M.NonTopLevelConstEnum = {})); + var NonTopLevelConstEnum = M.NonTopLevelConstEnum; + })(M || (M = {})); + } + } +}); diff --git a/tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.symbols b/tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.symbols new file mode 100644 index 00000000000..d57740b75e9 --- /dev/null +++ b/tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.symbols @@ -0,0 +1,35 @@ +=== tests/cases/compiler/systemModuleConstEnumsSeparateCompilation.ts === + +declare function use(a: any); +>use : Symbol(use, Decl(systemModuleConstEnumsSeparateCompilation.ts, 0, 0)) +>a : Symbol(a, Decl(systemModuleConstEnumsSeparateCompilation.ts, 1, 21)) + +const enum TopLevelConstEnum { X } +>TopLevelConstEnum : Symbol(TopLevelConstEnum, Decl(systemModuleConstEnumsSeparateCompilation.ts, 1, 29)) +>X : Symbol(TopLevelConstEnum.X, Decl(systemModuleConstEnumsSeparateCompilation.ts, 2, 30)) + +export function foo() { +>foo : Symbol(foo, Decl(systemModuleConstEnumsSeparateCompilation.ts, 2, 34)) + + use(TopLevelConstEnum.X); +>use : Symbol(use, Decl(systemModuleConstEnumsSeparateCompilation.ts, 0, 0)) +>TopLevelConstEnum.X : Symbol(TopLevelConstEnum.X, Decl(systemModuleConstEnumsSeparateCompilation.ts, 2, 30)) +>TopLevelConstEnum : Symbol(TopLevelConstEnum, Decl(systemModuleConstEnumsSeparateCompilation.ts, 1, 29)) +>X : Symbol(TopLevelConstEnum.X, Decl(systemModuleConstEnumsSeparateCompilation.ts, 2, 30)) + + use(M.NonTopLevelConstEnum.X); +>use : Symbol(use, Decl(systemModuleConstEnumsSeparateCompilation.ts, 0, 0)) +>M.NonTopLevelConstEnum.X : Symbol(M.NonTopLevelConstEnum.X, Decl(systemModuleConstEnumsSeparateCompilation.ts, 10, 44)) +>M.NonTopLevelConstEnum : Symbol(M.NonTopLevelConstEnum, Decl(systemModuleConstEnumsSeparateCompilation.ts, 9, 10)) +>M : Symbol(M, Decl(systemModuleConstEnumsSeparateCompilation.ts, 7, 1)) +>NonTopLevelConstEnum : Symbol(M.NonTopLevelConstEnum, Decl(systemModuleConstEnumsSeparateCompilation.ts, 9, 10)) +>X : Symbol(M.NonTopLevelConstEnum.X, Decl(systemModuleConstEnumsSeparateCompilation.ts, 10, 44)) +} + +module M { +>M : Symbol(M, Decl(systemModuleConstEnumsSeparateCompilation.ts, 7, 1)) + + export const enum NonTopLevelConstEnum { X } +>NonTopLevelConstEnum : Symbol(NonTopLevelConstEnum, Decl(systemModuleConstEnumsSeparateCompilation.ts, 9, 10)) +>X : Symbol(NonTopLevelConstEnum.X, Decl(systemModuleConstEnumsSeparateCompilation.ts, 10, 44)) +} diff --git a/tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.types b/tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.types new file mode 100644 index 00000000000..c3a352f66ec --- /dev/null +++ b/tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.types @@ -0,0 +1,37 @@ +=== tests/cases/compiler/systemModuleConstEnumsSeparateCompilation.ts === + +declare function use(a: any); +>use : (a: any) => any +>a : any + +const enum TopLevelConstEnum { X } +>TopLevelConstEnum : TopLevelConstEnum +>X : TopLevelConstEnum + +export function foo() { +>foo : () => void + + use(TopLevelConstEnum.X); +>use(TopLevelConstEnum.X) : any +>use : (a: any) => any +>TopLevelConstEnum.X : TopLevelConstEnum +>TopLevelConstEnum : typeof TopLevelConstEnum +>X : TopLevelConstEnum + + use(M.NonTopLevelConstEnum.X); +>use(M.NonTopLevelConstEnum.X) : any +>use : (a: any) => any +>M.NonTopLevelConstEnum.X : M.NonTopLevelConstEnum +>M.NonTopLevelConstEnum : typeof M.NonTopLevelConstEnum +>M : typeof M +>NonTopLevelConstEnum : typeof M.NonTopLevelConstEnum +>X : M.NonTopLevelConstEnum +} + +module M { +>M : typeof M + + export const enum NonTopLevelConstEnum { X } +>NonTopLevelConstEnum : NonTopLevelConstEnum +>X : NonTopLevelConstEnum +} diff --git a/tests/baselines/reference/systemModuleExportDefault.js b/tests/baselines/reference/systemModuleExportDefault.js new file mode 100644 index 00000000000..4df3ec828c1 --- /dev/null +++ b/tests/baselines/reference/systemModuleExportDefault.js @@ -0,0 +1,67 @@ +//// [tests/cases/compiler/systemModuleExportDefault.ts] //// + +//// [file1.ts] + +export default function() {} + +//// [file2.ts] +export default function foo() {} + +//// [file3.ts] +export default class {} + +//// [file4.ts] +export default class C {} + + + +//// [file1.js] +System.register([], function(exports_1) { + function default_1() { } + exports_1("default", default_1); + return { + setters:[], + execute: function() { + } + } +}); +//// [file2.js] +System.register([], function(exports_1) { + function foo() { } + exports_1("default", foo); + return { + setters:[], + execute: function() { + } + } +}); +//// [file3.js] +System.register([], function(exports_1) { + var default_1; + return { + setters:[], + execute: function() { + default_1 = (function () { + function default_1() { + } + return default_1; + })(); + exports_1("default", default_1); + } + } +}); +//// [file4.js] +System.register([], function(exports_1) { + var C; + return { + setters:[], + execute: function() { + C = (function () { + function C() { + } + return C; + })(); + exports_1("default", C); + } + } +}); diff --git a/tests/baselines/reference/systemModuleExportDefault.symbols b/tests/baselines/reference/systemModuleExportDefault.symbols new file mode 100644 index 00000000000..d6e7cde9b71 --- /dev/null +++ b/tests/baselines/reference/systemModuleExportDefault.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/file1.ts === + +No type information for this code.export default function() {} +No type information for this code. +No type information for this code.=== tests/cases/compiler/file2.ts === +export default function foo() {} +>foo : Symbol(foo, Decl(file2.ts, 0, 0)) + +=== tests/cases/compiler/file3.ts === +export default class {} +No type information for this code. +No type information for this code.=== tests/cases/compiler/file4.ts === +export default class C {} +>C : Symbol(C, Decl(file4.ts, 0, 0)) + + diff --git a/tests/baselines/reference/systemModuleExportDefault.types b/tests/baselines/reference/systemModuleExportDefault.types new file mode 100644 index 00000000000..38b5abec8ed --- /dev/null +++ b/tests/baselines/reference/systemModuleExportDefault.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/file1.ts === + +No type information for this code.export default function() {} +No type information for this code. +No type information for this code.=== tests/cases/compiler/file2.ts === +export default function foo() {} +>foo : () => void + +=== tests/cases/compiler/file3.ts === +export default class {} +No type information for this code. +No type information for this code.=== tests/cases/compiler/file4.ts === +export default class C {} +>C : C + + diff --git a/tests/cases/compiler/systemModuleConstEnums.ts b/tests/cases/compiler/systemModuleConstEnums.ts new file mode 100644 index 00000000000..6ad7f31ef91 --- /dev/null +++ b/tests/cases/compiler/systemModuleConstEnums.ts @@ -0,0 +1,13 @@ +// @module: system + +declare function use(a: any); +const enum TopLevelConstEnum { X } + +export function foo() { + use(TopLevelConstEnum.X); + use(M.NonTopLevelConstEnum.X); +} + +module M { + export const enum NonTopLevelConstEnum { X } +} \ No newline at end of file diff --git a/tests/cases/compiler/systemModuleConstEnumsSeparateCompilation.ts b/tests/cases/compiler/systemModuleConstEnumsSeparateCompilation.ts new file mode 100644 index 00000000000..2fc4707b78e --- /dev/null +++ b/tests/cases/compiler/systemModuleConstEnumsSeparateCompilation.ts @@ -0,0 +1,14 @@ +// @module: system +// @separateCompilation: true + +declare function use(a: any); +const enum TopLevelConstEnum { X } + +export function foo() { + use(TopLevelConstEnum.X); + use(M.NonTopLevelConstEnum.X); +} + +module M { + export const enum NonTopLevelConstEnum { X } +} \ No newline at end of file diff --git a/tests/cases/compiler/systemModuleExportDefault.ts b/tests/cases/compiler/systemModuleExportDefault.ts new file mode 100644 index 00000000000..102c03f0bcd --- /dev/null +++ b/tests/cases/compiler/systemModuleExportDefault.ts @@ -0,0 +1,14 @@ +// @module: system + +// @filename: file1.ts +export default function() {} + +// @filename: file2.ts +export default function foo() {} + +// @filename: file3.ts +export default class {} + +// @filename: file4.ts +export default class C {} + From 4cd012782220400028d8d13ec26a111c11832ea5 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 11 May 2015 14:52:02 -0700 Subject: [PATCH 26/33] sourcemap -> sourceMap --- src/compiler/diagnosticInformationMap.generated.ts | 4 ++-- src/compiler/diagnosticMessages.json | 4 ++-- src/compiler/program.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 52718c6ddc4..ffb1e301b83 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -444,8 +444,8 @@ module ts { Unknown_compiler_option_0: { code: 5023, category: DiagnosticCategory.Error, key: "Unknown compiler option '{0}'." }, Compiler_option_0_requires_a_value_of_type_1: { code: 5024, category: DiagnosticCategory.Error, key: "Compiler option '{0}' requires a value of type {1}." }, Could_not_write_file_0_Colon_1: { code: 5033, category: DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" }, - Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified without specifying 'sourcemap' option." }, - Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: DiagnosticCategory.Error, key: "Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option." }, + Option_mapRoot_cannot_be_specified_without_specifying_sourceMap_option: { code: 5038, category: DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified without specifying 'sourceMap' option." }, + Option_sourceRoot_cannot_be_specified_without_specifying_sourceMap_option: { code: 5039, category: DiagnosticCategory.Error, key: "Option 'sourceRoot' cannot be specified without specifying 'sourceMap' option." }, Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." }, Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'declaration'." }, Option_project_cannot_be_mixed_with_source_files_on_a_command_line: { code: 5042, category: DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index d7446907d23..fac1c4bf49a 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1765,11 +1765,11 @@ "category": "Error", "code": 5033 }, - "Option 'mapRoot' cannot be specified without specifying 'sourcemap' option.": { + "Option 'mapRoot' cannot be specified without specifying 'sourceMap' option.": { "category": "Error", "code": 5038 }, - "Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option.": { + "Option 'sourceRoot' cannot be specified without specifying 'sourceMap' option.": { "category": "Error", "code": 5039 }, diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 29dcd1d4932..f447c1d9f99 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -574,10 +574,10 @@ module ts { if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) { // Error to specify --mapRoot or --sourceRoot without mapSourceFiles if (options.mapRoot) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option)); + diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_mapRoot_cannot_be_specified_without_specifying_sourceMap_option)); } if (options.sourceRoot) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option)); + diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_sourceRoot_cannot_be_specified_without_specifying_sourceMap_option)); } return; } From 99b6e26831ac5fef316e84b91a15a22414888f02 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 11 May 2015 15:01:29 -0700 Subject: [PATCH 27/33] Accepted baselines. --- .../amd/mapRootSourceRootWithNoSourceMapOption.errors.txt | 8 ++++---- .../mapRootSourceRootWithNoSourceMapOption.errors.txt | 8 ++++---- .../amd/mapRootWithNoSourceMapOption.errors.txt | 4 ++-- .../node/mapRootWithNoSourceMapOption.errors.txt | 4 ++-- .../amd/sourceRootWithNoSourceMapOption.errors.txt | 4 ++-- .../node/sourceRootWithNoSourceMapOption.errors.txt | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/amd/mapRootSourceRootWithNoSourceMapOption.errors.txt b/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/amd/mapRootSourceRootWithNoSourceMapOption.errors.txt index 0d3528b6dc3..47d1f6df86e 100644 --- a/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/amd/mapRootSourceRootWithNoSourceMapOption.errors.txt +++ b/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/amd/mapRootSourceRootWithNoSourceMapOption.errors.txt @@ -1,9 +1,9 @@ -error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option. -error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option. +error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourceMap' option. +error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourceMap' option. -!!! error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option. -!!! error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option. +!!! error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourceMap' option. +!!! error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourceMap' option. ==== m1.ts (0 errors) ==== var m1_a1 = 10; class m1_c1 { diff --git a/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/node/mapRootSourceRootWithNoSourceMapOption.errors.txt b/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/node/mapRootSourceRootWithNoSourceMapOption.errors.txt index 0d3528b6dc3..47d1f6df86e 100644 --- a/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/node/mapRootSourceRootWithNoSourceMapOption.errors.txt +++ b/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/node/mapRootSourceRootWithNoSourceMapOption.errors.txt @@ -1,9 +1,9 @@ -error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option. -error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option. +error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourceMap' option. +error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourceMap' option. -!!! error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option. -!!! error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option. +!!! error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourceMap' option. +!!! error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourceMap' option. ==== m1.ts (0 errors) ==== var m1_a1 = 10; class m1_c1 { diff --git a/tests/baselines/reference/project/mapRootWithNoSourceMapOption/amd/mapRootWithNoSourceMapOption.errors.txt b/tests/baselines/reference/project/mapRootWithNoSourceMapOption/amd/mapRootWithNoSourceMapOption.errors.txt index 01a3526196c..d00f552ef97 100644 --- a/tests/baselines/reference/project/mapRootWithNoSourceMapOption/amd/mapRootWithNoSourceMapOption.errors.txt +++ b/tests/baselines/reference/project/mapRootWithNoSourceMapOption/amd/mapRootWithNoSourceMapOption.errors.txt @@ -1,7 +1,7 @@ -error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option. +error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourceMap' option. -!!! error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option. +!!! error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourceMap' option. ==== m1.ts (0 errors) ==== var m1_a1 = 10; class m1_c1 { diff --git a/tests/baselines/reference/project/mapRootWithNoSourceMapOption/node/mapRootWithNoSourceMapOption.errors.txt b/tests/baselines/reference/project/mapRootWithNoSourceMapOption/node/mapRootWithNoSourceMapOption.errors.txt index 01a3526196c..d00f552ef97 100644 --- a/tests/baselines/reference/project/mapRootWithNoSourceMapOption/node/mapRootWithNoSourceMapOption.errors.txt +++ b/tests/baselines/reference/project/mapRootWithNoSourceMapOption/node/mapRootWithNoSourceMapOption.errors.txt @@ -1,7 +1,7 @@ -error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option. +error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourceMap' option. -!!! error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourcemap' option. +!!! error TS5038: Option 'mapRoot' cannot be specified without specifying 'sourceMap' option. ==== m1.ts (0 errors) ==== var m1_a1 = 10; class m1_c1 { diff --git a/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/amd/sourceRootWithNoSourceMapOption.errors.txt b/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/amd/sourceRootWithNoSourceMapOption.errors.txt index b7abc0c2d52..f4b65c12f35 100644 --- a/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/amd/sourceRootWithNoSourceMapOption.errors.txt +++ b/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/amd/sourceRootWithNoSourceMapOption.errors.txt @@ -1,7 +1,7 @@ -error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option. +error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourceMap' option. -!!! error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option. +!!! error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourceMap' option. ==== m1.ts (0 errors) ==== var m1_a1 = 10; class m1_c1 { diff --git a/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/node/sourceRootWithNoSourceMapOption.errors.txt b/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/node/sourceRootWithNoSourceMapOption.errors.txt index b7abc0c2d52..f4b65c12f35 100644 --- a/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/node/sourceRootWithNoSourceMapOption.errors.txt +++ b/tests/baselines/reference/project/sourceRootWithNoSourceMapOption/node/sourceRootWithNoSourceMapOption.errors.txt @@ -1,7 +1,7 @@ -error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option. +error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourceMap' option. -!!! error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option. +!!! error TS5039: Option 'sourceRoot' cannot be specified without specifying 'sourceMap' option. ==== m1.ts (0 errors) ==== var m1_a1 = 10; class m1_c1 { From af342382ededd6e1bafae9a8ca82a15c18885135 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 12 May 2015 10:57:55 -0700 Subject: [PATCH 28/33] add optional 'getProjectVersion' method to perform fast up-to-date checks --- src/services/services.ts | 14 ++++++++++++++ src/services/shims.ts | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/services/services.ts b/src/services/services.ts index bec00b9a66a..4374f3f3ea8 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -949,6 +949,7 @@ module ts { export interface LanguageServiceHost { getCompilationSettings(): CompilerOptions; getNewLine?(): string; + getProjectVersion?(): string; getScriptFileNames(): string[]; getScriptVersion(fileName: string): string; getScriptSnapshot(fileName: string): IScriptSnapshot; @@ -2353,6 +2354,7 @@ module ts { let syntaxTreeCache: SyntaxTreeCache = new SyntaxTreeCache(host); let ruleProvider: formatting.RulesProvider; let program: Program; + let lastProjectVersion: string; let useCaseSensitivefileNames = false; let cancellationToken = new CancellationTokenObject(host.getCancellationToken && host.getCancellationToken()); @@ -2392,6 +2394,18 @@ module ts { } function synchronizeHostData(): void { + // perform fast check if host supports it + if (host.getProjectVersion) { + let hostProjectVersion = host.getProjectVersion(); + if (hostProjectVersion) { + if (lastProjectVersion === hostProjectVersion) { + return; + } + + lastProjectVersion = hostProjectVersion; + } + } + // Get a fresh cache of the host information let hostCache = new HostCache(host, getCanonicalFileName); diff --git a/src/services/shims.ts b/src/services/shims.ts index 869c707d175..27c70ddc878 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -55,6 +55,7 @@ module ts { getCurrentDirectory(): string; getDefaultLibFileName(options: string): string; getNewLine?(): string; + getProjectVersion?(): string; } /** Public interface of the the of a config service shim instance.*/ @@ -260,6 +261,15 @@ module ts { this.shimHost.error(s); } + public getProjectVersion(): string { + if (!this.shimHost.getProjectVersion) { + // shimmed host does not support getProjectVersion + return undefined; + } + + return this.shimHost.getProjectVersion(); + } + public getCompilationSettings(): CompilerOptions { var settingsJson = this.shimHost.getCompilationSettings(); if (settingsJson == null || settingsJson == "") { From 05f753918cddb89e536761eb7fd57dc73a07b11f Mon Sep 17 00:00:00 2001 From: Dan Quirk Date: Tue, 12 May 2015 14:31:38 -0700 Subject: [PATCH 29/33] Update help description for noEmitOnError --- src/compiler/commandLineParser.ts | 2 +- src/compiler/diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 6a055aebf6a..7a589fe61cb 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -88,7 +88,7 @@ module ts { { name: "noEmitOnError", type: "boolean", - description: Diagnostics.Do_not_emit_outputs_if_any_type_checking_errors_were_reported, + description: Diagnostics.Do_not_emit_outputs_if_any_errors_were_reported, }, { name: "noImplicitAny", diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index ffb1e301b83..32dc590eeec 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -465,7 +465,7 @@ module ts { Watch_input_files: { code: 6005, category: DiagnosticCategory.Message, key: "Watch input files." }, Redirect_output_structure_to_the_directory: { code: 6006, category: DiagnosticCategory.Message, key: "Redirect output structure to the directory." }, Do_not_erase_const_enum_declarations_in_generated_code: { code: 6007, category: DiagnosticCategory.Message, key: "Do not erase const enum declarations in generated code." }, - Do_not_emit_outputs_if_any_type_checking_errors_were_reported: { code: 6008, category: DiagnosticCategory.Message, key: "Do not emit outputs if any type checking errors were reported." }, + Do_not_emit_outputs_if_any_errors_were_reported: { code: 6008, category: DiagnosticCategory.Message, key: "Do not emit outputs if any errors were reported." }, Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." }, Do_not_emit_outputs: { code: 6010, category: DiagnosticCategory.Message, key: "Do not emit outputs." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index fac1c4bf49a..a3dfd62d34e 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1850,7 +1850,7 @@ "category": "Message", "code": 6007 }, - "Do not emit outputs if any type checking errors were reported.": { + "Do not emit outputs if any errors were reported.": { "category": "Message", "code": 6008 }, From c4b6e64ca63795b6d8c1343ce58ca238c1eb0c34 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 12 May 2015 15:49:41 -0700 Subject: [PATCH 30/33] Emit [...a] as a.slice() to ensure a is copied --- src/compiler/emitter.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index c16daf298c1..e9611188434 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1366,7 +1366,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { return true; } - function emitListWithSpread(elements: Expression[], multiLine: boolean, trailingComma: boolean) { + function emitListWithSpread(elements: Expression[], alwaysCopy: boolean, multiLine: boolean, trailingComma: boolean) { let pos = 0; let group = 0; let length = elements.length; @@ -1383,6 +1383,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { e = (e).expression; emitParenthesizedIf(e, /*parenthesized*/ group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); pos++; + if (pos === length && group === 0 && alwaysCopy) { + write(".slice()"); + } } else { let i = pos; @@ -1422,7 +1425,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { write("]"); } else { - emitListWithSpread(elements, /*multiLine*/(node.flags & NodeFlags.MultiLine) !== 0, + emitListWithSpread(elements, /*alwaysCopy*/ true, /*multiLine*/(node.flags & NodeFlags.MultiLine) !== 0, /*trailingComma*/ elements.hasTrailingComma); } } @@ -1847,7 +1850,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { write("void 0"); } write(", "); - emitListWithSpread(node.arguments, /*multiLine*/ false, /*trailingComma*/ false); + emitListWithSpread(node.arguments, /*alwaysCopy*/ false, /*multiLine*/ false, /*trailingComma*/ false); write(")"); } From fe4dd84d198a5ef4feda11a9fd765d809a64b97a Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 12 May 2015 15:51:20 -0700 Subject: [PATCH 31/33] Accepting new baselines --- tests/baselines/reference/arrayLiteralSpread.js | 6 +++--- tests/baselines/reference/arrayLiterals2ES5.js | 16 ++++++++-------- tests/baselines/reference/arrayLiterals3.js | 4 ++-- ...turingArrayBindingPatternAndAssignment1ES5.js | 2 +- ...ructuringArrayBindingPatternAndAssignment2.js | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/baselines/reference/arrayLiteralSpread.js b/tests/baselines/reference/arrayLiteralSpread.js index 73a60714526..5e4fcedf9d6 100644 --- a/tests/baselines/reference/arrayLiteralSpread.js +++ b/tests/baselines/reference/arrayLiteralSpread.js @@ -26,7 +26,7 @@ function f2() { //// [arrayLiteralSpread.js] function f0() { var a = [1, 2, 3]; - var a1 = a; + var a1 = a.slice(); var a2 = [1].concat(a); var a3 = [1, 2].concat(a); var a4 = a.concat([1]); @@ -41,6 +41,6 @@ function f1() { var b; } function f2() { - var a = []; - var b = [5]; + var a = [].slice().slice().slice().slice().slice(); + var b = [5].slice().slice().slice().slice().slice(); } diff --git a/tests/baselines/reference/arrayLiterals2ES5.js b/tests/baselines/reference/arrayLiterals2ES5.js index 0ff82e90970..689655fb302 100644 --- a/tests/baselines/reference/arrayLiterals2ES5.js +++ b/tests/baselines/reference/arrayLiterals2ES5.js @@ -93,12 +93,12 @@ var temp2 = [[1, 2, 3], ["hello", "string"]]; var temp3 = [undefined, null, undefined]; var temp4 = []; var d0 = [1, true].concat(temp); // has type (string|number|boolean)[] -var d1 = temp; // has type string[] -var d2 = temp1; -var d3 = temp1; +var d1 = temp.slice(); // has type string[] +var d2 = temp1.slice(); +var d3 = temp1.slice(); var d4 = temp.concat(temp1); -var d5 = temp3; -var d6 = temp4; -var d7 = temp1; -var d8 = [temp1]; -var d9 = [temp1].concat(["hello"]); +var d5 = temp3.slice(); +var d6 = temp4.slice(); +var d7 = temp1.slice().slice(); +var d8 = [temp1.slice()]; +var d9 = [temp1.slice()].concat(["hello"]); diff --git a/tests/baselines/reference/arrayLiterals3.js b/tests/baselines/reference/arrayLiterals3.js index 091c6148068..4769c069988 100644 --- a/tests/baselines/reference/arrayLiterals3.js +++ b/tests/baselines/reference/arrayLiterals3.js @@ -55,6 +55,6 @@ var _a = [1, 2, "string", true], b1 = _a[0], b2 = _a[1]; var temp = ["s", "t", "r"]; var temp1 = [1, 2, 3]; var temp2 = [[1, 2, 3], ["hello", "string"]]; -var c0 = temp2; // Error -var c1 = temp1; // Error cannot assign number[] to [number, number, number] +var c0 = temp2.slice(); // Error +var c1 = temp1.slice(); // Error cannot assign number[] to [number, number, number] var c2 = temp1.concat(temp); // Error cannot assign (number|string)[] to number[] diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js index bf71064264a..4f071b5e5ec 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js @@ -88,7 +88,7 @@ var _e = foo(), b6 = _e[0], b7 = _e[1]; var b8 = foo().slice(0); // S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. var temp = [1, 2, 3]; -var _f = temp, c0 = _f[0], c1 = _f[1]; +var _f = temp.slice(), c0 = _f[0], c1 = _f[1]; var c2 = [][0]; var _g = [[[]], [[[[]]]]], c3 = _g[0][0][0], c4 = _g[1][0][0][0][0]; var _h = [[1], true], c5 = _h[0][0], c6 = _h[1]; diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js index fdbf47fd970..223090ea8ca 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js @@ -50,8 +50,8 @@ var _c = bar(), _d = _c[0], b3 = _d === void 0 ? "string" : _d, b4 = _c[1], b5 = // V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, // S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. var temp = [1, 2, 3]; -var _e = temp, c0 = _e[0], c1 = _e[1]; // Error -var _f = temp, c2 = _f[0], c3 = _f[1]; // Error +var _e = temp.slice(), c0 = _e[0], c1 = _e[1]; // Error +var _f = temp.slice(), c2 = _f[0], c3 = _f[1]; // Error function foo(idx) { return { 2: true From 36290537c30255ac163d37949402fc703b20b9f4 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 12 May 2015 16:53:53 -0700 Subject: [PATCH 32/33] Optimize spread to not generate x.slice() when x is an array literal --- src/compiler/emitter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index e9611188434..38a84af6c05 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1383,7 +1383,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { e = (e).expression; emitParenthesizedIf(e, /*parenthesized*/ group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); pos++; - if (pos === length && group === 0 && alwaysCopy) { + if (pos === length && group === 0 && alwaysCopy && e.kind !== SyntaxKind.ArrayLiteralExpression) { write(".slice()"); } } From 8db3b76295313a2feda69751267e4f6953cc448f Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 12 May 2015 16:54:34 -0700 Subject: [PATCH 33/33] Accepting new baselines --- tests/baselines/reference/arrayLiteralSpread.js | 4 ++-- tests/baselines/reference/arrayLiterals2ES5.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/baselines/reference/arrayLiteralSpread.js b/tests/baselines/reference/arrayLiteralSpread.js index 5e4fcedf9d6..3561189671e 100644 --- a/tests/baselines/reference/arrayLiteralSpread.js +++ b/tests/baselines/reference/arrayLiteralSpread.js @@ -41,6 +41,6 @@ function f1() { var b; } function f2() { - var a = [].slice().slice().slice().slice().slice(); - var b = [5].slice().slice().slice().slice().slice(); + var a = []; + var b = [5]; } diff --git a/tests/baselines/reference/arrayLiterals2ES5.js b/tests/baselines/reference/arrayLiterals2ES5.js index 689655fb302..6a81ab465a2 100644 --- a/tests/baselines/reference/arrayLiterals2ES5.js +++ b/tests/baselines/reference/arrayLiterals2ES5.js @@ -99,6 +99,6 @@ var d3 = temp1.slice(); var d4 = temp.concat(temp1); var d5 = temp3.slice(); var d6 = temp4.slice(); -var d7 = temp1.slice().slice(); +var d7 = temp1.slice(); var d8 = [temp1.slice()]; var d9 = [temp1.slice()].concat(["hello"]);