From 4d3e842e9f3e5a7d521662dbb01966bb86875c1b Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Mon, 16 Mar 2015 16:47:50 -0700 Subject: [PATCH 01/28] Add assert to make sure getOccurences at position only returns results for the file we request the occurences for. --- src/services/services.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/services/services.ts b/src/services/services.ts index 1bf5f6336d..edb7032b81 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3571,8 +3571,22 @@ module ts { } } - /// References and Occurrences function getOccurrencesAtPosition(fileName: string, position: number): ReferenceEntry[] { + let results = getOccurrencesAtPositionCore(fileName, position); + + let sourceFile = getCanonicalFileName(normalizeSlashes(fileName)); + + // ensure the results are in the file we're interested in + results.forEach((value) => { + let targetFile = getCanonicalFileName(normalizeSlashes(value.fileName)); + Debug.assert(sourceFile == targetFile, `Unexpected file in results. Found results in ${targetFile} expected only results in ${sourceFile}.`); + }); + + return results; + } + + /// References and Occurrences + function getOccurrencesAtPositionCore(fileName: string, position: number): ReferenceEntry[] { synchronizeHostData(); let sourceFile = getValidSourceFile(fileName); From 325c8b655fe7cd50af49ec5e0be057e7c8140ffa Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Mon, 16 Mar 2015 17:29:56 -0700 Subject: [PATCH 02/28] Add a check to make sure we have results. --- src/services/services.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index edb7032b81..4458a45ed0 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3573,14 +3573,16 @@ module ts { function getOccurrencesAtPosition(fileName: string, position: number): ReferenceEntry[] { let results = getOccurrencesAtPositionCore(fileName, position); + + if (results) { + let sourceFile = getCanonicalFileName(normalizeSlashes(fileName)); - let sourceFile = getCanonicalFileName(normalizeSlashes(fileName)); - - // ensure the results are in the file we're interested in - results.forEach((value) => { - let targetFile = getCanonicalFileName(normalizeSlashes(value.fileName)); - Debug.assert(sourceFile == targetFile, `Unexpected file in results. Found results in ${targetFile} expected only results in ${sourceFile}.`); - }); + // ensure the results are in the file we're interested in + results.forEach((value) => { + let targetFile = getCanonicalFileName(normalizeSlashes(value.fileName)); + Debug.assert(sourceFile == targetFile, `Unexpected file in results. Found results in ${targetFile} expected only results in ${sourceFile}.`); + }); + } return results; } From 36ea7c8d7725b978d32da5d5975faad5cb96a9f8 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 19 Mar 2015 14:36:30 -0700 Subject: [PATCH 03/28] Emit destructuring in parameter --- src/compiler/declarationEmitter.ts | 3 +- ...clarationEmitDestructuringArrayPattern5.js | 37 +++++++++++++++++++ ...rationEmitDestructuringArrayPattern5.types | 33 +++++++++++++++++ ...ingOptionalBindingParametersInOverloads.js | 4 +- ...ionEmitDestructuringParameterProperties.js | 6 +-- ...tructuringWithOptionalBindingParameters.js | 4 +- ...clarationEmitDestructuringArrayPattern5.ts | 5 +++ 7 files changed, 84 insertions(+), 8 deletions(-) create mode 100644 tests/baselines/reference/declarationEmitDestructuringArrayPattern5.js create mode 100644 tests/baselines/reference/declarationEmitDestructuringArrayPattern5.types create mode 100644 tests/cases/compiler/declarationEmitDestructuringArrayPattern5.ts diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index cf75467e1c..6509ae6e2c 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -1291,7 +1291,8 @@ module ts { write("..."); } if (isBindingPattern(node.name)) { - write("_" + indexOf((node.parent).parameters, node)); + // By emitting binding pattern as binding pattern in function parameters, language service can provide better signature help + write(getTextOfNode(node.name)); } else { writeTextOfNode(currentSourceFile, node.name); diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern5.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern5.js new file mode 100644 index 0000000000..9e8dee3285 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern5.js @@ -0,0 +1,37 @@ +//// [declarationEmitDestructuringArrayPattern5.ts] +function foo([a, b, c]: [string, string, string]): void { } +function far([a, [b], [[c]]]: [number, boolean[], string[][]]): void { } +function bar({a1, b1, c1}: { a1: number, b1: boolean, c1: string }): void { } +function baz({a2, b2: {b1, c1}}: { a2: number, b2: { b1: boolean, c1: string } }): void { } + + +//// [declarationEmitDestructuringArrayPattern5.js] +function foo(_a) { + var a = _a[0], b = _a[1], c = _a[2]; +} +function far(_a) { + var a = _a[0], b = _a[1][0], c = _a[2][0][0]; +} +function bar(_a) { + var a1 = _a.a1, b1 = _a.b1, c1 = _a.c1; +} +function baz(_a) { + var a2 = _a.a2, _b = _a.b2, b1 = _b.b1, c1 = _b.c1; +} + + +//// [declarationEmitDestructuringArrayPattern5.d.ts] +declare function foo([a, b, c]: [string, string, string]): void; +declare function far([a, [b], [[c]]]: [number, boolean[], string[][]]): void; +declare function bar({a1, b1, c1}: { + a1: number; + b1: boolean; + c1: string; +}): void; +declare function baz({a2, b2: {b1, c1}}: { + a2: number; + b2: { + b1: boolean; + c1: string; + }; +}): void; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern5.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern5.types new file mode 100644 index 0000000000..fdb2bba88e --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern5.types @@ -0,0 +1,33 @@ +=== tests/cases/compiler/declarationEmitDestructuringArrayPattern5.ts === +function foo([a, b, c]: [string, string, string]): void { } +>foo : ([a, b, c]: [string, string, string]) => void +>a : string +>b : string +>c : string + +function far([a, [b], [[c]]]: [number, boolean[], string[][]]): void { } +>far : ([a, [b], [[c]]]: [number, boolean[], string[][]]) => void +>a : number +>b : boolean +>c : string + +function bar({a1, b1, c1}: { a1: number, b1: boolean, c1: string }): void { } +>bar : ({a1, b1, c1}: { a1: number; b1: boolean; c1: string; }) => void +>a1 : number +>b1 : boolean +>c1 : string +>a1 : number +>b1 : boolean +>c1 : string + +function baz({a2, b2: {b1, c1}}: { a2: number, b2: { b1: boolean, c1: string } }): void { } +>baz : ({a2, b2: {b1, c1}}: { a2: number; b2: { b1: boolean; c1: string; }; }) => void +>a2 : number +>b2 : unknown +>b1 : boolean +>c1 : string +>a2 : number +>b2 : { b1: boolean; c1: string; } +>b1 : boolean +>c1 : string + diff --git a/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js index c907add11f..d44c9d4236 100644 --- a/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js +++ b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js @@ -25,8 +25,8 @@ function foo2() { //// [declarationEmitDestructuringOptionalBindingParametersInOverloads.d.ts] -declare function foo(_0?: [string, number, boolean]): any; -declare function foo2(_0?: { +declare function foo([x, y, z]?: [string, number, boolean]): any; +declare function foo2({ x, y, z }?: { x: string; y: number; z: boolean; diff --git a/tests/baselines/reference/declarationEmitDestructuringParameterProperties.js b/tests/baselines/reference/declarationEmitDestructuringParameterProperties.js index cfe4acc173..841508c331 100644 --- a/tests/baselines/reference/declarationEmitDestructuringParameterProperties.js +++ b/tests/baselines/reference/declarationEmitDestructuringParameterProperties.js @@ -43,12 +43,12 @@ var C3 = (function () { //// [declarationEmitDestructuringParameterProperties.d.ts] declare class C1 { x: string, y: string, z: string; - constructor(_0: string[]); + constructor([x, y, z]: string[]); } declare type TupleType1 = [string, number, boolean]; declare class C2 { x: string, y: number, z: boolean; - constructor(_0: TupleType1); + constructor([x, y, z]: TupleType1); } declare type ObjType1 = { x: number; @@ -57,5 +57,5 @@ declare type ObjType1 = { }; declare class C3 { x: number, y: string, z: boolean; - constructor(_0: ObjType1); + constructor({ x, y, z }: ObjType1); } diff --git a/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.js b/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.js index 284cf10778..9ffd25a7fa 100644 --- a/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.js +++ b/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.js @@ -14,8 +14,8 @@ function foo1(_a) { //// [declarationEmitDestructuringWithOptionalBindingParameters.d.ts] -declare function foo(_0?: [string, number, boolean]): void; -declare function foo1(_0?: { +declare function foo([x,y,z]?: [string, number, boolean]): void; +declare function foo1({ x, y, z }?: { x: string; y: number; z: boolean; diff --git a/tests/cases/compiler/declarationEmitDestructuringArrayPattern5.ts b/tests/cases/compiler/declarationEmitDestructuringArrayPattern5.ts new file mode 100644 index 0000000000..c610e24f93 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringArrayPattern5.ts @@ -0,0 +1,5 @@ +// @declaration: true +function foo([a, b, c]: [string, string, string]): void { } +function far([a, [b], [[c]]]: [number, boolean[], string[][]]): void { } +function bar({a1, b1, c1}: { a1: number, b1: boolean, c1: string }): void { } +function baz({a2, b2: {b1, c1}}: { a2: number, b2: { b1: boolean, c1: string } }): void { } From b5065f1f3aaa9817b9e5c060bb30927714faeb0f Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 19 Mar 2015 14:42:57 -0700 Subject: [PATCH 04/28] Allow destructuring in ambient context --- src/compiler/checker.ts | 3 --- .../reference/declarationInAmbientContext.errors.txt | 12 ------------ .../reference/declarationInAmbientContext.types | 9 +++++++++ 3 files changed, 9 insertions(+), 15 deletions(-) delete mode 100644 tests/baselines/reference/declarationInAmbientContext.errors.txt create mode 100644 tests/baselines/reference/declarationInAmbientContext.types diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d50e440c5e..f67b721465 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12005,9 +12005,6 @@ module ts { function checkGrammarVariableDeclaration(node: VariableDeclaration) { if (node.parent.parent.kind !== SyntaxKind.ForInStatement && node.parent.parent.kind !== SyntaxKind.ForOfStatement) { if (isInAmbientContext(node)) { - if (isBindingPattern(node.name)) { - return grammarErrorOnNode(node, Diagnostics.Destructuring_declarations_are_not_allowed_in_ambient_contexts); - } if (node.initializer) { // Error on equals token which immediate precedes the initializer let equalsTokenLength = "=".length; diff --git a/tests/baselines/reference/declarationInAmbientContext.errors.txt b/tests/baselines/reference/declarationInAmbientContext.errors.txt deleted file mode 100644 index 338da990a0..0000000000 --- a/tests/baselines/reference/declarationInAmbientContext.errors.txt +++ /dev/null @@ -1,12 +0,0 @@ -tests/cases/conformance/es6/destructuring/declarationInAmbientContext.ts(1,13): error TS1183: Destructuring declarations are not allowed in ambient contexts. -tests/cases/conformance/es6/destructuring/declarationInAmbientContext.ts(2,13): error TS1183: Destructuring declarations are not allowed in ambient contexts. - - -==== tests/cases/conformance/es6/destructuring/declarationInAmbientContext.ts (2 errors) ==== - declare var [a, b]; // Error, destructuring declaration not allowed in ambient context - ~~~~~~ -!!! error TS1183: Destructuring declarations are not allowed in ambient contexts. - declare var {c, d}; // Error, destructuring declaration not allowed in ambient context - ~~~~~~ -!!! error TS1183: Destructuring declarations are not allowed in ambient contexts. - \ No newline at end of file diff --git a/tests/baselines/reference/declarationInAmbientContext.types b/tests/baselines/reference/declarationInAmbientContext.types new file mode 100644 index 0000000000..ecdd3b7c7e --- /dev/null +++ b/tests/baselines/reference/declarationInAmbientContext.types @@ -0,0 +1,9 @@ +=== tests/cases/conformance/es6/destructuring/declarationInAmbientContext.ts === +declare var [a, b]; // Error, destructuring declaration not allowed in ambient context +>a : any +>b : any + +declare var {c, d}; // Error, destructuring declaration not allowed in ambient context +>c : any +>d : any + From 5979dacf4f0278278b42749aa2ae7f146326bdac Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 23 Mar 2015 11:30:51 -0700 Subject: [PATCH 05/28] Correctly emit bidning pattern with initializer and rest --- src/compiler/declarationEmitter.ts | 99 +++++++++++++++---- ...clarationEmitDestructuringArrayPattern6.js | 65 ++++++++++++ ...rationEmitDestructuringArrayPattern6.types | 49 +++++++++ ...clarationEmitDestructuringArrayPattern7.js | 20 ++++ ...rationEmitDestructuringArrayPattern7.types | 13 +++ ...ingOptionalBindingParametersInOverloads.js | 2 +- ...ionEmitDestructuringParameterProperties.js | 2 +- ...tructuringWithOptionalBindingParameters.js | 4 +- ...clarationEmitDestructuringArrayPattern6.ts | 5 + ...clarationEmitDestructuringArrayPattern7.ts | 3 + 10 files changed, 237 insertions(+), 25 deletions(-) create mode 100644 tests/baselines/reference/declarationEmitDestructuringArrayPattern6.js create mode 100644 tests/baselines/reference/declarationEmitDestructuringArrayPattern6.types create mode 100644 tests/baselines/reference/declarationEmitDestructuringArrayPattern7.js create mode 100644 tests/baselines/reference/declarationEmitDestructuringArrayPattern7.types create mode 100644 tests/cases/compiler/declarationEmitDestructuringArrayPattern6.ts create mode 100644 tests/cases/compiler/declarationEmitDestructuringArrayPattern7.ts diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 6509ae6e2c..93e0fa3129 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -1291,8 +1291,10 @@ module ts { write("..."); } if (isBindingPattern(node.name)) { - // By emitting binding pattern as binding pattern in function parameters, language service can provide better signature help - write(getTextOfNode(node.name)); + // For bindingPattern, we can't simply writeTextOfNode from the source file + // because we want to omit the initializer and using writeTextOfNode will result in initializer get emitted. + // Therefore, we will have to recursively emit each element in the bindingPattern. + emitBindingPattern(node.name); } else { writeTextOfNode(currentSourceFile, node.name); @@ -1312,41 +1314,46 @@ module ts { } function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - let diagnosticMessage: DiagnosticMessage; + let diagnosticMessage: DiagnosticMessage = getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult); + return diagnosticMessage !== undefined ? { + diagnosticMessage, + errorNode: node, + typeName: node.name + } : undefined; + } + + function getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult: SymbolAccessiblityResult) { switch (node.parent.kind) { case SyntaxKind.Constructor: - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1; - break; case SyntaxKind.ConstructSignature: // Interfaces cannot have parameter types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + return symbolAccesibilityResult.errorModuleName ? Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; - break; case SyntaxKind.CallSignature: // Interfaces cannot have parameter types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + return symbolAccesibilityResult.errorModuleName ? Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; - break; case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: if (node.parent.flags & NodeFlags.Static) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : @@ -1354,30 +1361,80 @@ module ts { } else { // Interfaces cannot have parameter types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + return symbolAccesibilityResult.errorModuleName ? Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } - break; case SyntaxKind.FunctionDeclaration: - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1; - break; default: Debug.fail("This is unknown parent for parameter: " + node.parent.kind); } - - return { - diagnosticMessage, - errorNode: node, - typeName: node.name - }; } + + function emitBindingPattern(bindingPattern: BindingPattern) { + // We have to explicitly emit square bracket and bracket because these tokens are not store inside the node. + if (bindingPattern.kind === SyntaxKind.ObjectBindingPattern) { + write("{"); + emitCommaList(bindingPattern.elements, emitBindingElement); + write("}"); + } + else if (bindingPattern.kind === SyntaxKind.ArrayBindingPattern) { + write("["); + emitCommaList(bindingPattern.elements, emitBindingElement); + write("]"); + } + } + + function emitBindingElement(bindingElement: BindingElement) { + function getBindingElementTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + let diagnosticMessage = getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult); + return diagnosticMessage !== undefined ? { + diagnosticMessage, + errorNode: bindingElement, + typeName: bindingElement.name + } : undefined; + } + + if (bindingElement.propertyName) { + // bindingElement has propertyName property in the following case: + // { y: [a,b,c] ...} -> bindingPattern will have a property called propertyName for "y" + // We have to explicitly emit the propertyName before descending into its binding elements. + // Example: + // original: function foo({y: [a,b,c]}) {} + // emit : declare function foo({y: [a, b, c]}: { y: [any, any, any] }) void; + writeTextOfNode(currentSourceFile, bindingElement.propertyName); + write(": "); + + // If bindingElement has propertyName property, then its name must be another bindingPattern of SyntaxKind.ObjectBindingPattern + emitBindingPattern(bindingElement.name); + } + else if (bindingElement.name) { + if (isBindingPattern(bindingElement.name)) { + // If it is a nested binding pattern, we will recursively descend into each element and emit each one separately. + // In the case of rest element, we will omit rest element. + // Example: + // original: function foo([a, [[b]], c] = [1,[["string"]], 3]) {} + // emit : declare function foo([a, [[b]], c]: [number, [[string]], number]): void; + // original with rest: function foo([a ...c]) {} + // emit : declare function foo([a, c]): void; + emitBindingPattern(bindingElement.name); + } + else { + // If the node is just an identifier, we will simply emit the text associated with the node's name + // Example: + // original: function foo({y = 10, x}) {} + // emit : declare function foo({y, x}: {number, any}): void; + writeTextOfNode(currentSourceFile, bindingElement.name); + } + } + } } function emitNode(node: Node) { diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern6.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern6.js new file mode 100644 index 0000000000..803ea9fe01 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern6.js @@ -0,0 +1,65 @@ +//// [declarationEmitDestructuringArrayPattern6.ts] +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}}]){ } +function h1([a, [b], [[c]], {x = 10, y = [1, 2, 3], z: {a1, b1}}]){ } + +//// [declarationEmitDestructuringArrayPattern6.js] +function f(_a) { + var _b = _a === void 0 ? { + x: 10, + y: [ + 2, + 4, + 6, + 8 + ] + } : _a, _c = _b.x, x = _c === void 0 ? 10 : _c, _d = _b.y, _e = _d === void 0 ? [ + 1, + 2, + 3, + 4 + ] : _d, a = _e[0], b = _e[1], c = _e[2], d = _e[3]; +} +function g(_a) { + var _b = _a === void 0 ? [ + 1, + 2, + 3, + 4 + ] : _a, a = _b[0], b = _b[1], c = _b[2], d = _b[3]; +} +function h(_a) { + var a = _a[0], b = _a[1][0], c = _a[2][0][0], _b = _a[3], _c = _b.x, x = _c === void 0 ? 10 : _c, _d = _b.y, a = _d[0], b = _d[1], c = _d[2], _e = _b.z, a1 = _e.a1, b1 = _e.b1; +} +function h1(_a) { + var a = _a[0], b = _a[1][0], c = _a[2][0][0], _b = _a[3], _c = _b.x, x = _c === void 0 ? 10 : _c, _d = _b.y, y = _d === void 0 ? [ + 1, + 2, + 3 + ] : _d, _e = _b.z, a1 = _e.a1, b1 = _e.b1; +} + + +//// [declarationEmitDestructuringArrayPattern6.d.ts] +declare function f({x, y: [a, b, c, d]}?: { + x: number; + y: [number, number, number, number]; +}): void; +declare function g([a, b, c, d]?: [number, number, number, number]): void; +declare function h([a, [b], [[c]], {x, y: [a, b, c], z: {a1, b1}}]: [any, [any], [[any]], { + x?: number; + y: [any, any, any]; + z: { + a1: any; + b1: any; + }; +}]): void; +declare function h1([a, [b], [[c]], {x, y, z: {a1, b1}}]: [any, [any], [[any]], { + x?: number; + y?: number[]; + z: { + a1: any; + b1: any; + }; +}]): void; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern6.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern6.types new file mode 100644 index 0000000000..6112094cbe --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern6.types @@ -0,0 +1,49 @@ +=== tests/cases/compiler/declarationEmitDestructuringArrayPattern6.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 +>y : unknown +>a : number +>b : number +>c : number +>d : number +>[1, 2, 3, 4] : [number, number, number, number] +>{ x: 10, y: [2, 4, 6, 8] } : { x: number; y: [number, number, number, number]; } +>x : number +>y : [number, number, number, number] +>[2, 4, 6, 8] : [number, number, number, 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] + +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 +>y : unknown +>a : any +>b : any +>c : any +>z : unknown +>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 +>y : number[] +>[1, 2, 3] : number[] +>z : unknown +>a1 : any +>b1 : any + diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern7.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern7.js new file mode 100644 index 0000000000..00e65b816b --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern7.js @@ -0,0 +1,20 @@ +//// [declarationEmitDestructuringArrayPattern7.ts] +function bar([x, z, ...w]) { } +function foo([x, ...y] = [1, "string", true]) { } + +//// [declarationEmitDestructuringArrayPattern7.js] +function bar(_a) { + var x = _a[0], z = _a[1], w = _a.slice(2); +} +function foo(_a) { + var _b = _a === void 0 ? [ + 1, + "string", + true + ] : _a, x = _b[0], y = _b.slice(1); +} + + +//// [declarationEmitDestructuringArrayPattern7.d.ts] +declare function bar([x, z, w]: any[]): void; +declare function foo([x, y]?: (string | number | boolean)[]): void; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern7.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern7.types new file mode 100644 index 0000000000..8dc51bf5c7 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern7.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/declarationEmitDestructuringArrayPattern7.ts === +function bar([x, z, ...w]) { } +>bar : ([x, z, ...w]: any[]) => void +>x : any +>z : any +>w : any[] + +function foo([x, ...y] = [1, "string", true]) { } +>foo : ([x, ...y]?: (string | number | boolean)[]) => void +>x : string | number | boolean +>y : (string | number | boolean)[] +>[1, "string", true] : (string | number | boolean)[] + diff --git a/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js index d44c9d4236..a3cdee3122 100644 --- a/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js +++ b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js @@ -26,7 +26,7 @@ function foo2() { //// [declarationEmitDestructuringOptionalBindingParametersInOverloads.d.ts] declare function foo([x, y, z]?: [string, number, boolean]): any; -declare function foo2({ x, y, z }?: { +declare function foo2({x, y, z}?: { x: string; y: number; z: boolean; diff --git a/tests/baselines/reference/declarationEmitDestructuringParameterProperties.js b/tests/baselines/reference/declarationEmitDestructuringParameterProperties.js index 841508c331..a98620c852 100644 --- a/tests/baselines/reference/declarationEmitDestructuringParameterProperties.js +++ b/tests/baselines/reference/declarationEmitDestructuringParameterProperties.js @@ -57,5 +57,5 @@ declare type ObjType1 = { }; declare class C3 { x: number, y: string, z: boolean; - constructor({ x, y, z }: ObjType1); + constructor({x, y, z}: ObjType1); } diff --git a/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.js b/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.js index 9ffd25a7fa..5c7f4d2cec 100644 --- a/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.js +++ b/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.js @@ -14,8 +14,8 @@ function foo1(_a) { //// [declarationEmitDestructuringWithOptionalBindingParameters.d.ts] -declare function foo([x,y,z]?: [string, number, boolean]): void; -declare function foo1({ x, y, z }?: { +declare function foo([x, y, z]?: [string, number, boolean]): void; +declare function foo1({x, y, z}?: { x: string; y: number; z: boolean; diff --git a/tests/cases/compiler/declarationEmitDestructuringArrayPattern6.ts b/tests/cases/compiler/declarationEmitDestructuringArrayPattern6.ts new file mode 100644 index 0000000000..34441cd6c7 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringArrayPattern6.ts @@ -0,0 +1,5 @@ +// @declaration: true +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}}]){ } +function h1([a, [b], [[c]], {x = 10, y = [1, 2, 3], z: {a1, b1}}]){ } \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDestructuringArrayPattern7.ts b/tests/cases/compiler/declarationEmitDestructuringArrayPattern7.ts new file mode 100644 index 0000000000..321c6fd420 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringArrayPattern7.ts @@ -0,0 +1,3 @@ +// @declaration: true +function bar([x, z, ...w]) { } +function foo([x, ...y] = [1, "string", true]) { } \ No newline at end of file From 85624c03219d119f38a44debb0697c0839409200 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 23 Mar 2015 17:58:53 -0700 Subject: [PATCH 06/28] Change test files name --- ...n5.js => declarationEmitDestructuring1.js} | 6 +- ...es => declarationEmitDestructuring1.types} | 2 +- ...n6.js => declarationEmitDestructuring2.js} | 6 +- ...es => declarationEmitDestructuring2.types} | 2 +- .../declarationEmitDestructuring3.js | 22 ++++++ ...es => declarationEmitDestructuring3.types} | 3 +- .../declarationEmitDestructuring4.js | 67 +++++++++++++++++++ .../declarationEmitDestructuring4.types | 32 +++++++++ ...clarationEmitDestructuringArrayPattern7.js | 20 ------ ...n5.ts => declarationEmitDestructuring1.ts} | 0 ...n6.ts => declarationEmitDestructuring2.ts} | 0 .../compiler/declarationEmitDestructuring3.ts | 4 ++ .../compiler/declarationEmitDestructuring4.ts | 12 ++++ ...clarationEmitDestructuringArrayPattern7.ts | 3 - 14 files changed, 147 insertions(+), 32 deletions(-) rename tests/baselines/reference/{declarationEmitDestructuringArrayPattern5.js => declarationEmitDestructuring1.js} (83%) rename tests/baselines/reference/{declarationEmitDestructuringArrayPattern5.types => declarationEmitDestructuring1.types} (89%) rename tests/baselines/reference/{declarationEmitDestructuringArrayPattern6.js => declarationEmitDestructuring2.js} (88%) rename tests/baselines/reference/{declarationEmitDestructuringArrayPattern6.types => declarationEmitDestructuring2.types} (91%) create mode 100644 tests/baselines/reference/declarationEmitDestructuring3.js rename tests/baselines/reference/{declarationEmitDestructuringArrayPattern7.types => declarationEmitDestructuring3.types} (78%) create mode 100644 tests/baselines/reference/declarationEmitDestructuring4.js create mode 100644 tests/baselines/reference/declarationEmitDestructuring4.types delete mode 100644 tests/baselines/reference/declarationEmitDestructuringArrayPattern7.js rename tests/cases/compiler/{declarationEmitDestructuringArrayPattern5.ts => declarationEmitDestructuring1.ts} (100%) rename tests/cases/compiler/{declarationEmitDestructuringArrayPattern6.ts => declarationEmitDestructuring2.ts} (100%) create mode 100644 tests/cases/compiler/declarationEmitDestructuring3.ts create mode 100644 tests/cases/compiler/declarationEmitDestructuring4.ts delete mode 100644 tests/cases/compiler/declarationEmitDestructuringArrayPattern7.ts diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern5.js b/tests/baselines/reference/declarationEmitDestructuring1.js similarity index 83% rename from tests/baselines/reference/declarationEmitDestructuringArrayPattern5.js rename to tests/baselines/reference/declarationEmitDestructuring1.js index 9e8dee3285..9ac08032a0 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern5.js +++ b/tests/baselines/reference/declarationEmitDestructuring1.js @@ -1,11 +1,11 @@ -//// [declarationEmitDestructuringArrayPattern5.ts] +//// [declarationEmitDestructuring1.ts] function foo([a, b, c]: [string, string, string]): void { } function far([a, [b], [[c]]]: [number, boolean[], string[][]]): void { } function bar({a1, b1, c1}: { a1: number, b1: boolean, c1: string }): void { } function baz({a2, b2: {b1, c1}}: { a2: number, b2: { b1: boolean, c1: string } }): void { } -//// [declarationEmitDestructuringArrayPattern5.js] +//// [declarationEmitDestructuring1.js] function foo(_a) { var a = _a[0], b = _a[1], c = _a[2]; } @@ -20,7 +20,7 @@ function baz(_a) { } -//// [declarationEmitDestructuringArrayPattern5.d.ts] +//// [declarationEmitDestructuring1.d.ts] declare function foo([a, b, c]: [string, string, string]): void; declare function far([a, [b], [[c]]]: [number, boolean[], string[][]]): void; declare function bar({a1, b1, c1}: { diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern5.types b/tests/baselines/reference/declarationEmitDestructuring1.types similarity index 89% rename from tests/baselines/reference/declarationEmitDestructuringArrayPattern5.types rename to tests/baselines/reference/declarationEmitDestructuring1.types index fdb2bba88e..6b22f25b54 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern5.types +++ b/tests/baselines/reference/declarationEmitDestructuring1.types @@ -1,4 +1,4 @@ -=== tests/cases/compiler/declarationEmitDestructuringArrayPattern5.ts === +=== tests/cases/compiler/declarationEmitDestructuring1.ts === function foo([a, b, c]: [string, string, string]): void { } >foo : ([a, b, c]: [string, string, string]) => void >a : string diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern6.js b/tests/baselines/reference/declarationEmitDestructuring2.js similarity index 88% rename from tests/baselines/reference/declarationEmitDestructuringArrayPattern6.js rename to tests/baselines/reference/declarationEmitDestructuring2.js index 803ea9fe01..f6d3d17abe 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern6.js +++ b/tests/baselines/reference/declarationEmitDestructuring2.js @@ -1,10 +1,10 @@ -//// [declarationEmitDestructuringArrayPattern6.ts] +//// [declarationEmitDestructuring2.ts] 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}}]){ } function h1([a, [b], [[c]], {x = 10, y = [1, 2, 3], z: {a1, b1}}]){ } -//// [declarationEmitDestructuringArrayPattern6.js] +//// [declarationEmitDestructuring2.js] function f(_a) { var _b = _a === void 0 ? { x: 10, @@ -41,7 +41,7 @@ function h1(_a) { } -//// [declarationEmitDestructuringArrayPattern6.d.ts] +//// [declarationEmitDestructuring2.d.ts] declare function f({x, y: [a, b, c, d]}?: { x: number; y: [number, number, number, number]; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern6.types b/tests/baselines/reference/declarationEmitDestructuring2.types similarity index 91% rename from tests/baselines/reference/declarationEmitDestructuringArrayPattern6.types rename to tests/baselines/reference/declarationEmitDestructuring2.types index 6112094cbe..3368d4e72f 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern6.types +++ b/tests/baselines/reference/declarationEmitDestructuring2.types @@ -1,4 +1,4 @@ -=== tests/cases/compiler/declarationEmitDestructuringArrayPattern6.ts === +=== 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 diff --git a/tests/baselines/reference/declarationEmitDestructuring3.js b/tests/baselines/reference/declarationEmitDestructuring3.js new file mode 100644 index 0000000000..66f6b071a8 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuring3.js @@ -0,0 +1,22 @@ +//// [declarationEmitDestructuring3.ts] +function bar([x, z, ...w]) { } +function foo([x, ...y] = [1, "string", true]) { } + + + +//// [declarationEmitDestructuring3.js] +function bar(_a) { + var x = _a[0], z = _a[1], w = _a.slice(2); +} +function foo(_a) { + var _b = _a === void 0 ? [ + 1, + "string", + true + ] : _a, x = _b[0], y = _b.slice(1); +} + + +//// [declarationEmitDestructuring3.d.ts] +declare function bar([x, z, ...w]: any[]): void; +declare function foo([x, ...y]?: (string | number | boolean)[]): void; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern7.types b/tests/baselines/reference/declarationEmitDestructuring3.types similarity index 78% rename from tests/baselines/reference/declarationEmitDestructuringArrayPattern7.types rename to tests/baselines/reference/declarationEmitDestructuring3.types index 8dc51bf5c7..57764f53ee 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern7.types +++ b/tests/baselines/reference/declarationEmitDestructuring3.types @@ -1,4 +1,4 @@ -=== tests/cases/compiler/declarationEmitDestructuringArrayPattern7.ts === +=== tests/cases/compiler/declarationEmitDestructuring3.ts === function bar([x, z, ...w]) { } >bar : ([x, z, ...w]: any[]) => void >x : any @@ -11,3 +11,4 @@ function foo([x, ...y] = [1, "string", true]) { } >y : (string | number | boolean)[] >[1, "string", true] : (string | number | boolean)[] + diff --git a/tests/baselines/reference/declarationEmitDestructuring4.js b/tests/baselines/reference/declarationEmitDestructuring4.js new file mode 100644 index 0000000000..5b43fbfc85 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuring4.js @@ -0,0 +1,67 @@ +//// [declarationEmitDestructuring4.ts] +function baz([]) { } +function baz1([] = [1,2,3]) { } +function baz2([[]] = [[1,2,3]]) { } +function baz3({}) { } +function baz4({} = { x: 10 }) { } +function baz5({} = { x: 10, y: { a: 2 }, z: [1,2] }) { } + + + +//// [declarationEmitDestructuring4.js] +function baz(_a) { + var ; +} +function baz1(_a) { + var _b = _a === void 0 ? [ + 1, + 2, + 3 + ] : _a; +} +function baz2(_a) { + var _b = (_a === void 0 ? [ + [ + 1, + 2, + 3 + ] + ] : _a)[0]; +} +function baz3(_a) { + var ; +} +function baz4(_a) { + var _b = _a === void 0 ? { + x: 10 + } : _a; +} +function baz5(_a) { + var _b = _a === void 0 ? { + x: 10, + y: { + a: 2 + }, + z: [ + 1, + 2 + ] + } : _a; +} + + +//// [declarationEmitDestructuring4.d.ts] +declare function baz([]: any[]): void; +declare function baz1([]?: number[]): void; +declare function baz2([[]]?: [number[]]): void; +declare function baz3({}: {}): void; +declare function baz4({}?: { + x: number; +}): void; +declare function baz5({}?: { + x: number; + y: { + a: number; + }; + z: number[]; +}): void; diff --git a/tests/baselines/reference/declarationEmitDestructuring4.types b/tests/baselines/reference/declarationEmitDestructuring4.types new file mode 100644 index 0000000000..6602fbdcb7 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuring4.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/declarationEmitDestructuring4.ts === +function baz([]) { } +>baz : ([]: any[]) => void + +function baz1([] = [1,2,3]) { } +>baz1 : ([]?: number[]) => void +>[1,2,3] : number[] + +function baz2([[]] = [[1,2,3]]) { } +>baz2 : ([[]]?: [number[]]) => void +>[[1,2,3]] : [number[]] +>[1,2,3] : number[] + +function baz3({}) { } +>baz3 : ({}: {}) => void + +function baz4({} = { x: 10 }) { } +>baz4 : ({}?: { x: number; }) => void +>{ x: 10 } : { x: number; } +>x : number + +function baz5({} = { x: 10, y: { a: 2 }, z: [1,2] }) { } +>baz5 : ({}?: { x: number; y: { a: number; }; z: number[]; }) => void +>{ x: 10, y: { a: 2 }, z: [1,2] } : { x: number; y: { a: number; }; z: number[]; } +>x : number +>y : { a: number; } +>{ a: 2 } : { a: number; } +>a : number +>z : number[] +>[1,2] : number[] + + diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern7.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern7.js deleted file mode 100644 index 00e65b816b..0000000000 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern7.js +++ /dev/null @@ -1,20 +0,0 @@ -//// [declarationEmitDestructuringArrayPattern7.ts] -function bar([x, z, ...w]) { } -function foo([x, ...y] = [1, "string", true]) { } - -//// [declarationEmitDestructuringArrayPattern7.js] -function bar(_a) { - var x = _a[0], z = _a[1], w = _a.slice(2); -} -function foo(_a) { - var _b = _a === void 0 ? [ - 1, - "string", - true - ] : _a, x = _b[0], y = _b.slice(1); -} - - -//// [declarationEmitDestructuringArrayPattern7.d.ts] -declare function bar([x, z, w]: any[]): void; -declare function foo([x, y]?: (string | number | boolean)[]): void; diff --git a/tests/cases/compiler/declarationEmitDestructuringArrayPattern5.ts b/tests/cases/compiler/declarationEmitDestructuring1.ts similarity index 100% rename from tests/cases/compiler/declarationEmitDestructuringArrayPattern5.ts rename to tests/cases/compiler/declarationEmitDestructuring1.ts diff --git a/tests/cases/compiler/declarationEmitDestructuringArrayPattern6.ts b/tests/cases/compiler/declarationEmitDestructuring2.ts similarity index 100% rename from tests/cases/compiler/declarationEmitDestructuringArrayPattern6.ts rename to tests/cases/compiler/declarationEmitDestructuring2.ts diff --git a/tests/cases/compiler/declarationEmitDestructuring3.ts b/tests/cases/compiler/declarationEmitDestructuring3.ts new file mode 100644 index 0000000000..78aeddb0e1 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuring3.ts @@ -0,0 +1,4 @@ +// @declaration: true +function bar([x, z, ...w]) { } +function foo([x, ...y] = [1, "string", true]) { } + diff --git a/tests/cases/compiler/declarationEmitDestructuring4.ts b/tests/cases/compiler/declarationEmitDestructuring4.ts new file mode 100644 index 0000000000..b961be2b39 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuring4.ts @@ -0,0 +1,12 @@ +// @declaration: true +// For an array binding pattern with empty elements, +// we will not make any modification and will emit +// the similar binding pattern users' have written +function baz([]) { } +function baz1([] = [1,2,3]) { } +function baz2([[]] = [[1,2,3]]) { } + +function baz3({}) { } +function baz4({} = { x: 10 }) { } +function baz5({} = { x: 10, y: { a: 2 }, z: [1,2] }) { } + diff --git a/tests/cases/compiler/declarationEmitDestructuringArrayPattern7.ts b/tests/cases/compiler/declarationEmitDestructuringArrayPattern7.ts deleted file mode 100644 index 321c6fd420..0000000000 --- a/tests/cases/compiler/declarationEmitDestructuringArrayPattern7.ts +++ /dev/null @@ -1,3 +0,0 @@ -// @declaration: true -function bar([x, z, ...w]) { } -function foo([x, ...y] = [1, "string", true]) { } \ No newline at end of file From 6695981583fa5f4f2ad184d64fae630808266c50 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 23 Mar 2015 17:59:02 -0700 Subject: [PATCH 07/28] Address code review --- src/compiler/declarationEmitter.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 93e0fa3129..8431756c91 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -1322,7 +1322,7 @@ module ts { } : undefined; } - function getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult: SymbolAccessiblityResult) { + function getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult: SymbolAccessiblityResult): DiagnosticMessage { switch (node.parent.kind) { case SyntaxKind.Constructor: return symbolAccesibilityResult.errorModuleName ? @@ -1422,15 +1422,19 @@ module ts { // Example: // original: function foo([a, [[b]], c] = [1,[["string"]], 3]) {} // emit : declare function foo([a, [[b]], c]: [number, [[string]], number]): void; - // original with rest: function foo([a ...c]) {} - // emit : declare function foo([a, c]): void; + // original with rest: function foo([a, ...c]) {} + // emit : declare function foo([a, ...c]): void; emitBindingPattern(bindingElement.name); } else { + Debug.assert(bindingElement.name.kind === SyntaxKind.Identifier); // If the node is just an identifier, we will simply emit the text associated with the node's name // Example: // original: function foo({y = 10, x}) {} // emit : declare function foo({y, x}: {number, any}): void; + if (bindingElement.dotDotDotToken) { + write("..."); + } writeTextOfNode(currentSourceFile, bindingElement.name); } } From 1c2eae6b72c8cc9646fda407bbaa6344bcf4e997 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 24 Mar 2015 10:11:29 -0700 Subject: [PATCH 08/28] Update test cases --- .../declarationEmitDestructuring4.js | 27 +++++-------------- .../declarationEmitDestructuring4.types | 13 +++------ .../compiler/declarationEmitDestructuring4.ts | 1 - 3 files changed, 10 insertions(+), 31 deletions(-) diff --git a/tests/baselines/reference/declarationEmitDestructuring4.js b/tests/baselines/reference/declarationEmitDestructuring4.js index 5b43fbfc85..81d1707b8e 100644 --- a/tests/baselines/reference/declarationEmitDestructuring4.js +++ b/tests/baselines/reference/declarationEmitDestructuring4.js @@ -1,14 +1,20 @@ //// [declarationEmitDestructuring4.ts] +// For an array binding pattern with empty elements, +// we will not make any modification and will emit +// the similar binding pattern users' have written function baz([]) { } function baz1([] = [1,2,3]) { } function baz2([[]] = [[1,2,3]]) { } + function baz3({}) { } function baz4({} = { x: 10 }) { } -function baz5({} = { x: 10, y: { a: 2 }, z: [1,2] }) { } //// [declarationEmitDestructuring4.js] +// For an array binding pattern with empty elements, +// we will not make any modification and will emit +// the similar binding pattern users' have written function baz(_a) { var ; } @@ -36,18 +42,6 @@ function baz4(_a) { x: 10 } : _a; } -function baz5(_a) { - var _b = _a === void 0 ? { - x: 10, - y: { - a: 2 - }, - z: [ - 1, - 2 - ] - } : _a; -} //// [declarationEmitDestructuring4.d.ts] @@ -58,10 +52,3 @@ declare function baz3({}: {}): void; declare function baz4({}?: { x: number; }): void; -declare function baz5({}?: { - x: number; - y: { - a: number; - }; - z: number[]; -}): void; diff --git a/tests/baselines/reference/declarationEmitDestructuring4.types b/tests/baselines/reference/declarationEmitDestructuring4.types index 6602fbdcb7..6a90eda170 100644 --- a/tests/baselines/reference/declarationEmitDestructuring4.types +++ b/tests/baselines/reference/declarationEmitDestructuring4.types @@ -1,4 +1,7 @@ === tests/cases/compiler/declarationEmitDestructuring4.ts === +// For an array binding pattern with empty elements, +// we will not make any modification and will emit +// the similar binding pattern users' have written function baz([]) { } >baz : ([]: any[]) => void @@ -19,14 +22,4 @@ function baz4({} = { x: 10 }) { } >{ x: 10 } : { x: number; } >x : number -function baz5({} = { x: 10, y: { a: 2 }, z: [1,2] }) { } ->baz5 : ({}?: { x: number; y: { a: number; }; z: number[]; }) => void ->{ x: 10, y: { a: 2 }, z: [1,2] } : { x: number; y: { a: number; }; z: number[]; } ->x : number ->y : { a: number; } ->{ a: 2 } : { a: number; } ->a : number ->z : number[] ->[1,2] : number[] - diff --git a/tests/cases/compiler/declarationEmitDestructuring4.ts b/tests/cases/compiler/declarationEmitDestructuring4.ts index b961be2b39..bd1a57af12 100644 --- a/tests/cases/compiler/declarationEmitDestructuring4.ts +++ b/tests/cases/compiler/declarationEmitDestructuring4.ts @@ -8,5 +8,4 @@ function baz2([[]] = [[1,2,3]]) { } function baz3({}) { } function baz4({} = { x: 10 }) { } -function baz5({} = { x: 10, y: { a: 2 }, z: [1,2] }) { } From a51f0bf8bbca289f692e046cecd18670fd5cf6dd Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 25 Mar 2015 23:18:58 -0700 Subject: [PATCH 09/28] added relaxed emit rules for separate compilation --- src/compiler/checker.ts | 19 ++++++++-- src/compiler/types.ts | 1 + src/services/services.ts | 80 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6fdaac79ce..9765ceee4a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -713,8 +713,14 @@ module ts { function markExportAsReferenced(node: ImportEqualsDeclaration | ExportAssignment | ExportSpecifier) { let symbol = getSymbolOfNode(node); let target = resolveAlias(symbol); - if (target && target !== unknownSymbol && target.flags & SymbolFlags.Value && !isConstEnumOrConstEnumOnlyModule(target)) { - markAliasSymbolAsReferenced(symbol); + if (target) { + let markAlias = + (target === unknownSymbol && compilerOptions.separateCompilation) || + (target !== unknownSymbol && target.flags & SymbolFlags.Value && !isConstEnumOrConstEnumOnlyModule(target)); + + if (markAlias) { + markAliasSymbolAsReferenced(symbol); + } } } @@ -9745,7 +9751,9 @@ module ts { checkKindsOfPropertyMemberOverrides(type, baseType); } + } + if (type.baseTypes.length || (baseTypeNode && compilerOptions.separateCompilation)) { // Check that base type can be evaluated as expression checkExpressionOrQualifiedName(baseTypeNode.typeName); } @@ -11264,11 +11272,16 @@ module ts { // parent is not source file or it is not reference to internal module return false; } - return isAliasResolvedToValue(getSymbolOfNode(node)); + + var isValue = isAliasResolvedToValue(getSymbolOfNode(node)); + return isValue && node.moduleReference && !nodeIsMissing(node.moduleReference); } function isAliasResolvedToValue(symbol: Symbol): boolean { let target = resolveAlias(symbol); + if (target === unknownSymbol && compilerOptions.separateCompilation) { + return true; + } // const enums and modules that contain only const enums are not considered values from the emit perespective return target !== unknownSymbol && target.flags & SymbolFlags.Value && !isConstEnumOrConstEnumOnlyModule(target); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index e5697f9f37..9482339d09 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1587,6 +1587,7 @@ module ts { target?: ScriptTarget; version?: boolean; watch?: boolean; + separateCompilation?: boolean; /* @internal */ stripInternal?: boolean; /* @internal */ preserveNewLines?: boolean; /* @internal */ cacheDownlevelForOfLength?: boolean; diff --git a/src/services/services.ts b/src/services/services.ts index 41ffc04e5a..5f8ab267e7 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1635,6 +1635,86 @@ module ts { sourceFile.scriptSnapshot = scriptSnapshot; } + export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, syntaxErrors?: Diagnostic[]): string { + let options = compilerOptions ? ts.clone(compilerOptions) : getDefaultCompilerOptions(); + + // Single file transformation is only guranteed to be correct if inside an external module. + // External modules have thier own scope and can not contribute to internal modules outside their + // scope. + if (options.target !== ScriptTarget.ES6 && (!options.module || options.module === ModuleKind.None)) { + // add errors + } + + // In sigle file transformation the compiler does not have access to declaration sites. + // Const enum property access will not be detected if they are not in the same file as the enum. + // thus they are goign to be emitted as normal propety access. To ensure correct behaviour at runtime, + // we need to generare the actual enum object so that the proprty accesses do not fail. + options.preserveConstEnums = true; + + // No reason to get declarations, we are only returning javascript + options.declaration = false; + + // Filename can be non-ts file. We are not locating any modules as well, so allow + // non-ts extensions + options.allowNonTsExtensions = true; + + // enable relaxed emit rules + options.separateCompilation = true; + + // We are not resolving references or modules, or even including the library. Disabling + // emit on error will block generating the output and has no meaningful use here. + options.noEmitOnError = false; + + // No resolution requests will be honered anyways. So do not do it + options.noResolve = true; + + // TODO (vladima): add inlineSourceMap once it is checked in + //if (options.sourceMap) { + // // We need to return a single string, so inline the sourceMap in the output + // options.inlineSourceMap = true;; + //} + + // Parse + var inputFileName = fileName || "module.ts"; + var sourceFile = ts.createSourceFile(inputFileName, input, options.target); + + // Store syntactic diagnostics + if (syntaxErrors && sourceFile.parseDiagnostics) { + syntaxErrors.push(...sourceFile.parseDiagnostics); + } + + // Output + let outputText: string; + + // Create a compilerHost object to allow the compiler to read and write files + var compilerHost: CompilerHost = { + getSourceFile: (fileName, target) => fileName === inputFileName ? sourceFile : undefined, + writeFile: (name, text, writeByteOrderMark) => { + if (ts.fileExtensionIs(name, ".js")) { + Debug.assert(outputText === undefined, "Unexpected multiple outputs for the file: " + name); + outputText = text; + } + }, + getDefaultLibFileName: () => "lib.d.ts", + useCaseSensitiveFileNames: () => false, + getCanonicalFileName: fileName => fileName, + getCurrentDirectory: () => "", + getNewLine: () => "\r\n" + }; + + // Note: The emitter needs a the checker to walk the file, so we will create a program for this + // though single file transformation does not really need this. First we need to drop the emitter + // dependcy on the checker and then implement a new resolver that does not do the full check. + var program = ts.createProgram([inputFileName], options, compilerHost); + + // Emit + program.emit(); + + Debug.assert(outputText !== undefined, "Output generation failed"); + + return outputText; + } + export function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile { let sourceFile = createSourceFile(fileName, scriptSnapshot.getText(0, scriptSnapshot.getLength()), scriptTarget, setNodeParents); setSourceFileFields(sourceFile, scriptSnapshot, version); From 83e8910dc128d28573adaaf5b073a323a606a150 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 26 Mar 2015 10:44:44 -0700 Subject: [PATCH 10/28] update version in program --- src/compiler/program.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index cb12e6da4d..63847dec51 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -8,7 +8,7 @@ module ts { /* @internal */ export let ioWriteTime = 0; /** The version of the TypeScript compiler release */ - export let version = "1.5.0.0"; + export let version = "1.5.0"; export function findConfigFile(searchPath: string): string { var fileName = "tsconfig.json"; From 8f616ce65c5daa72565bdb60044671f1314f6606 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 30 Mar 2015 12:43:10 -0700 Subject: [PATCH 11/28] fix typos in comments --- src/services/services.ts | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 5f8ab267e7..2d5ce2d5f2 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1638,41 +1638,37 @@ module ts { export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, syntaxErrors?: Diagnostic[]): string { let options = compilerOptions ? ts.clone(compilerOptions) : getDefaultCompilerOptions(); - // Single file transformation is only guranteed to be correct if inside an external module. - // External modules have thier own scope and can not contribute to internal modules outside their + // Single file transformation is only guaranteed to be correct inside an external module. + // External modules have their own scope and cannot contribute to internal modules outside their // scope. if (options.target !== ScriptTarget.ES6 && (!options.module || options.module === ModuleKind.None)) { - // add errors + // TODO: add errors } - // In sigle file transformation the compiler does not have access to declaration sites. - // Const enum property access will not be detected if they are not in the same file as the enum. - // thus they are goign to be emitted as normal propety access. To ensure correct behaviour at runtime, - // we need to generare the actual enum object so that the proprty accesses do not fail. + // In single file transformation the compiler does not have access to declaration sites. + // Const enum property accesses will not be detected if they are not in the same file as the enum. + // thus they are going to be emitted as normal propety access. To ensure correct behaviour at runtime, + // we need to generate the actual enum object so that the property accesses do not fail. options.preserveConstEnums = true; // No reason to get declarations, we are only returning javascript options.declaration = false; - // Filename can be non-ts file. We are not locating any modules as well, so allow - // non-ts extensions + // Filename can be non-ts file. options.allowNonTsExtensions = true; // enable relaxed emit rules options.separateCompilation = true; - // We are not resolving references or modules, or even including the library. Disabling + // We are not resolving references or modules, or even including the default library. Disabling // emit on error will block generating the output and has no meaningful use here. options.noEmitOnError = false; - // No resolution requests will be honered anyways. So do not do it + // No resolution requests will be honored anyways. So do not do it options.noResolve = true; - // TODO (vladima): add inlineSourceMap once it is checked in - //if (options.sourceMap) { - // // We need to return a single string, so inline the sourceMap in the output - // options.inlineSourceMap = true;; - //} + // TODO (vladima): this should be enabled after adding support to inlinable source maps + options.sourceMap = false; // Parse var inputFileName = fileName || "module.ts"; @@ -1690,10 +1686,8 @@ module ts { var compilerHost: CompilerHost = { getSourceFile: (fileName, target) => fileName === inputFileName ? sourceFile : undefined, writeFile: (name, text, writeByteOrderMark) => { - if (ts.fileExtensionIs(name, ".js")) { - Debug.assert(outputText === undefined, "Unexpected multiple outputs for the file: " + name); - outputText = text; - } + Debug.assert(outputText === undefined, "Unexpected multiple outputs for the file: " + name); + outputText = text; }, getDefaultLibFileName: () => "lib.d.ts", useCaseSensitiveFileNames: () => false, @@ -1702,9 +1696,6 @@ module ts { getNewLine: () => "\r\n" }; - // Note: The emitter needs a the checker to walk the file, so we will create a program for this - // though single file transformation does not really need this. First we need to drop the emitter - // dependcy on the checker and then implement a new resolver that does not do the full check. var program = ts.createProgram([inputFileName], options, compilerHost); // Emit From 1f055b95aa704e3881d9ed8a2e8dd4f915877f71 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 30 Mar 2015 13:25:46 -0700 Subject: [PATCH 12/28] Emit ommittedExpression in binding pattern --- src/compiler/declarationEmitter.ts | 73 +++++++++++-------- .../declarationEmitDestructuring5.js | 37 ++++++++++ .../declarationEmitDestructuring5.types | 22 ++++++ .../compiler/declarationEmitDestructuring5.ts | 6 ++ 4 files changed, 109 insertions(+), 29 deletions(-) create mode 100644 tests/baselines/reference/declarationEmitDestructuring5.js create mode 100644 tests/baselines/reference/declarationEmitDestructuring5.types create mode 100644 tests/cases/compiler/declarationEmitDestructuring5.ts diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 8431756c91..ee8b7f2ac3 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -1387,7 +1387,11 @@ module ts { } else if (bindingPattern.kind === SyntaxKind.ArrayBindingPattern) { write("["); - emitCommaList(bindingPattern.elements, emitBindingElement); + let elements = bindingPattern.elements; + emitCommaList(elements, emitBindingElement); + if (elements && elements.hasTrailingComma) { + write(", "); + } write("]"); } } @@ -1402,40 +1406,51 @@ module ts { } : undefined; } - if (bindingElement.propertyName) { - // bindingElement has propertyName property in the following case: - // { y: [a,b,c] ...} -> bindingPattern will have a property called propertyName for "y" - // We have to explicitly emit the propertyName before descending into its binding elements. + if (bindingElement.kind === SyntaxKind.OmittedExpression) { + // If bindingElement is an omittedExpression (i.e. containing elision), + // we will emit blank space (although this may differ from users' original code, + // it allows emitSeparatedList to write separator appropriately) // Example: - // original: function foo({y: [a,b,c]}) {} - // emit : declare function foo({y: [a, b, c]}: { y: [any, any, any] }) void; - writeTextOfNode(currentSourceFile, bindingElement.propertyName); - write(": "); - - // If bindingElement has propertyName property, then its name must be another bindingPattern of SyntaxKind.ObjectBindingPattern - emitBindingPattern(bindingElement.name); + // original: function foo([, x, ,]) {} + // emit : function foo([ , x, , ]) {} + write(" "); } - else if (bindingElement.name) { - if (isBindingPattern(bindingElement.name)) { - // If it is a nested binding pattern, we will recursively descend into each element and emit each one separately. - // In the case of rest element, we will omit rest element. + else if (bindingElement.kind === SyntaxKind.BindingElement) { + if (bindingElement.propertyName) { + // bindingElement has propertyName property in the following case: + // { y: [a,b,c] ...} -> bindingPattern will have a property called propertyName for "y" + // We have to explicitly emit the propertyName before descending into its binding elements. // Example: - // original: function foo([a, [[b]], c] = [1,[["string"]], 3]) {} - // emit : declare function foo([a, [[b]], c]: [number, [[string]], number]): void; - // original with rest: function foo([a, ...c]) {} - // emit : declare function foo([a, ...c]): void; + // original: function foo({y: [a,b,c]}) {} + // emit : declare function foo({y: [a, b, c]}: { y: [any, any, any] }) void; + writeTextOfNode(currentSourceFile, bindingElement.propertyName); + write(": "); + + // If bindingElement has propertyName property, then its name must be another bindingPattern of SyntaxKind.ObjectBindingPattern emitBindingPattern(bindingElement.name); } - else { - Debug.assert(bindingElement.name.kind === SyntaxKind.Identifier); - // If the node is just an identifier, we will simply emit the text associated with the node's name - // Example: - // original: function foo({y = 10, x}) {} - // emit : declare function foo({y, x}: {number, any}): void; - if (bindingElement.dotDotDotToken) { - write("..."); + else if (bindingElement.name) { + if (isBindingPattern(bindingElement.name)) { + // If it is a nested binding pattern, we will recursively descend into each element and emit each one separately. + // In the case of rest element, we will omit rest element. + // Example: + // original: function foo([a, [[b]], c] = [1,[["string"]], 3]) {} + // emit : declare function foo([a, [[b]], c]: [number, [[string]], number]): void; + // original with rest: function foo([a, ...c]) {} + // emit : declare function foo([a, ...c]): void; + emitBindingPattern(bindingElement.name); + } + else { + Debug.assert(bindingElement.name.kind === SyntaxKind.Identifier); + // If the node is just an identifier, we will simply emit the text associated with the node's name + // Example: + // original: function foo({y = 10, x}) {} + // emit : declare function foo({y, x}: {number, any}): void; + if (bindingElement.dotDotDotToken) { + write("..."); + } + writeTextOfNode(currentSourceFile, bindingElement.name); } - writeTextOfNode(currentSourceFile, bindingElement.name); } } } diff --git a/tests/baselines/reference/declarationEmitDestructuring5.js b/tests/baselines/reference/declarationEmitDestructuring5.js new file mode 100644 index 0000000000..f0602206a1 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuring5.js @@ -0,0 +1,37 @@ +//// [declarationEmitDestructuring5.ts] +function baz([, z, , ]) { } +function foo([, b, ]: [any, any]): void { } +function bar([z, , , ]) { } +function bar1([z, , , ] = [1, 3, 4, 6, 7]) { } +function bar2([,,z, , , ]) { } + +//// [declarationEmitDestructuring5.js] +function baz(_a) { + var z = _a[1]; +} +function foo(_a) { + var b = _a[1]; +} +function bar(_a) { + var z = _a[0]; +} +function bar1(_a) { + var _b = _a === void 0 ? [ + 1, + 3, + 4, + 6, + 7 + ] : _a, z = _b[0]; +} +function bar2(_a) { + var z = _a[2]; +} + + +//// [declarationEmitDestructuring5.d.ts] +declare function baz([ , z, , ]: [any, any, any]): void; +declare function foo([ , b, ]: [any, any]): void; +declare function bar([z, , , ]: [any, any, any]): void; +declare function bar1([z, , , ]?: [number, number, number, number, number]): void; +declare function bar2([ , , z, , , ]: [any, any, any, any, any]): void; diff --git a/tests/baselines/reference/declarationEmitDestructuring5.types b/tests/baselines/reference/declarationEmitDestructuring5.types new file mode 100644 index 0000000000..375440bea0 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuring5.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/declarationEmitDestructuring5.ts === +function baz([, z, , ]) { } +>baz : ([, z, , ]: [any, any, any]) => void +>z : any + +function foo([, b, ]: [any, any]): void { } +>foo : ([, b, ]: [any, any]) => void +>b : any + +function bar([z, , , ]) { } +>bar : ([z, , , ]: [any, any, any]) => void +>z : any + +function bar1([z, , , ] = [1, 3, 4, 6, 7]) { } +>bar1 : ([z, , , ]?: [number, number, number, number, number]) => void +>z : number +>[1, 3, 4, 6, 7] : [number, number, number, number, number] + +function bar2([,,z, , , ]) { } +>bar2 : ([,,z, , , ]: [any, any, any, any, any]) => void +>z : any + diff --git a/tests/cases/compiler/declarationEmitDestructuring5.ts b/tests/cases/compiler/declarationEmitDestructuring5.ts new file mode 100644 index 0000000000..a02a21b5a5 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuring5.ts @@ -0,0 +1,6 @@ +// @declaration: true +function baz([, z, , ]) { } +function foo([, b, ]: [any, any]): void { } +function bar([z, , , ]) { } +function bar1([z, , , ] = [1, 3, 4, 6, 7]) { } +function bar2([,,z, , , ]) { } \ No newline at end of file From 8320bca4d002e9081282fb689676470c3b34be82 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 30 Mar 2015 14:41:07 -0700 Subject: [PATCH 13/28] Fix emit trailing comma for array binding pattern for varaible declaration --- src/compiler/declarationEmitter.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index ee8b7f2ac3..3ba1cb0a1a 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -993,7 +993,18 @@ module ts { } function emitBindingPattern(bindingPattern: BindingPattern) { - emitCommaList(bindingPattern.elements, emitBindingElement); + // Only select non-omitted expression from the bindingPattern's elements. + // We have to do this to avoid emitting trailing commas. + // For example: + // original: var [, c,,] = [ 2,3,4] + // emitted: declare var c: number; // instead of declare var c:number, ; + let elements: Node[] = []; + for (let element of bindingPattern.elements) { + if (element.kind !== SyntaxKind.OmittedExpression){ + elements.push(element); + } + } + emitCommaList(elements, emitBindingElement); } function emitBindingElement(bindingElement: BindingElement) { From 129b8ad8b041f34e5e06c09f0b94793d987133a0 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 30 Mar 2015 16:28:10 -0700 Subject: [PATCH 14/28] Update baselines from merging with master --- .../declarationEmitDestructuring2.js | 28 ++----------------- .../declarationEmitDestructuring3.js | 6 +--- .../declarationEmitDestructuring4.js | 18 ++---------- .../declarationEmitDestructuring5.js | 8 +----- 4 files changed, 8 insertions(+), 52 deletions(-) diff --git a/tests/baselines/reference/declarationEmitDestructuring2.js b/tests/baselines/reference/declarationEmitDestructuring2.js index f6d3d17abe..eeabbf1ff3 100644 --- a/tests/baselines/reference/declarationEmitDestructuring2.js +++ b/tests/baselines/reference/declarationEmitDestructuring2.js @@ -6,38 +6,16 @@ function h1([a, [b], [[c]], {x = 10, y = [1, 2, 3], z: {a1, b1}}]){ } //// [declarationEmitDestructuring2.js] function f(_a) { - var _b = _a === void 0 ? { - x: 10, - y: [ - 2, - 4, - 6, - 8 - ] - } : _a, _c = _b.x, x = _c === void 0 ? 10 : _c, _d = _b.y, _e = _d === void 0 ? [ - 1, - 2, - 3, - 4 - ] : _d, a = _e[0], b = _e[1], c = _e[2], d = _e[3]; + var _b = _a === void 0 ? { x: 10, y: [2, 4, 6, 8] } : _a, _c = _b.x, x = _c === void 0 ? 10 : _c, _d = _b.y, _e = _d === void 0 ? [1, 2, 3, 4] : _d, a = _e[0], b = _e[1], c = _e[2], d = _e[3]; } function g(_a) { - var _b = _a === void 0 ? [ - 1, - 2, - 3, - 4 - ] : _a, a = _b[0], b = _b[1], c = _b[2], d = _b[3]; + var _b = _a === void 0 ? [1, 2, 3, 4] : _a, a = _b[0], b = _b[1], c = _b[2], d = _b[3]; } function h(_a) { var a = _a[0], b = _a[1][0], c = _a[2][0][0], _b = _a[3], _c = _b.x, x = _c === void 0 ? 10 : _c, _d = _b.y, a = _d[0], b = _d[1], c = _d[2], _e = _b.z, a1 = _e.a1, b1 = _e.b1; } function h1(_a) { - var a = _a[0], b = _a[1][0], c = _a[2][0][0], _b = _a[3], _c = _b.x, x = _c === void 0 ? 10 : _c, _d = _b.y, y = _d === void 0 ? [ - 1, - 2, - 3 - ] : _d, _e = _b.z, a1 = _e.a1, b1 = _e.b1; + var a = _a[0], b = _a[1][0], c = _a[2][0][0], _b = _a[3], _c = _b.x, x = _c === void 0 ? 10 : _c, _d = _b.y, y = _d === void 0 ? [1, 2, 3] : _d, _e = _b.z, a1 = _e.a1, b1 = _e.b1; } diff --git a/tests/baselines/reference/declarationEmitDestructuring3.js b/tests/baselines/reference/declarationEmitDestructuring3.js index 66f6b071a8..b21c63203c 100644 --- a/tests/baselines/reference/declarationEmitDestructuring3.js +++ b/tests/baselines/reference/declarationEmitDestructuring3.js @@ -9,11 +9,7 @@ function bar(_a) { var x = _a[0], z = _a[1], w = _a.slice(2); } function foo(_a) { - var _b = _a === void 0 ? [ - 1, - "string", - true - ] : _a, x = _b[0], y = _b.slice(1); + var _b = _a === void 0 ? [1, "string", true] : _a, x = _b[0], y = _b.slice(1); } diff --git a/tests/baselines/reference/declarationEmitDestructuring4.js b/tests/baselines/reference/declarationEmitDestructuring4.js index 81d1707b8e..f5d9df0917 100644 --- a/tests/baselines/reference/declarationEmitDestructuring4.js +++ b/tests/baselines/reference/declarationEmitDestructuring4.js @@ -19,28 +19,16 @@ function baz(_a) { var ; } function baz1(_a) { - var _b = _a === void 0 ? [ - 1, - 2, - 3 - ] : _a; + var _b = _a === void 0 ? [1, 2, 3] : _a; } function baz2(_a) { - var _b = (_a === void 0 ? [ - [ - 1, - 2, - 3 - ] - ] : _a)[0]; + var _b = (_a === void 0 ? [[1, 2, 3]] : _a)[0]; } function baz3(_a) { var ; } function baz4(_a) { - var _b = _a === void 0 ? { - x: 10 - } : _a; + var _b = _a === void 0 ? { x: 10 } : _a; } diff --git a/tests/baselines/reference/declarationEmitDestructuring5.js b/tests/baselines/reference/declarationEmitDestructuring5.js index f0602206a1..32c9b5667d 100644 --- a/tests/baselines/reference/declarationEmitDestructuring5.js +++ b/tests/baselines/reference/declarationEmitDestructuring5.js @@ -16,13 +16,7 @@ function bar(_a) { var z = _a[0]; } function bar1(_a) { - var _b = _a === void 0 ? [ - 1, - 3, - 4, - 6, - 7 - ] : _a, z = _b[0]; + var _b = _a === void 0 ? [1, 3, 4, 6, 7] : _a, z = _b[0]; } function bar2(_a) { var z = _a[2]; From c1d9cfe6408fb5954133ac38bcb867298f2a74bb Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 30 Mar 2015 16:45:20 -0700 Subject: [PATCH 15/28] Add test for emit destructuring invariable declaration with omitted expression --- .../declarationEmitDestructuringArrayPattern5.js | 15 +++++++++++++++ ...eclarationEmitDestructuringArrayPattern5.types | 14 ++++++++++++++ .../declarationEmitDestructuringArrayPattern5.ts | 4 ++++ 3 files changed, 33 insertions(+) create mode 100644 tests/baselines/reference/declarationEmitDestructuringArrayPattern5.js create mode 100644 tests/baselines/reference/declarationEmitDestructuringArrayPattern5.types create mode 100644 tests/cases/compiler/declarationEmitDestructuringArrayPattern5.ts diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern5.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern5.js new file mode 100644 index 0000000000..820864cc25 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern5.js @@ -0,0 +1,15 @@ +//// [declarationEmitDestructuringArrayPattern5.ts] +var [, , z] = [1, 2, 4]; +var [, a, , ] = [3, 4, 5]; +var [, , [, b, ]] = [3,5,[0, 1]]; + +//// [declarationEmitDestructuringArrayPattern5.js] +var _a = [1, 2, 4], z = _a[2]; +var _b = [3, 4, 5], a = _b[1]; +var _c = [3, 5, [0, 1]], _d = _c[2], b = _d[1]; + + +//// [declarationEmitDestructuringArrayPattern5.d.ts] +declare var z: number; +declare var a: number; +declare var b: number; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern5.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern5.types new file mode 100644 index 0000000000..6352917682 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern5.types @@ -0,0 +1,14 @@ +=== tests/cases/compiler/declarationEmitDestructuringArrayPattern5.ts === +var [, , z] = [1, 2, 4]; +>z : number +>[1, 2, 4] : [number, number, number] + +var [, a, , ] = [3, 4, 5]; +>a : number +>[3, 4, 5] : [number, number, number] + +var [, , [, b, ]] = [3,5,[0, 1]]; +>b : number +>[3,5,[0, 1]] : [number, number, [number, number]] +>[0, 1] : [number, number] + diff --git a/tests/cases/compiler/declarationEmitDestructuringArrayPattern5.ts b/tests/cases/compiler/declarationEmitDestructuringArrayPattern5.ts new file mode 100644 index 0000000000..eeb5dd4bdc --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringArrayPattern5.ts @@ -0,0 +1,4 @@ +// @declaration: true +var [, , z] = [1, 2, 4]; +var [, a, , ] = [3, 4, 5]; +var [, , [, b, ]] = [3,5,[0, 1]]; \ No newline at end of file From 4d0aa589f2819649043ec737989cf64b271aa949 Mon Sep 17 00:00:00 2001 From: Zev Spitz Date: Tue, 31 Mar 2015 04:34:55 +0300 Subject: [PATCH 16/28] Allows extending ActiveXObject with with specialized overloads returning string types, per https://github.com/Microsoft/TypeScript/issues/2541. --- src/lib/scriptHost.d.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/scriptHost.d.ts b/src/lib/scriptHost.d.ts index 2639739e5d..bfa562a930 100644 --- a/src/lib/scriptHost.d.ts +++ b/src/lib/scriptHost.d.ts @@ -4,7 +4,11 @@ /// Windows Script Host APIS ///////////////////////////// -declare var ActiveXObject: { new (s: string): any; }; + +interface ActiveXObject { + new (s: string): any; +} +declare var ActiveXObject: ActiveXObject; interface ITextWriter { Write(s: string): void; From 4b7e6cfc2e981fbd005812d0ce5a3c0167f689e4 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 30 Mar 2015 19:33:15 -0700 Subject: [PATCH 17/28] addressed CR feedback, accepted baselines --- src/compiler/checker.ts | 6 +-- src/compiler/commandLineParser.ts | 4 ++ .../diagnosticInformationMap.generated.ts | 6 +++ src/compiler/diagnosticMessages.json | 25 +++++++++- src/compiler/emitter.ts | 9 +++- src/compiler/program.ts | 39 +++++++++++++--- src/compiler/utilities.ts | 7 +++ src/services/services.ts | 46 ++++++------------- .../baselines/reference/APISample_compile.js | 2 + .../reference/APISample_compile.types | 12 +++++ tests/baselines/reference/APISample_linter.js | 2 + .../reference/APISample_linter.types | 12 +++++ .../reference/APISample_transform.js | 2 + .../reference/APISample_transform.types | 12 +++++ .../baselines/reference/APISample_watcher.js | 2 + .../reference/APISample_watcher.types | 12 +++++ 16 files changed, 155 insertions(+), 43 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 58383e2b6f..a5c83f8d3f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -716,7 +716,7 @@ module ts { if (target) { let markAlias = (target === unknownSymbol && compilerOptions.separateCompilation) || - (target !== unknownSymbol && target.flags & SymbolFlags.Value && !isConstEnumOrConstEnumOnlyModule(target)); + (target !== unknownSymbol && (target.flags & SymbolFlags.Value) && !isConstEnumOrConstEnumOnlyModule(target)); if (markAlias) { markAliasSymbolAsReferenced(symbol); @@ -10231,7 +10231,7 @@ module ts { if (symbol.flags & SymbolFlags.ValueModule && symbol.declarations.length > 1 && !isInAmbientContext(node) - && isInstantiatedModule(node, compilerOptions.preserveConstEnums)) { + && isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.separateCompilation)) { let classOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol); if (classOrFunc) { if (getSourceFileOfNode(node) !== getSourceFileOfNode(classOrFunc)) { @@ -11285,7 +11285,7 @@ module ts { return true; } // const enums and modules that contain only const enums are not considered values from the emit perespective - return target !== unknownSymbol && target.flags & SymbolFlags.Value && !isConstEnumOrConstEnumOnlyModule(target); + return target !== unknownSymbol && target && target.flags & SymbolFlags.Value && !isConstEnumOrConstEnumOnlyModule(target); } function isConstEnumOrConstEnumOnlyModule(s: Symbol): boolean { diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 4ba2da757e..c91fef4032 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -117,6 +117,10 @@ module ts { type: "boolean", description: Diagnostics.Do_not_emit_comments_to_output, }, + { + name: "separateCompilation", + type: "boolean", + }, { name: "sourceMap", type: "boolean", diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 967afd171b..a7bbe3a3ba 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -165,6 +165,7 @@ module ts { Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1205, category: DiagnosticCategory.Error, key: "Decorators are only available when targeting ECMAScript 5 and higher." }, Decorators_are_not_valid_here: { code: 1206, category: DiagnosticCategory.Error, key: "Decorators are not valid here." }, Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." }, + Cannot_compile_non_external_modules_when_the_separateCompilation_flag_is_provided: { code: 1208, category: DiagnosticCategory.Error, key: "Cannot compile non-external modules when the '--separateCompilation' flag is provided." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -434,6 +435,11 @@ module ts { 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." }, + Option_sourceMap_cannot_be_specified_with_option_separateCompilation: { code: 5043, category: DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'separateCompilation'." }, + Option_declaration_cannot_be_specified_with_option_separateCompilation: { code: 5044, category: DiagnosticCategory.Error, key: "Option 'declaration' cannot be specified with option 'separateCompilation'." }, + Option_noEmitOnError_cannot_be_specified_with_option_separateCompilation: { code: 5045, category: DiagnosticCategory.Error, key: "Option 'noEmitOnError' cannot be specified with option 'separateCompilation'." }, + Option_out_cannot_be_specified_with_option_separateCompilation: { code: 5046, category: DiagnosticCategory.Error, key: "Option 'out' cannot be specified with option 'separateCompilation'." }, + Option_separateCompilation_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher: { code: 5047, category: DiagnosticCategory.Error, key: "Option 'separateCompilation' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: DiagnosticCategory.Message, key: "Concatenate and emit output to single file." }, Generates_corresponding_d_ts_file: { code: 6002, category: DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." }, Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate map files instead of generated locations." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 6e24afad80..d3643e6536 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -651,7 +651,10 @@ "category": "Error", "code": 1207 }, - + "Cannot compile non-external modules when the '--separateCompilation' flag is provided.": { + "category": "Error", + "code": 1208 + }, "Duplicate identifier '{0}'.": { "category": "Error", "code": 2300 @@ -1729,6 +1732,26 @@ "category": "Error", "code": 5042 }, + "Option 'sourceMap' cannot be specified with option 'separateCompilation'.": { + "category": "Error", + "code": 5043 + }, + "Option 'declaration' cannot be specified with option 'separateCompilation'.": { + "category": "Error", + "code": 5044 + }, + "Option 'noEmitOnError' cannot be specified with option 'separateCompilation'.": { + "category": "Error", + "code": 5045 + }, + "Option 'out' cannot be specified with option 'separateCompilation'.": { + "category": "Error", + "code": 5046 + }, + "Option 'separateCompilation' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher.": { + "category": "Error", + "code": 5047 + }, "Concatenate and emit output to single file.": { "category": "Message", "code": 6001 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 366bb1856e..bf58167bd8 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1641,6 +1641,11 @@ module ts { } function tryEmitConstantValue(node: PropertyAccessExpression | ElementAccessExpression): boolean { + if (compilerOptions.separateCompilation) { + // do not inline enum values in separate compilation mode + return false; + } + let constantValue = resolver.getConstantValue(node); if (constantValue !== undefined) { write(constantValue.toString()); @@ -3874,7 +3879,7 @@ module ts { function shouldEmitEnumDeclaration(node: EnumDeclaration) { let isConstEnum = isConst(node); - return !isConstEnum || compilerOptions.preserveConstEnums; + return !isConstEnum || compilerOptions.preserveConstEnums || compilerOptions.separateCompilation; } function emitEnumDeclaration(node: EnumDeclaration) { @@ -3966,7 +3971,7 @@ module ts { } function shouldEmitModuleDeclaration(node: ModuleDeclaration) { - return isInstantiatedModule(node, compilerOptions.preserveConstEnums); + return isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.separateCompilation); } function emitModuleDeclaration(node: ModuleDeclaration) { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index cb12e6da4d..1deb413231 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -454,6 +454,24 @@ module ts { } function verifyCompilerOptions() { + if (options.separateCompilation) { + if (options.sourceMap) { + diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_sourceMap_cannot_be_specified_with_option_separateCompilation)); + } + + if (options.declaration) { + diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_declaration_cannot_be_specified_with_option_separateCompilation)); + } + + if (options.noEmitOnError) { + diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_noEmitOnError_cannot_be_specified_with_option_separateCompilation)); + } + + if (options.out) { + diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_out_cannot_be_specified_with_option_separateCompilation)); + } + } + if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) { // Error to specify --mapRoot or --sourceRoot without mapSourceFiles if (options.mapRoot) { @@ -468,12 +486,21 @@ module ts { let languageVersion = options.target || ScriptTarget.ES3; let firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined); - if (firstExternalModuleSourceFile && !options.module) { + if (options.separateCompilation) { if (!options.module && languageVersion < ScriptTarget.ES6) { - // We cannot use createDiagnosticFromNode because nodes do not have parents yet - let span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); - diagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided)); + diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_separateCompilation_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); } + + let firstNonExternalModuleSourceFile = forEach(files, f => !isExternalModule(f) ? f : undefined); + if (firstNonExternalModuleSourceFile) { + let span = getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile); + diagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_non_external_modules_when_the_separateCompilation_flag_is_provided)); + } + } + else if (firstExternalModuleSourceFile && languageVersion < ScriptTarget.ES6 && !options.module) { + // We cannot use createDiagnosticFromNode because nodes do not have parents yet + let span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); + diagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided)); } // Cannot specify module gen target when in es6 or above @@ -481,11 +508,11 @@ module ts { diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher)); } - // there has to be common source directory if user specified --outdir || --sourcRoot + // there has to be common source directory if user specified --outdir || --sourceRoot // if user specified --mapRoot, there needs to be common source directory if there would be multiple files being emitted if (options.outDir || // there is --outDir specified options.sourceRoot || // there is --sourceRoot specified - (options.mapRoot && // there is --mapRoot Specified and there would be multiple js files generated + (options.mapRoot && // there is --mapRoot specified and there would be multiple js files generated (!options.out || firstExternalModuleSourceFile !== undefined))) { let commonPathComponents: string[]; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 9fa0674c25..936d40e18d 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -274,6 +274,13 @@ module ts { export function getErrorSpanForNode(sourceFile: SourceFile, node: Node): TextSpan { let errorNode = node; switch (node.kind) { + case SyntaxKind.SourceFile: + let pos = skipTrivia(sourceFile.text, 0, /*stopAfterLineBreak*/ false); + if (pos === sourceFile.text.length) { + // file is empty - return span for the beginning of the file + return createTextSpan(0, 0); + } + return getSpanOfTokenAtPosition(sourceFile, pos); // This list is a work in progress. Add missing node kinds to improve their error // spans. case SyntaxKind.VariableDeclaration: diff --git a/src/services/services.ts b/src/services/services.ts index 2d5ce2d5f2..05e173e70b 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1635,48 +1635,28 @@ module ts { sourceFile.scriptSnapshot = scriptSnapshot; } - export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, syntaxErrors?: Diagnostic[]): string { + /* + * This function will compile source text from 'input' argument using specified compiler options. + * If not options are provided - it will use a set of default compiler options. + * Extra compiler options that will unconditionally be used bu this function are: + * - separateCompilation = true + * - allowNonTsExtensions = true + */ + export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string { let options = compilerOptions ? ts.clone(compilerOptions) : getDefaultCompilerOptions(); - // Single file transformation is only guaranteed to be correct inside an external module. - // External modules have their own scope and cannot contribute to internal modules outside their - // scope. - if (options.target !== ScriptTarget.ES6 && (!options.module || options.module === ModuleKind.None)) { - // TODO: add errors - } - - // In single file transformation the compiler does not have access to declaration sites. - // Const enum property accesses will not be detected if they are not in the same file as the enum. - // thus they are going to be emitted as normal propety access. To ensure correct behaviour at runtime, - // we need to generate the actual enum object so that the property accesses do not fail. - options.preserveConstEnums = true; - - // No reason to get declarations, we are only returning javascript - options.declaration = false; + options.separateCompilation = true; // Filename can be non-ts file. options.allowNonTsExtensions = true; - // enable relaxed emit rules - options.separateCompilation = true; - - // We are not resolving references or modules, or even including the default library. Disabling - // emit on error will block generating the output and has no meaningful use here. - options.noEmitOnError = false; - - // No resolution requests will be honored anyways. So do not do it - options.noResolve = true; - - // TODO (vladima): this should be enabled after adding support to inlinable source maps - options.sourceMap = false; - // Parse var inputFileName = fileName || "module.ts"; var sourceFile = ts.createSourceFile(inputFileName, input, options.target); // Store syntactic diagnostics - if (syntaxErrors && sourceFile.parseDiagnostics) { - syntaxErrors.push(...sourceFile.parseDiagnostics); + if (diagnostics && sourceFile.parseDiagnostics) { + diagnostics.push(...sourceFile.parseDiagnostics); } // Output @@ -1698,6 +1678,10 @@ module ts { var program = ts.createProgram([inputFileName], options, compilerHost); + if (diagnostics) { + diagnostics.push(...program.getGlobalDiagnostics()); + } + // Emit program.emit(); diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 3f0ba5f18c..70e9f76115 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -1243,6 +1243,7 @@ declare module "typescript" { target?: ScriptTarget; version?: boolean; watch?: boolean; + separateCompilation?: boolean; [option: string]: string | number | boolean; } const enum ModuleKind { @@ -1984,6 +1985,7 @@ declare module "typescript" { isCancellationRequested(): boolean; throwIfCancellationRequested(): void; } + function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string; function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile; let disableIncrementalParsing: boolean; function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index eff47a4cb7..f06e49fcba 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -3984,6 +3984,9 @@ declare module "typescript" { watch?: boolean; >watch : boolean + separateCompilation?: boolean; +>separateCompilation : boolean + [option: string]: string | number | boolean; >option : string } @@ -6160,6 +6163,15 @@ declare module "typescript" { throwIfCancellationRequested(): void; >throwIfCancellationRequested : () => void } + function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string; +>transpile : (input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]) => string +>input : string +>compilerOptions : CompilerOptions +>CompilerOptions : CompilerOptions +>fileName : string +>diagnostics : Diagnostic[] +>Diagnostic : Diagnostic + function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile; >createLanguageServiceSourceFile : (fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean) => SourceFile >fileName : string diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index ab48f78aff..9387b52f4b 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -1274,6 +1274,7 @@ declare module "typescript" { target?: ScriptTarget; version?: boolean; watch?: boolean; + separateCompilation?: boolean; [option: string]: string | number | boolean; } const enum ModuleKind { @@ -2015,6 +2016,7 @@ declare module "typescript" { isCancellationRequested(): boolean; throwIfCancellationRequested(): void; } + function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string; function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile; let disableIncrementalParsing: boolean; function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 600bf5c6ad..c92c66afd2 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -4130,6 +4130,9 @@ declare module "typescript" { watch?: boolean; >watch : boolean + separateCompilation?: boolean; +>separateCompilation : boolean + [option: string]: string | number | boolean; >option : string } @@ -6306,6 +6309,15 @@ declare module "typescript" { throwIfCancellationRequested(): void; >throwIfCancellationRequested : () => void } + function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string; +>transpile : (input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]) => string +>input : string +>compilerOptions : CompilerOptions +>CompilerOptions : CompilerOptions +>fileName : string +>diagnostics : Diagnostic[] +>Diagnostic : Diagnostic + function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile; >createLanguageServiceSourceFile : (fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean) => SourceFile >fileName : string diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index d40c078a15..fba3642d36 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -1275,6 +1275,7 @@ declare module "typescript" { target?: ScriptTarget; version?: boolean; watch?: boolean; + separateCompilation?: boolean; [option: string]: string | number | boolean; } const enum ModuleKind { @@ -2016,6 +2017,7 @@ declare module "typescript" { isCancellationRequested(): boolean; throwIfCancellationRequested(): void; } + function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string; function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile; let disableIncrementalParsing: boolean; function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 4ea9c49d75..a7a898e01b 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -4080,6 +4080,9 @@ declare module "typescript" { watch?: boolean; >watch : boolean + separateCompilation?: boolean; +>separateCompilation : boolean + [option: string]: string | number | boolean; >option : string } @@ -6256,6 +6259,15 @@ declare module "typescript" { throwIfCancellationRequested(): void; >throwIfCancellationRequested : () => void } + function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string; +>transpile : (input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]) => string +>input : string +>compilerOptions : CompilerOptions +>CompilerOptions : CompilerOptions +>fileName : string +>diagnostics : Diagnostic[] +>Diagnostic : Diagnostic + function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile; >createLanguageServiceSourceFile : (fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean) => SourceFile >fileName : string diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index c53034c11d..1a203faea4 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -1312,6 +1312,7 @@ declare module "typescript" { target?: ScriptTarget; version?: boolean; watch?: boolean; + separateCompilation?: boolean; [option: string]: string | number | boolean; } const enum ModuleKind { @@ -2053,6 +2054,7 @@ declare module "typescript" { isCancellationRequested(): boolean; throwIfCancellationRequested(): void; } + function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string; function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile; let disableIncrementalParsing: boolean; function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 3903e169b4..acbbfdb2ea 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -4253,6 +4253,9 @@ declare module "typescript" { watch?: boolean; >watch : boolean + separateCompilation?: boolean; +>separateCompilation : boolean + [option: string]: string | number | boolean; >option : string } @@ -6429,6 +6432,15 @@ declare module "typescript" { throwIfCancellationRequested(): void; >throwIfCancellationRequested : () => void } + function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string; +>transpile : (input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]) => string +>input : string +>compilerOptions : CompilerOptions +>CompilerOptions : CompilerOptions +>fileName : string +>diagnostics : Diagnostic[] +>Diagnostic : Diagnostic + function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile; >createLanguageServiceSourceFile : (fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean) => SourceFile >fileName : string From a6c88e290efb1f8f659f6bfe66833fda4345afc6 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 30 Mar 2015 21:35:27 -0700 Subject: [PATCH 18/28] addressed CR feedback --- src/services/services.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 05e173e70b..296ff033ef 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1643,7 +1643,7 @@ module ts { * - allowNonTsExtensions = true */ export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string { - let options = compilerOptions ? ts.clone(compilerOptions) : getDefaultCompilerOptions(); + let options = compilerOptions ? clone(compilerOptions) : getDefaultCompilerOptions(); options.separateCompilation = true; @@ -1676,7 +1676,7 @@ module ts { getNewLine: () => "\r\n" }; - var program = ts.createProgram([inputFileName], options, compilerHost); + var program = createProgram([inputFileName], options, compilerHost); if (diagnostics) { diagnostics.push(...program.getGlobalDiagnostics()); From 955b4c05890bf2e10611ea954672415a55d343b7 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 30 Mar 2015 21:36:06 -0700 Subject: [PATCH 19/28] addressed CR feedback --- src/services/services.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/services.ts b/src/services/services.ts index 296ff033ef..e481479150 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1652,7 +1652,7 @@ module ts { // Parse var inputFileName = fileName || "module.ts"; - var sourceFile = ts.createSourceFile(inputFileName, input, options.target); + var sourceFile = createSourceFile(inputFileName, input, options.target); // Store syntactic diagnostics if (diagnostics && sourceFile.parseDiagnostics) { From c885f59d1b4f176afb872c852649b585fed05900 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 30 Mar 2015 22:41:49 -0700 Subject: [PATCH 20/28] do not include declaration files in 'is external module' check --- src/compiler/program.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 1deb413231..6a211d6213 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -491,7 +491,7 @@ module ts { diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_separateCompilation_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); } - let firstNonExternalModuleSourceFile = forEach(files, f => !isExternalModule(f) ? f : undefined); + let firstNonExternalModuleSourceFile = forEach(files, f => !isExternalModule(f) && !isDeclarationFile(f) ? f : undefined); if (firstNonExternalModuleSourceFile) { let span = getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile); diagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_non_external_modules_when_the_separateCompilation_flag_is_provided)); From 49b3f85a179db0b020312214f681f670ccf7c0a4 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 30 Mar 2015 22:42:54 -0700 Subject: [PATCH 21/28] disallow ambient const enums in 'separate compilation' mode --- src/compiler/checker.ts | 6 +++++- src/compiler/diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a5c83f8d3f..d303be36f7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10159,6 +10159,11 @@ module ts { computeEnumMemberValues(node); + let enumIsConst = isConst(node); + if (compilerOptions.separateCompilation && enumIsConst && isInAmbientContext(node)) { + error(node.name, Diagnostics.Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided); + } + // Spec 2014 - Section 9.3: // It isn't possible for one enum declaration to continue the automatic numbering sequence of another, // and when an enum type has multiple declarations, only one declaration is permitted to omit a value @@ -10169,7 +10174,6 @@ module ts { let firstDeclaration = getDeclarationOfKind(enumSymbol, node.kind); if (node === firstDeclaration) { if (enumSymbol.declarations.length > 1) { - let enumIsConst = isConst(node); // check that const is placed\omitted on all enum declarations forEach(enumSymbol.declarations, decl => { if (isConstEnumDeclaration(decl) !== enumIsConst) { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index a7bbe3a3ba..32d36020d3 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -166,6 +166,7 @@ module ts { Decorators_are_not_valid_here: { code: 1206, category: DiagnosticCategory.Error, key: "Decorators are not valid here." }, Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." }, Cannot_compile_non_external_modules_when_the_separateCompilation_flag_is_provided: { code: 1208, category: DiagnosticCategory.Error, key: "Cannot compile non-external modules when the '--separateCompilation' flag is provided." }, + Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided: { code: 1209, category: DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--separateCompilation' flag is provided." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index d3643e6536..f593ac2ff7 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -655,6 +655,10 @@ "category": "Error", "code": 1208 }, + "Ambient const enums are not allowed when the '--separateCompilation' flag is provided.": { + "category": "Error", + "code": 1209 + }, "Duplicate identifier '{0}'.": { "category": "Error", "code": 2300 From 1803d730c2f737dda8ec765744745f8ffb4acf27 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 30 Mar 2015 23:17:45 -0700 Subject: [PATCH 22/28] added initial set of unit tests for separate compilation mode --- src/harness/harness.ts | 11 +++++++- ...rateCompilationAmbientConstEnum.errors.txt | 10 +++++++ .../separateCompilationAmbientConstEnum.js | 8 ++++++ .../separateCompilationDeclaration.errors.txt | 7 +++++ .../separateCompilationDeclaration.js | 10 +++++++ .../reference/separateCompilationES6.js | 5 ++++ .../reference/separateCompilationES6.types | 4 +++ ...eparateCompilationNoEmitOnError.errors.txt | 7 +++++ ...rateCompilationNoExternalModule.errors.txt | 8 ++++++ .../separateCompilationNoExternalModule.js | 6 +++++ .../separateCompilationNonAmbientConstEnum.js | 14 ++++++++++ ...parateCompilationNonAmbientConstEnum.types | 15 +++++++++++ .../separateCompilationOut.errors.txt | 12 +++++++++ .../reference/separateCompilationOut.js | 12 +++++++++ .../separateCompilationSourceMap.errors.txt | 7 +++++ .../reference/separateCompilationSourceMap.js | 7 +++++ .../separateCompilationSourceMap.js.map | 2 ++ ...separateCompilationSourceMap.sourcemap.txt | 27 +++++++++++++++++++ .../separateCompilationSpecifiedModule.js | 5 ++++ .../separateCompilationSpecifiedModule.types | 4 +++ ...ateCompilationUnspecifiedModule.errors.txt | 6 +++++ .../separateCompilationUnspecifiedModule.js | 5 ++++ .../separateCompilationWithDeclarationFile.js | 11 ++++++++ ...parateCompilationWithDeclarationFile.types | 9 +++++++ .../separateCompilationAmbientConstEnum.ts | 7 +++++ .../separateCompilationDeclaration.ts | 6 +++++ .../cases/compiler/separateCompilationES6.ts | 4 +++ .../separateCompilationNoEmitOnError.ts | 6 +++++ .../separateCompilationNoExternalModule.ts | 5 ++++ .../separateCompilationNonAmbientConstEnum.ts | 7 +++++ .../cases/compiler/separateCompilationOut.ts | 8 ++++++ .../compiler/separateCompilationSourceMap.ts | 6 +++++ .../separateCompilationSpecifiedModule.ts | 4 +++ .../separateCompilationUnspecifiedModule.ts | 3 +++ .../separateCompilationWithDeclarationFile.ts | 8 ++++++ 35 files changed, 275 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/separateCompilationAmbientConstEnum.errors.txt create mode 100644 tests/baselines/reference/separateCompilationAmbientConstEnum.js create mode 100644 tests/baselines/reference/separateCompilationDeclaration.errors.txt create mode 100644 tests/baselines/reference/separateCompilationDeclaration.js create mode 100644 tests/baselines/reference/separateCompilationES6.js create mode 100644 tests/baselines/reference/separateCompilationES6.types create mode 100644 tests/baselines/reference/separateCompilationNoEmitOnError.errors.txt create mode 100644 tests/baselines/reference/separateCompilationNoExternalModule.errors.txt create mode 100644 tests/baselines/reference/separateCompilationNoExternalModule.js create mode 100644 tests/baselines/reference/separateCompilationNonAmbientConstEnum.js create mode 100644 tests/baselines/reference/separateCompilationNonAmbientConstEnum.types create mode 100644 tests/baselines/reference/separateCompilationOut.errors.txt create mode 100644 tests/baselines/reference/separateCompilationOut.js create mode 100644 tests/baselines/reference/separateCompilationSourceMap.errors.txt create mode 100644 tests/baselines/reference/separateCompilationSourceMap.js create mode 100644 tests/baselines/reference/separateCompilationSourceMap.js.map create mode 100644 tests/baselines/reference/separateCompilationSourceMap.sourcemap.txt create mode 100644 tests/baselines/reference/separateCompilationSpecifiedModule.js create mode 100644 tests/baselines/reference/separateCompilationSpecifiedModule.types create mode 100644 tests/baselines/reference/separateCompilationUnspecifiedModule.errors.txt create mode 100644 tests/baselines/reference/separateCompilationUnspecifiedModule.js create mode 100644 tests/baselines/reference/separateCompilationWithDeclarationFile.js create mode 100644 tests/baselines/reference/separateCompilationWithDeclarationFile.types create mode 100644 tests/cases/compiler/separateCompilationAmbientConstEnum.ts create mode 100644 tests/cases/compiler/separateCompilationDeclaration.ts create mode 100644 tests/cases/compiler/separateCompilationES6.ts create mode 100644 tests/cases/compiler/separateCompilationNoEmitOnError.ts create mode 100644 tests/cases/compiler/separateCompilationNoExternalModule.ts create mode 100644 tests/cases/compiler/separateCompilationNonAmbientConstEnum.ts create mode 100644 tests/cases/compiler/separateCompilationOut.ts create mode 100644 tests/cases/compiler/separateCompilationSourceMap.ts create mode 100644 tests/cases/compiler/separateCompilationSpecifiedModule.ts create mode 100644 tests/cases/compiler/separateCompilationUnspecifiedModule.ts create mode 100644 tests/cases/compiler/separateCompilationWithDeclarationFile.ts diff --git a/src/harness/harness.ts b/src/harness/harness.ts index f401f19da2..55f0910524 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1062,6 +1062,10 @@ module Harness { options.preserveConstEnums = setting.value === 'true'; break; + case 'separatecompilation': + options.separateCompilation = setting.value === 'true'; + break; + case 'suppressimplicitanyindexerrors': options.suppressImplicitAnyIndexErrors = setting.value === 'true'; break; @@ -1461,7 +1465,12 @@ module Harness { var optionRegex = /^[\/]{2}\s*@(\w+)\s*:\s*(\S*)/gm; // multiple matches on multiple lines // List of allowed metadata names - var fileMetadataNames = ["filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outdir", "noemitonerror", "noimplicitany", "noresolve", "newline", "newlines", "emitbom", "errortruncation", "usecasesensitivefilenames", "preserveconstenums", "includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal"]; + var fileMetadataNames = ["filename", "comments", "declaration", "module", + "nolib", "sourcemap", "target", "out", "outdir", "noemitonerror", + "noimplicitany", "noresolve", "newline", "newlines", "emitbom", + "errortruncation", "usecasesensitivefilenames", "preserveconstenums", + "includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal", + "separatecompilation"]; function extractCompilerSettings(content: string): CompilerSetting[] { diff --git a/tests/baselines/reference/separateCompilationAmbientConstEnum.errors.txt b/tests/baselines/reference/separateCompilationAmbientConstEnum.errors.txt new file mode 100644 index 0000000000..6ea2e445e2 --- /dev/null +++ b/tests/baselines/reference/separateCompilationAmbientConstEnum.errors.txt @@ -0,0 +1,10 @@ +tests/cases/compiler/separateCompilationAmbientConstEnum.ts(3,20): error TS1209: Ambient const enums are not allowed when the '--separateCompilation' flag is provided. + + +==== tests/cases/compiler/separateCompilationAmbientConstEnum.ts (1 errors) ==== + + + declare const enum E { X = 1} + ~ +!!! error TS1209: Ambient const enums are not allowed when the '--separateCompilation' flag is provided. + export var y; \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationAmbientConstEnum.js b/tests/baselines/reference/separateCompilationAmbientConstEnum.js new file mode 100644 index 0000000000..5b3af0957e --- /dev/null +++ b/tests/baselines/reference/separateCompilationAmbientConstEnum.js @@ -0,0 +1,8 @@ +//// [separateCompilationAmbientConstEnum.ts] + + +declare const enum E { X = 1} +export var y; + +//// [separateCompilationAmbientConstEnum.js] +export var y; diff --git a/tests/baselines/reference/separateCompilationDeclaration.errors.txt b/tests/baselines/reference/separateCompilationDeclaration.errors.txt new file mode 100644 index 0000000000..8951184584 --- /dev/null +++ b/tests/baselines/reference/separateCompilationDeclaration.errors.txt @@ -0,0 +1,7 @@ +error TS5044: Option 'declaration' cannot be specified with option 'separateCompilation'. + + +!!! error TS5044: Option 'declaration' cannot be specified with option 'separateCompilation'. +==== tests/cases/compiler/separateCompilationDeclaration.ts (0 errors) ==== + + export var x; \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationDeclaration.js b/tests/baselines/reference/separateCompilationDeclaration.js new file mode 100644 index 0000000000..33d64b088d --- /dev/null +++ b/tests/baselines/reference/separateCompilationDeclaration.js @@ -0,0 +1,10 @@ +//// [separateCompilationDeclaration.ts] + +export var x; + +//// [separateCompilationDeclaration.js] +export var x; + + +//// [separateCompilationDeclaration.d.ts] +export declare var x: any; diff --git a/tests/baselines/reference/separateCompilationES6.js b/tests/baselines/reference/separateCompilationES6.js new file mode 100644 index 0000000000..cf05e5590a --- /dev/null +++ b/tests/baselines/reference/separateCompilationES6.js @@ -0,0 +1,5 @@ +//// [separateCompilationES6.ts] +export var x; + +//// [separateCompilationES6.js] +export var x; diff --git a/tests/baselines/reference/separateCompilationES6.types b/tests/baselines/reference/separateCompilationES6.types new file mode 100644 index 0000000000..7038190680 --- /dev/null +++ b/tests/baselines/reference/separateCompilationES6.types @@ -0,0 +1,4 @@ +=== tests/cases/compiler/separateCompilationES6.ts === +export var x; +>x : any + diff --git a/tests/baselines/reference/separateCompilationNoEmitOnError.errors.txt b/tests/baselines/reference/separateCompilationNoEmitOnError.errors.txt new file mode 100644 index 0000000000..61d4f2d6d9 --- /dev/null +++ b/tests/baselines/reference/separateCompilationNoEmitOnError.errors.txt @@ -0,0 +1,7 @@ +error TS5045: Option 'noEmitOnError' cannot be specified with option 'separateCompilation'. + + +!!! error TS5045: Option 'noEmitOnError' cannot be specified with option 'separateCompilation'. +==== tests/cases/compiler/separateCompilationNoEmitOnError.ts (0 errors) ==== + + export var x; \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationNoExternalModule.errors.txt b/tests/baselines/reference/separateCompilationNoExternalModule.errors.txt new file mode 100644 index 0000000000..269727584d --- /dev/null +++ b/tests/baselines/reference/separateCompilationNoExternalModule.errors.txt @@ -0,0 +1,8 @@ +tests/cases/compiler/separateCompilationNoExternalModule.ts(2,1): error TS1208: Cannot compile non-external modules when the '--separateCompilation' flag is provided. + + +==== tests/cases/compiler/separateCompilationNoExternalModule.ts (1 errors) ==== + + var x; + ~~~ +!!! error TS1208: Cannot compile non-external modules when the '--separateCompilation' flag is provided. \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationNoExternalModule.js b/tests/baselines/reference/separateCompilationNoExternalModule.js new file mode 100644 index 0000000000..9ddc8bdef2 --- /dev/null +++ b/tests/baselines/reference/separateCompilationNoExternalModule.js @@ -0,0 +1,6 @@ +//// [separateCompilationNoExternalModule.ts] + +var x; + +//// [separateCompilationNoExternalModule.js] +var x; diff --git a/tests/baselines/reference/separateCompilationNonAmbientConstEnum.js b/tests/baselines/reference/separateCompilationNonAmbientConstEnum.js new file mode 100644 index 0000000000..74096adca1 --- /dev/null +++ b/tests/baselines/reference/separateCompilationNonAmbientConstEnum.js @@ -0,0 +1,14 @@ +//// [separateCompilationNonAmbientConstEnum.ts] + +const enum E { X = 100 }; +var e = E.X; +export var x; + +//// [separateCompilationNonAmbientConstEnum.js] +var E; +(function (E) { + E[E["X"] = 100] = "X"; +})(E || (E = {})); +; +var e = E.X; +export var x; diff --git a/tests/baselines/reference/separateCompilationNonAmbientConstEnum.types b/tests/baselines/reference/separateCompilationNonAmbientConstEnum.types new file mode 100644 index 0000000000..d444cbd149 --- /dev/null +++ b/tests/baselines/reference/separateCompilationNonAmbientConstEnum.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/separateCompilationNonAmbientConstEnum.ts === + +const enum E { X = 100 }; +>E : E +>X : E + +var e = E.X; +>e : E +>E.X : E +>E : typeof E +>X : E + +export var x; +>x : any + diff --git a/tests/baselines/reference/separateCompilationOut.errors.txt b/tests/baselines/reference/separateCompilationOut.errors.txt new file mode 100644 index 0000000000..7c2631a718 --- /dev/null +++ b/tests/baselines/reference/separateCompilationOut.errors.txt @@ -0,0 +1,12 @@ +error TS5046: Option 'out' cannot be specified with option 'separateCompilation'. +tests/cases/compiler/file2.ts(1,1): error TS1208: Cannot compile non-external modules when the '--separateCompilation' flag is provided. + + +!!! error TS5046: Option 'out' cannot be specified with option 'separateCompilation'. +==== tests/cases/compiler/file1.ts (0 errors) ==== + + export var x; +==== tests/cases/compiler/file2.ts (1 errors) ==== + var y; + ~~~ +!!! error TS1208: Cannot compile non-external modules when the '--separateCompilation' flag is provided. \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationOut.js b/tests/baselines/reference/separateCompilationOut.js new file mode 100644 index 0000000000..67dd2dcfbf --- /dev/null +++ b/tests/baselines/reference/separateCompilationOut.js @@ -0,0 +1,12 @@ +//// [tests/cases/compiler/separateCompilationOut.ts] //// + +//// [file1.ts] + +export var x; +//// [file2.ts] +var y; + +//// [file1.js] +export var x; +//// [all.js] +var y; diff --git a/tests/baselines/reference/separateCompilationSourceMap.errors.txt b/tests/baselines/reference/separateCompilationSourceMap.errors.txt new file mode 100644 index 0000000000..5274ef3921 --- /dev/null +++ b/tests/baselines/reference/separateCompilationSourceMap.errors.txt @@ -0,0 +1,7 @@ +error TS5043: Option 'sourceMap' cannot be specified with option 'separateCompilation'. + + +!!! error TS5043: Option 'sourceMap' cannot be specified with option 'separateCompilation'. +==== tests/cases/compiler/separateCompilationSourceMap.ts (0 errors) ==== + + export var x; \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationSourceMap.js b/tests/baselines/reference/separateCompilationSourceMap.js new file mode 100644 index 0000000000..1e8f141eb4 --- /dev/null +++ b/tests/baselines/reference/separateCompilationSourceMap.js @@ -0,0 +1,7 @@ +//// [separateCompilationSourceMap.ts] + +export var x; + +//// [separateCompilationSourceMap.js] +export var x; +//# sourceMappingURL=separateCompilationSourceMap.js.map \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationSourceMap.js.map b/tests/baselines/reference/separateCompilationSourceMap.js.map new file mode 100644 index 0000000000..68c4e2c78d --- /dev/null +++ b/tests/baselines/reference/separateCompilationSourceMap.js.map @@ -0,0 +1,2 @@ +//// [separateCompilationSourceMap.js.map] +{"version":3,"file":"separateCompilationSourceMap.js","sourceRoot":"","sources":["separateCompilationSourceMap.ts"],"names":[],"mappings":"AACA,WAAW,CAAC,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationSourceMap.sourcemap.txt b/tests/baselines/reference/separateCompilationSourceMap.sourcemap.txt new file mode 100644 index 0000000000..74e0d73d7e --- /dev/null +++ b/tests/baselines/reference/separateCompilationSourceMap.sourcemap.txt @@ -0,0 +1,27 @@ +=================================================================== +JsFile: separateCompilationSourceMap.js +mapUrl: separateCompilationSourceMap.js.map +sourceRoot: +sources: separateCompilationSourceMap.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/separateCompilationSourceMap.js +sourceFile:separateCompilationSourceMap.ts +------------------------------------------------------------------- +>>>export var x; +1 > +2 >^^^^^^^^^^^ +3 > ^ +4 > ^ +5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > +2 >export var +3 > x +4 > ; +1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(1, 12) Source(2, 12) + SourceIndex(0) +3 >Emitted(1, 13) Source(2, 13) + SourceIndex(0) +4 >Emitted(1, 14) Source(2, 14) + SourceIndex(0) +--- +>>>//# sourceMappingURL=separateCompilationSourceMap.js.map \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationSpecifiedModule.js b/tests/baselines/reference/separateCompilationSpecifiedModule.js new file mode 100644 index 0000000000..5f3c7ceb39 --- /dev/null +++ b/tests/baselines/reference/separateCompilationSpecifiedModule.js @@ -0,0 +1,5 @@ +//// [separateCompilationSpecifiedModule.ts] +export var x; + +//// [separateCompilationSpecifiedModule.js] +exports.x; diff --git a/tests/baselines/reference/separateCompilationSpecifiedModule.types b/tests/baselines/reference/separateCompilationSpecifiedModule.types new file mode 100644 index 0000000000..497f63faf6 --- /dev/null +++ b/tests/baselines/reference/separateCompilationSpecifiedModule.types @@ -0,0 +1,4 @@ +=== tests/cases/compiler/separateCompilationSpecifiedModule.ts === +export var x; +>x : any + diff --git a/tests/baselines/reference/separateCompilationUnspecifiedModule.errors.txt b/tests/baselines/reference/separateCompilationUnspecifiedModule.errors.txt new file mode 100644 index 0000000000..ab0fd7ffe9 --- /dev/null +++ b/tests/baselines/reference/separateCompilationUnspecifiedModule.errors.txt @@ -0,0 +1,6 @@ +error TS5047: Option 'separateCompilation' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher. + + +!!! error TS5047: Option 'separateCompilation' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher. +==== tests/cases/compiler/separateCompilationUnspecifiedModule.ts (0 errors) ==== + export var x; \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationUnspecifiedModule.js b/tests/baselines/reference/separateCompilationUnspecifiedModule.js new file mode 100644 index 0000000000..0f2e5c71a8 --- /dev/null +++ b/tests/baselines/reference/separateCompilationUnspecifiedModule.js @@ -0,0 +1,5 @@ +//// [separateCompilationUnspecifiedModule.ts] +export var x; + +//// [separateCompilationUnspecifiedModule.js] +exports.x; diff --git a/tests/baselines/reference/separateCompilationWithDeclarationFile.js b/tests/baselines/reference/separateCompilationWithDeclarationFile.js new file mode 100644 index 0000000000..71d7ef4192 --- /dev/null +++ b/tests/baselines/reference/separateCompilationWithDeclarationFile.js @@ -0,0 +1,11 @@ +//// [tests/cases/compiler/separateCompilationWithDeclarationFile.ts] //// + +//// [file1.d.ts] + +declare function foo(): void; + +//// [file1.ts] +export var x; + +//// [file1.js] +export var x; diff --git a/tests/baselines/reference/separateCompilationWithDeclarationFile.types b/tests/baselines/reference/separateCompilationWithDeclarationFile.types new file mode 100644 index 0000000000..94adc5fa27 --- /dev/null +++ b/tests/baselines/reference/separateCompilationWithDeclarationFile.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/file1.d.ts === + +declare function foo(): void; +>foo : () => void + +=== tests/cases/compiler/file1.ts === +export var x; +>x : any + diff --git a/tests/cases/compiler/separateCompilationAmbientConstEnum.ts b/tests/cases/compiler/separateCompilationAmbientConstEnum.ts new file mode 100644 index 0000000000..aaccfaaf02 --- /dev/null +++ b/tests/cases/compiler/separateCompilationAmbientConstEnum.ts @@ -0,0 +1,7 @@ +// @separateCompilation: true +// @target: es6 + +// @filename: file1.ts + +declare const enum E { X = 1} +export var y; \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationDeclaration.ts b/tests/cases/compiler/separateCompilationDeclaration.ts new file mode 100644 index 0000000000..11003a1919 --- /dev/null +++ b/tests/cases/compiler/separateCompilationDeclaration.ts @@ -0,0 +1,6 @@ +// @separateCompilation: true +// @declaration: true +// @target: es6 + +// @filename: file1.ts +export var x; \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationES6.ts b/tests/cases/compiler/separateCompilationES6.ts new file mode 100644 index 0000000000..a2ac8c8d94 --- /dev/null +++ b/tests/cases/compiler/separateCompilationES6.ts @@ -0,0 +1,4 @@ +// @separateCompilation: true +// @target: es6 +// @filename: file1.ts +export var x; \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationNoEmitOnError.ts b/tests/cases/compiler/separateCompilationNoEmitOnError.ts new file mode 100644 index 0000000000..fe0f59199f --- /dev/null +++ b/tests/cases/compiler/separateCompilationNoEmitOnError.ts @@ -0,0 +1,6 @@ +// @separateCompilation: true +// @noEmitOnError:true +// @target: es6 + +// @filename: file1.ts +export var x; \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationNoExternalModule.ts b/tests/cases/compiler/separateCompilationNoExternalModule.ts new file mode 100644 index 0000000000..e66ef27c00 --- /dev/null +++ b/tests/cases/compiler/separateCompilationNoExternalModule.ts @@ -0,0 +1,5 @@ +// @separateCompilation: true +// @target: es6 + +// @filename: file1.ts +var x; \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationNonAmbientConstEnum.ts b/tests/cases/compiler/separateCompilationNonAmbientConstEnum.ts new file mode 100644 index 0000000000..5f3054238d --- /dev/null +++ b/tests/cases/compiler/separateCompilationNonAmbientConstEnum.ts @@ -0,0 +1,7 @@ +// @separateCompilation: true +// @target: es6 + +// @filename: file1.ts +const enum E { X = 100 }; +var e = E.X; +export var x; \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationOut.ts b/tests/cases/compiler/separateCompilationOut.ts new file mode 100644 index 0000000000..6c0a95f8ae --- /dev/null +++ b/tests/cases/compiler/separateCompilationOut.ts @@ -0,0 +1,8 @@ +// @separateCompilation: true +// @out:all.js +// @target: es6 + +// @filename: file1.ts +export var x; +// @filename: file2.ts +var y; \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationSourceMap.ts b/tests/cases/compiler/separateCompilationSourceMap.ts new file mode 100644 index 0000000000..7becf7cbda --- /dev/null +++ b/tests/cases/compiler/separateCompilationSourceMap.ts @@ -0,0 +1,6 @@ +// @separateCompilation: true +// @sourceMap:sourcemap.map +// @target: es6 + +// @filename: file1.ts +export var x; \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationSpecifiedModule.ts b/tests/cases/compiler/separateCompilationSpecifiedModule.ts new file mode 100644 index 0000000000..6ba3a0d3bf --- /dev/null +++ b/tests/cases/compiler/separateCompilationSpecifiedModule.ts @@ -0,0 +1,4 @@ +// @separateCompilation: true +// @module: commonjs +// @filename: file1.ts +export var x; \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationUnspecifiedModule.ts b/tests/cases/compiler/separateCompilationUnspecifiedModule.ts new file mode 100644 index 0000000000..38a3fd8286 --- /dev/null +++ b/tests/cases/compiler/separateCompilationUnspecifiedModule.ts @@ -0,0 +1,3 @@ +// @separateCompilation: true +// @filename: file1.ts +export var x; \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationWithDeclarationFile.ts b/tests/cases/compiler/separateCompilationWithDeclarationFile.ts new file mode 100644 index 0000000000..121db1702a --- /dev/null +++ b/tests/cases/compiler/separateCompilationWithDeclarationFile.ts @@ -0,0 +1,8 @@ +// @separateCompilation: true +// @target: es6 + +// @filename: file1.d.ts +declare function foo(): void; + +// @filename: file1.ts +export var x; \ No newline at end of file From cebe42b81fbeeaf68c8e228dda5e602ab94e151b Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 30 Mar 2015 23:32:11 -0700 Subject: [PATCH 23/28] Remove unsed options --- src/compiler/commandLineParser.ts | 8 -------- src/compiler/types.ts | 2 -- src/harness/harness.ts | 10 ---------- tests/baselines/reference/APISample_compile.js | 2 -- tests/baselines/reference/APISample_compile.types | 6 ------ tests/baselines/reference/APISample_linter.js | 2 -- tests/baselines/reference/APISample_linter.types | 6 ------ tests/baselines/reference/APISample_transform.js | 2 -- tests/baselines/reference/APISample_transform.types | 6 ------ tests/baselines/reference/APISample_watcher.js | 2 -- tests/baselines/reference/APISample_watcher.types | 6 ------ 11 files changed, 52 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 4ba2da757e..96c1bc9e29 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -9,10 +9,6 @@ module ts { name: "charset", type: "string", }, - { - name: "codepage", - type: "number", - }, { name: "declaration", shortName: "d", @@ -78,10 +74,6 @@ module ts { name: "noLib", type: "boolean", }, - { - name: "noLibCheck", - type: "boolean", - }, { name: "noResolve", type: "boolean", diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d24ee45e21..56d5b0a7e1 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1560,7 +1560,6 @@ module ts { export interface CompilerOptions { allowNonTsExtensions?: boolean; charset?: string; - codepage?: number; declaration?: boolean; diagnostics?: boolean; emitBOM?: boolean; @@ -1574,7 +1573,6 @@ module ts { noErrorTruncation?: boolean; noImplicitAny?: boolean; noLib?: boolean; - noLibCheck?: boolean; noResolve?: boolean; out?: string; outDir?: string; diff --git a/src/harness/harness.ts b/src/harness/harness.ts index f401f19da2..40bf68f0a3 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1036,17 +1036,7 @@ module Harness { useCaseSensitiveFileNames = setting.value === 'true'; break; - case 'mapsourcefiles': - case 'maproot': - case 'generatedeclarationfiles': - case 'gatherDiagnostics': - case 'codepage': - case 'createFileLog': case 'filename': - case 'removecomments': - case 'watch': - case 'allowautomaticsemicoloninsertion': - case 'locale': // Not supported yet break; diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 3f0ba5f18c..397404ee98 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -1216,7 +1216,6 @@ declare module "typescript" { interface CompilerOptions { allowNonTsExtensions?: boolean; charset?: string; - codepage?: number; declaration?: boolean; diagnostics?: boolean; emitBOM?: boolean; @@ -1230,7 +1229,6 @@ declare module "typescript" { noErrorTruncation?: boolean; noImplicitAny?: boolean; noLib?: boolean; - noLibCheck?: boolean; noResolve?: boolean; out?: string; outDir?: string; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index eff47a4cb7..b23ab38e0c 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -3901,9 +3901,6 @@ declare module "typescript" { charset?: string; >charset : string - codepage?: number; ->codepage : number - declaration?: boolean; >declaration : boolean @@ -3944,9 +3941,6 @@ declare module "typescript" { noLib?: boolean; >noLib : boolean - noLibCheck?: boolean; ->noLibCheck : boolean - noResolve?: boolean; >noResolve : boolean diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index ab48f78aff..fc8f844ac0 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -1247,7 +1247,6 @@ declare module "typescript" { interface CompilerOptions { allowNonTsExtensions?: boolean; charset?: string; - codepage?: number; declaration?: boolean; diagnostics?: boolean; emitBOM?: boolean; @@ -1261,7 +1260,6 @@ declare module "typescript" { noErrorTruncation?: boolean; noImplicitAny?: boolean; noLib?: boolean; - noLibCheck?: boolean; noResolve?: boolean; out?: string; outDir?: string; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 600bf5c6ad..64e4910853 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -4047,9 +4047,6 @@ declare module "typescript" { charset?: string; >charset : string - codepage?: number; ->codepage : number - declaration?: boolean; >declaration : boolean @@ -4090,9 +4087,6 @@ declare module "typescript" { noLib?: boolean; >noLib : boolean - noLibCheck?: boolean; ->noLibCheck : boolean - noResolve?: boolean; >noResolve : boolean diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index d40c078a15..77c7727811 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -1248,7 +1248,6 @@ declare module "typescript" { interface CompilerOptions { allowNonTsExtensions?: boolean; charset?: string; - codepage?: number; declaration?: boolean; diagnostics?: boolean; emitBOM?: boolean; @@ -1262,7 +1261,6 @@ declare module "typescript" { noErrorTruncation?: boolean; noImplicitAny?: boolean; noLib?: boolean; - noLibCheck?: boolean; noResolve?: boolean; out?: string; outDir?: string; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 4ea9c49d75..7a284e2026 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -3997,9 +3997,6 @@ declare module "typescript" { charset?: string; >charset : string - codepage?: number; ->codepage : number - declaration?: boolean; >declaration : boolean @@ -4040,9 +4037,6 @@ declare module "typescript" { noLib?: boolean; >noLib : boolean - noLibCheck?: boolean; ->noLibCheck : boolean - noResolve?: boolean; >noResolve : boolean diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index c53034c11d..8340a5150c 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -1285,7 +1285,6 @@ declare module "typescript" { interface CompilerOptions { allowNonTsExtensions?: boolean; charset?: string; - codepage?: number; declaration?: boolean; diagnostics?: boolean; emitBOM?: boolean; @@ -1299,7 +1298,6 @@ declare module "typescript" { noErrorTruncation?: boolean; noImplicitAny?: boolean; noLib?: boolean; - noLibCheck?: boolean; noResolve?: boolean; out?: string; outDir?: string; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 3903e169b4..d151e8f046 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -4170,9 +4170,6 @@ declare module "typescript" { charset?: string; >charset : string - codepage?: number; ->codepage : number - declaration?: boolean; >declaration : boolean @@ -4213,9 +4210,6 @@ declare module "typescript" { noLib?: boolean; >noLib : boolean - noLibCheck?: boolean; ->noLibCheck : boolean - noResolve?: boolean; >noResolve : boolean From d53e0c2ac2c0655cb656b02c774684bd52c5072b Mon Sep 17 00:00:00 2001 From: Zev Spitz Date: Tue, 31 Mar 2015 12:59:50 +0300 Subject: [PATCH 24/28] Added properties/methods for WScript - https://msdn.microsoft.com/en-us/library/2795740w(v=vs.84).aspx per #2540 --- src/lib/scriptHost.d.ts | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/lib/scriptHost.d.ts b/src/lib/scriptHost.d.ts index bfa562a930..ec5d5cca57 100644 --- a/src/lib/scriptHost.d.ts +++ b/src/lib/scriptHost.d.ts @@ -10,12 +10,28 @@ interface ActiveXObject { } declare var ActiveXObject: ActiveXObject; -interface ITextWriter { - Write(s: string): void; - WriteLine(s: string): void; +interface ITextStreamBase { + Column: number; + Line: number; Close(): void; } +interface ITextWriter extends ITextStreamBase { + Write(s: string): void; + WriteBlankLines(intLines: number): void; + WriteLine(s: string): void; +} + +interface ITextReader extends ITextStreamBase { + Read(characters: number): string; + ReadAll(): string; + ReadLine(): string; + Skip(characters: number): void; + SkipLine(): void; + AtEndOfLine: boolean; + AtEndOfStream: boolean; +} + declare var WScript: { Echo(s: any): void; StdErr: ITextWriter; @@ -23,4 +39,17 @@ declare var WScript: { Arguments: { length: number; Item(n: number): string; }; ScriptFullName: string; Quit(exitCode?: number): number; + BuildVersion: number; + FullName: string; + Interactive: boolean; + Name: string; + Path: string; + ScriptName: string; + StdIn: ITextReader; + Version: string; + ConnectObject(objEventSource: any, strPrefix: string): void; + CreateObject(strProgID: string, strPrefix?: string): any; + DisconnectObject(obj: any): void; + GetObject(strPathname: string, strProgID?: string, strPrefix?: string): any; + Sleep(intTime: number): void; } From 41547dc2f26d5fc6583ff8c9a53cd0541b56338e Mon Sep 17 00:00:00 2001 From: Zev Spitz Date: Tue, 31 Mar 2015 14:09:43 +0300 Subject: [PATCH 25/28] JSDoc for WScript members --- src/lib/scriptHost.d.ts | 111 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/src/lib/scriptHost.d.ts b/src/lib/scriptHost.d.ts index ec5d5cca57..9f7b773b31 100644 --- a/src/lib/scriptHost.d.ts +++ b/src/lib/scriptHost.d.ts @@ -11,45 +11,156 @@ interface ActiveXObject { declare var ActiveXObject: ActiveXObject; interface ITextStreamBase { + /** + * The column number of the current character position in an input stream. + */ Column: number; + /** + * The current line number in an input stream. + */ Line: number; + /** + * Closes a text stream. + * It is not necessary to close standard streams; they close automatically when the process ends. If you close a standard stream, be aware that any other pointers to that standard stream become invalid. + */ Close(): void; } interface ITextWriter extends ITextStreamBase { + /** + * Sends a string to an output stream. + */ Write(s: string): void; + /** + * Sends a specified number of blank lines (newline characters) to an output stream. + */ WriteBlankLines(intLines: number): void; + /** + * Sends a string followed by a newline character to an output stream. + */ WriteLine(s: string): void; } interface ITextReader extends ITextStreamBase { + /** + * Returns a specified number of characters from an input stream, beginning at the current pointer position. + * Does not return until the ENTER key is pressed. + * Can only be used on a stream in reading mode; causes an error in writing or appending mode. + */ Read(characters: number): string; + /** + * Returns all characters from an input stream. + * Can only be used on a stream in reading mode; causes an error in writing or appending mode. + */ ReadAll(): string; + /** + * Returns an entire line from an input stream. + * Although this method extracts the newline character, it does not add it to the returned string. + * Can only be used on a stream in reading mode; causes an error in writing or appending mode. + */ ReadLine(): string; + /** + * Skips a specified number of characters when reading from an input text stream. + * Can only be used on a stream in reading mode; causes an error in writing or appending mode. + * @param characters Positive number of characters to skip forward. (Backward skipping is not supported.) + */ Skip(characters: number): void; + /** + * Skips the next line when reading from an input text stream. + * Can only be used on a stream in reading mode, not writing or appending mode. + */ SkipLine(): void; + /** + * Indicates whether the stream pointer position is at the end of a line. + */ AtEndOfLine: boolean; + /** + * Indicates whether the stream pointer position is at the end of a stream. + */ AtEndOfStream: boolean; } declare var WScript: { + /** + * Outputs text to either a message box (under WScript.exe) or the command console window followed by a newline (under CScript.ext). + */ Echo(s: any): void; + /** + * Exposes the write-only error output stream for the current script. + * Can be accessed only while using CScript.exe. + */ StdErr: ITextWriter; + /** + * Exposes the write-only output stream for the current script. + * Can be accessed only while using CScript.exe. + */ StdOut: ITextWriter; Arguments: { length: number; Item(n: number): string; }; + /** + * The full path of the currently running script. + */ ScriptFullName: string; + /** + * Forces the script to stop immediately, with an optional exit code. + */ Quit(exitCode?: number): number; + /** + * The Windows Script Host build version number. + */ BuildVersion: number; + /** + * Fully qualified path of the host executable. + */ FullName: string; + /** + * Gets/sets the script mode - interactive(true) or batch(false). + */ Interactive: boolean; + /** + * The name of the host executable (WScript.exe or CScript.exe). + */ Name: string; + /** + * Path of the directory containing the host executable. + */ Path: string; + /** + * The filename of the currently running script. + */ ScriptName: string; + /** + * Exposes the read-only input stream for the current script. + * Can be accessed only while using CScript.exe. + */ StdIn: ITextReader; + /** + * Windows Script Host version + */ Version: string; + /** + * Connects a COM object's event sources to functions named with a given prefix, in the form prefix_event. + */ ConnectObject(objEventSource: any, strPrefix: string): void; + /** + * Creates a COM object. + * @param strProgiID + * @param strPrefix Function names in the form prefix_event will be bound to this object's COM events. + */ CreateObject(strProgID: string, strPrefix?: string): any; + /** + * Disconnects a COM object from its event sources. + */ DisconnectObject(obj: any): void; + /** + * Retrieves an existing object with the specified ProgID from memory, or creates a new one from a file. + * @param strPathname Fully qualified path to the file containing the object persisted to disk. For objects in memory, pass a zero-length string. + * @param strProgID + * @param strPrefix Function names in the form prefix_event will be bound to this object's COM events. + */ GetObject(strPathname: string, strProgID?: string, strPrefix?: string): any; + /** + * Suspends script execution for a specified length of time, then continues execution. + * @param intTime Interval (in milliseconds) to suspend script execution. + */ Sleep(intTime: number): void; } From b06e19bee86bd1049c92ed1bf8cae30e14c24766 Mon Sep 17 00:00:00 2001 From: Zev Spitz Date: Tue, 31 Mar 2015 14:43:10 +0300 Subject: [PATCH 26/28] Missing ; --- src/lib/scriptHost.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/scriptHost.d.ts b/src/lib/scriptHost.d.ts index 9f7b773b31..eaf3cfc2d9 100644 --- a/src/lib/scriptHost.d.ts +++ b/src/lib/scriptHost.d.ts @@ -82,8 +82,8 @@ interface ITextReader extends ITextStreamBase { declare var WScript: { /** - * Outputs text to either a message box (under WScript.exe) or the command console window followed by a newline (under CScript.ext). - */ + * Outputs text to either a message box (under WScript.exe) or the command console window followed by a newline (under CScript.ext). + */ Echo(s: any): void; /** * Exposes the write-only error output stream for the current script. @@ -163,4 +163,4 @@ declare var WScript: { * @param intTime Interval (in milliseconds) to suspend script execution. */ Sleep(intTime: number): void; -} +}; From 7890a6894c5ada8ac3582538748d4f53c7804d2b Mon Sep 17 00:00:00 2001 From: Zev Spitz Date: Tue, 31 Mar 2015 16:56:30 +0300 Subject: [PATCH 27/28] Nre TextStreamWriter interface with JSDoc and additional members (ITextWriter is being used by the compiler and cannot be safely modified).. --- src/lib/scriptHost.d.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/lib/scriptHost.d.ts b/src/lib/scriptHost.d.ts index eaf3cfc2d9..decf813bc2 100644 --- a/src/lib/scriptHost.d.ts +++ b/src/lib/scriptHost.d.ts @@ -10,7 +10,13 @@ interface ActiveXObject { } declare var ActiveXObject: ActiveXObject; -interface ITextStreamBase { +interface ITextWriter { + Write(s: string): void; + WriteLine(s: string): void; + Close(): void; +} + +interface TextStreamBase { /** * The column number of the current character position in an input stream. */ @@ -26,7 +32,7 @@ interface ITextStreamBase { Close(): void; } -interface ITextWriter extends ITextStreamBase { +interface TextStreamWriter extends TextStreamBase { /** * Sends a string to an output stream. */ @@ -41,7 +47,7 @@ interface ITextWriter extends ITextStreamBase { WriteLine(s: string): void; } -interface ITextReader extends ITextStreamBase { +interface TextStreamReader extends TextStreamBase { /** * Returns a specified number of characters from an input stream, beginning at the current pointer position. * Does not return until the ENTER key is pressed. @@ -89,12 +95,12 @@ declare var WScript: { * Exposes the write-only error output stream for the current script. * Can be accessed only while using CScript.exe. */ - StdErr: ITextWriter; + StdErr: TextStreamWriter; /** * Exposes the write-only output stream for the current script. * Can be accessed only while using CScript.exe. */ - StdOut: ITextWriter; + StdOut: TextStreamWriter; Arguments: { length: number; Item(n: number): string; }; /** * The full path of the currently running script. @@ -132,7 +138,7 @@ declare var WScript: { * Exposes the read-only input stream for the current script. * Can be accessed only while using CScript.exe. */ - StdIn: ITextReader; + StdIn: TextStreamReader; /** * Windows Script Host version */ From 1bdcaa3d43db6a44bed574f93de3d422bb47bf04 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 31 Mar 2015 13:54:33 -0700 Subject: [PATCH 28/28] added tests for import\export elision --- ...eCompilationImportExportElision.errors.txt | 28 ++++++++++++++ .../separateCompilationImportExportElision.js | 37 +++++++++++++++++++ .../separateCompilationImportExportElision.ts | 17 +++++++++ 3 files changed, 82 insertions(+) create mode 100644 tests/baselines/reference/separateCompilationImportExportElision.errors.txt create mode 100644 tests/baselines/reference/separateCompilationImportExportElision.js create mode 100644 tests/cases/compiler/separateCompilationImportExportElision.ts diff --git a/tests/baselines/reference/separateCompilationImportExportElision.errors.txt b/tests/baselines/reference/separateCompilationImportExportElision.errors.txt new file mode 100644 index 0000000000..db418681e8 --- /dev/null +++ b/tests/baselines/reference/separateCompilationImportExportElision.errors.txt @@ -0,0 +1,28 @@ +tests/cases/compiler/separateCompilationImportExportElision.ts(2,17): error TS2307: Cannot find external module 'module'. +tests/cases/compiler/separateCompilationImportExportElision.ts(3,18): error TS2307: Cannot find external module 'module'. +tests/cases/compiler/separateCompilationImportExportElision.ts(4,21): error TS2307: Cannot find external module 'module'. +tests/cases/compiler/separateCompilationImportExportElision.ts(12,18): error TS2307: Cannot find external module 'module'. + + +==== tests/cases/compiler/separateCompilationImportExportElision.ts (4 errors) ==== + + import {c} from "module" + ~~~~~~~~ +!!! error TS2307: Cannot find external module 'module'. + import {c2} from "module" + ~~~~~~~~ +!!! error TS2307: Cannot find external module 'module'. + import * as ns from "module" + ~~~~~~~~ +!!! error TS2307: Cannot find external module 'module'. + + class C extends c2.C { + } + + let x = new c(); + let y = ns.value; + + export {c1} from "module"; + ~~~~~~~~ +!!! error TS2307: Cannot find external module 'module'. + export var z = x; \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationImportExportElision.js b/tests/baselines/reference/separateCompilationImportExportElision.js new file mode 100644 index 0000000000..2d255798c3 --- /dev/null +++ b/tests/baselines/reference/separateCompilationImportExportElision.js @@ -0,0 +1,37 @@ +//// [separateCompilationImportExportElision.ts] + +import {c} from "module" +import {c2} from "module" +import * as ns from "module" + +class C extends c2.C { +} + +let x = new c(); +let y = ns.value; + +export {c1} from "module"; +export var z = x; + +//// [separateCompilationImportExportElision.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var module_1 = require("module"); +var module_2 = require("module"); +var ns = require("module"); +var C = (function (_super) { + __extends(C, _super); + function C() { + _super.apply(this, arguments); + } + return C; +})(module_2.c2.C); +var x = new module_1.c(); +var y = ns.value; +var module_3 = require("module"); +exports.c1 = module_3.c1; +exports.z = x; diff --git a/tests/cases/compiler/separateCompilationImportExportElision.ts b/tests/cases/compiler/separateCompilationImportExportElision.ts new file mode 100644 index 0000000000..d7af74a1a6 --- /dev/null +++ b/tests/cases/compiler/separateCompilationImportExportElision.ts @@ -0,0 +1,17 @@ +// @separateCompilation: true +// @target: es5 +// @module: commonjs + +// @filename: file1.ts +import {c} from "module" +import {c2} from "module" +import * as ns from "module" + +class C extends c2.C { +} + +let x = new c(); +let y = ns.value; + +export {c1} from "module"; +export var z = x; \ No newline at end of file