merge with destructuringDts

This commit is contained in:
Vladimir Matveev
2015-02-25 00:01:15 -08:00
35 changed files with 978 additions and 20 deletions
+8 -1
View File
@@ -1662,8 +1662,15 @@ module ts {
function isDeclarationVisible(node: Declaration): boolean {
function determineIfDeclarationIsVisible() {
switch (node.kind) {
case SyntaxKind.VariableDeclaration:
case SyntaxKind.BindingElement:
return isDeclarationVisible(<Declaration>node.parent.parent);
case SyntaxKind.VariableDeclaration:
if (isBindingPattern(node.name) &&
!(<BindingPattern>node.name).elements.length) {
// If the binding pattern is empty, this variable declaration is not visible
return false;
}
// Otherwise fall through
case SyntaxKind.ModuleDeclaration:
case SyntaxKind.ClassDeclaration:
case SyntaxKind.InterfaceDeclaration:
+59 -19
View File
@@ -1217,25 +1217,33 @@ module ts {
}
function emitVariableDeclaration(node: VariableDeclaration) {
// If this node is a computed name, it can only be a symbol, because we've already skipped
// it if it's not a well known symbol. In that case, the text of the name will be exactly
// what we want, namely the name expression enclosed in brackets.
writeTextOfNode(currentSourceFile, node.name);
// If optional property emit ?
if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && hasQuestionToken(node)) {
write("?");
}
if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) {
emitTypeOfVariableDeclarationFromTypeLiteral(node);
}
else if (!(node.flags & NodeFlags.Private)) {
writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError);
// If we are emitting property it isn't moduleElement and hence we already know it needs to be emitted
// so there is no check needed to see if declaration is visible
if (node.kind !== SyntaxKind.VariableDeclaration || resolver.isDeclarationVisible(node)) {
if (isBindingPattern(node.name)) {
emitBindingPattern(<BindingPattern>node.name);
}
else {
// If this node is a computed name, it can only be a symbol, because we've already skipped
// it if it's not a well known symbol. In that case, the text of the name will be exactly
// what we want, namely the name expression enclosed in brackets.
writeTextOfNode(currentSourceFile, node.name);
// If optional property emit ?
if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && hasQuestionToken(node)) {
write("?");
}
if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) {
emitTypeOfVariableDeclarationFromTypeLiteral(node);
}
else if (!(node.flags & NodeFlags.Private)) {
writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError);
}
}
}
function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
var diagnosticMessage: DiagnosticMessage;
function getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult: SymbolAccessiblityResult) {
if (node.kind === SyntaxKind.VariableDeclaration) {
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
return symbolAccesibilityResult.errorModuleName ?
symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 :
@@ -1245,14 +1253,14 @@ module ts {
else if (node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) {
// TODO(jfreeman): Deal with computed properties in error reporting.
if (node.flags & NodeFlags.Static) {
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
return symbolAccesibilityResult.errorModuleName ?
symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1;
}
else if (node.parent.kind === SyntaxKind.ClassDeclaration) {
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
return symbolAccesibilityResult.errorModuleName ?
symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
@@ -1260,18 +1268,46 @@ module ts {
}
else {
// Interfaces cannot have types that cannot be named
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
return symbolAccesibilityResult.errorModuleName ?
Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 :
Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1;
}
}
}
function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
var diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult);
return diagnosticMessage !== undefined ? {
diagnosticMessage,
errorNode: node,
typeName: node.name
} : undefined;
}
function emitBindingPattern(bindingPattern: BindingPattern) {
emitCommaList(bindingPattern.elements, emitBindingElement);
}
function emitBindingElement(bindingElement: BindingElement) {
function getBindingElementTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
var diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult);
return diagnosticMessage !== undefined ? {
diagnosticMessage,
errorNode: bindingElement,
typeName: bindingElement.name
} : undefined;
}
if (bindingElement.name) {
if (isBindingPattern(bindingElement.name)) {
emitBindingPattern(<BindingPattern>bindingElement.name);
}
else {
writeTextOfNode(currentSourceFile, bindingElement.name);
writeTypeOfDeclaration(bindingElement, /*type*/ undefined, getBindingElementTypeVisibilityError);
}
}
}
}
function emitTypeOfVariableDeclarationFromTypeLiteral(node: VariableLikeDeclaration) {
@@ -3869,6 +3905,10 @@ module ts {
}
function emitExportVariableAssignments(node: VariableDeclaration | BindingElement) {
if (node.kind === SyntaxKind.OmittedExpression) {
return;
}
var name = (<VariableLikeDeclaration>node).name;
if (name.kind === SyntaxKind.Identifier) {
emitExportMemberAssignments(<Identifier>name);
@@ -0,0 +1,28 @@
//// [declarationEmitDestructuringArrayPattern1.ts]
var [] = [1, "hello"]; // Dont emit anything
var [x] = [1, "hello"]; // emit x: number
var [x1, y1] = [1, "hello"]; // emit x1: number, y1: string
var [, , z1] = [0, 1, 2]; // emit z1: number
var a = [1, "hello"];
var [x2] = a; // emit x2: number | string
var [x3, y3, z3] = a; // emit x3, y3, z3
//// [declarationEmitDestructuringArrayPattern1.js]
var _a = [1, "hello"]; // Dont emit anything
var x = ([1, "hello"])[0]; // emit x: number
var _b = [1, "hello"], x1 = _b[0], y1 = _b[1]; // emit x1: number, y1: string
var _c = [0, 1, 2], z1 = _c[2]; // emit z1: number
var a = [1, "hello"];
var x2 = a[0]; // emit x2: number | string
var x3 = a[0], y3 = a[1], z3 = a[2]; // emit x3, y3, z3
//// [declarationEmitDestructuringArrayPattern1.d.ts]
declare var x: number;
declare var x1: number, y1: string;
declare var z1: number;
declare var a: (string | number)[];
declare var x2: string | number;
declare var x3: string | number, y3: string | number, z3: string | number;
@@ -0,0 +1,32 @@
=== tests/cases/compiler/declarationEmitDestructuringArrayPattern1.ts ===
var [] = [1, "hello"]; // Dont emit anything
>[1, "hello"] : (string | number)[]
var [x] = [1, "hello"]; // emit x: number
>x : number
>[1, "hello"] : [number, string]
var [x1, y1] = [1, "hello"]; // emit x1: number, y1: string
>x1 : number
>y1 : string
>[1, "hello"] : [number, string]
var [, , z1] = [0, 1, 2]; // emit z1: number
>z1 : number
>[0, 1, 2] : [number, number, number]
var a = [1, "hello"];
>a : (string | number)[]
>[1, "hello"] : (string | number)[]
var [x2] = a; // emit x2: number | string
>x2 : string | number
>a : (string | number)[]
var [x3, y3, z3] = a; // emit x3, y3, z3
>x3 : string | number
>y3 : string | number
>z3 : string | number
>a : (string | number)[]
@@ -0,0 +1,31 @@
//// [declarationEmitDestructuringArrayPattern2.ts]
var [x10, [y10, [z10]]] = [1, ["hello", [true]]];
var [x11 = 0, y11 = ""] = [1, "hello"];
var [a11, b11, c11] = [];
var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]];
var [x13, y13] = [1, "hello"];
var [a3, b3] = [[x13, y13], { x: x13, y: y13 }];
//// [declarationEmitDestructuringArrayPattern2.js]
var _a = [1, ["hello", [true]]], x10 = _a[0], _b = _a[1], y10 = _b[0], z10 = _b[1][0];
var _c = [1, "hello"], _d = _c[0], x11 = _d === void 0 ? 0 : _d, _e = _c[1], y11 = _e === void 0 ? "" : _e;
var _f = [], a11 = _f[0], b11 = _f[1], c11 = _f[2];
var _g = [1, ["hello", { x12: 5, y12: true }]], a2 = _g[0], _h = _g[1], _j = _h === void 0 ? ["abc", { x12: 10, y12: false }] : _h, b2 = _j[0], _k = _j[1], x12 = _k.x12, c2 = _k.y12;
var _l = [1, "hello"], x13 = _l[0], y13 = _l[1];
var _m = [[x13, y13], { x: x13, y: y13 }], a3 = _m[0], b3 = _m[1];
//// [declarationEmitDestructuringArrayPattern2.d.ts]
declare var x10: number, y10: string, z10: boolean;
declare var x11: number, y11: string;
declare var a11: any, b11: any, c11: any;
declare var a2: number, b2: string, x12: number, c2: boolean;
declare var x13: number, y13: string;
declare var a3: (string | number)[], b3: {
x: number;
y: string;
};
@@ -0,0 +1,54 @@
=== tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts ===
var [x10, [y10, [z10]]] = [1, ["hello", [true]]];
>x10 : number
>y10 : string
>z10 : boolean
>[1, ["hello", [true]]] : [number, [string, [boolean]]]
>["hello", [true]] : [string, [boolean]]
>[true] : [boolean]
var [x11 = 0, y11 = ""] = [1, "hello"];
>x11 : number
>y11 : string
>[1, "hello"] : [number, string]
var [a11, b11, c11] = [];
>a11 : any
>b11 : any
>c11 : any
>[] : undefined[]
var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]];
>a2 : number
>b2 : string
>x12 : number
>y12 : unknown
>c2 : boolean
>["abc", { x12: 10, y12: false }] : [string, { x12: number; y12: boolean; }]
>{ x12: 10, y12: false } : { x12: number; y12: boolean; }
>x12 : number
>y12 : boolean
>[1, ["hello", { x12: 5, y12: true }]] : [number, [string, { x12: number; y12: boolean; }]]
>["hello", { x12: 5, y12: true }] : [string, { x12: number; y12: boolean; }]
>{ x12: 5, y12: true } : { x12: number; y12: boolean; }
>x12 : number
>y12 : boolean
var [x13, y13] = [1, "hello"];
>x13 : number
>y13 : string
>[1, "hello"] : [number, string]
var [a3, b3] = [[x13, y13], { x: x13, y: y13 }];
>a3 : (string | number)[]
>b3 : { x: number; y: string; }
>[[x13, y13], { x: x13, y: y13 }] : [(string | number)[], { x: number; y: string; }]
>[x13, y13] : (string | number)[]
>x13 : number
>y13 : string
>{ x: x13, y: y13 } : { x: number; y: string; }
>x : number
>x13 : number
>y : string
>y13 : string
@@ -0,0 +1,17 @@
//// [declarationEmitDestructuringArrayPattern3.ts]
module M {
export var [a, b] = [1, 2];
}
//// [declarationEmitDestructuringArrayPattern3.js]
var M;
(function (M) {
_a = [1, 2], M.a = _a[0], M.b = _a[1];
var _a;
})(M || (M = {}));
//// [declarationEmitDestructuringArrayPattern3.d.ts]
declare module M {
var a: number, b: number;
}
@@ -0,0 +1,9 @@
=== tests/cases/compiler/declarationEmitDestructuringArrayPattern3.ts ===
module M {
>M : typeof M
export var [a, b] = [1, 2];
>a : number
>b : number
>[1, 2] : [number, number]
}
@@ -0,0 +1,31 @@
//// [declarationEmitDestructuringArrayPattern4.ts]
var [...a5] = [1, 2, 3];
var [x14, ...a6] = [1, 2, 3];
var [x15, y15, ...a7] = [1, 2, 3];
var [x16, y16, z16, ...a8] = [1, 2, 3];
var [...a9] = [1, "hello", true];
var [x17, ...a10] = [1, "hello", true];
var [x18, y18, ...a12] = [1, "hello", true];
var [x19, y19, z19, ...a13] = [1, "hello", true];
//// [declarationEmitDestructuringArrayPattern4.js]
var _a = [1, 2, 3], a5 = _a.slice(0);
var _b = [1, 2, 3], x14 = _b[0], a6 = _b.slice(1);
var _c = [1, 2, 3], x15 = _c[0], y15 = _c[1], a7 = _c.slice(2);
var _d = [1, 2, 3], x16 = _d[0], y16 = _d[1], z16 = _d[2], a8 = _d.slice(3);
var _e = [1, "hello", true], a9 = _e.slice(0);
var _f = [1, "hello", true], x17 = _f[0], a10 = _f.slice(1);
var _g = [1, "hello", true], x18 = _g[0], y18 = _g[1], a12 = _g.slice(2);
var _h = [1, "hello", true], x19 = _h[0], y19 = _h[1], z19 = _h[2], a13 = _h.slice(3);
//// [declarationEmitDestructuringArrayPattern4.d.ts]
declare var a5: number[];
declare var x14: number, a6: number[];
declare var x15: number, y15: number, a7: number[];
declare var x16: number, y16: number, z16: number, a8: number[];
declare var a9: (string | number | boolean)[];
declare var x17: string | number | boolean, a10: (string | number | boolean)[];
declare var x18: string | number | boolean, y18: string | number | boolean, a12: (string | number | boolean)[];
declare var x19: string | number | boolean, y19: string | number | boolean, z19: string | number | boolean, a13: (string | number | boolean)[];
@@ -0,0 +1,45 @@
=== tests/cases/compiler/declarationEmitDestructuringArrayPattern4.ts ===
var [...a5] = [1, 2, 3];
>a5 : number[]
>[1, 2, 3] : number[]
var [x14, ...a6] = [1, 2, 3];
>x14 : number
>a6 : number[]
>[1, 2, 3] : number[]
var [x15, y15, ...a7] = [1, 2, 3];
>x15 : number
>y15 : number
>a7 : number[]
>[1, 2, 3] : number[]
var [x16, y16, z16, ...a8] = [1, 2, 3];
>x16 : number
>y16 : number
>z16 : number
>a8 : number[]
>[1, 2, 3] : number[]
var [...a9] = [1, "hello", true];
>a9 : (string | number | boolean)[]
>[1, "hello", true] : (string | number | boolean)[]
var [x17, ...a10] = [1, "hello", true];
>x17 : string | number | boolean
>a10 : (string | number | boolean)[]
>[1, "hello", true] : (string | number | boolean)[]
var [x18, y18, ...a12] = [1, "hello", true];
>x18 : string | number | boolean
>y18 : string | number | boolean
>a12 : (string | number | boolean)[]
>[1, "hello", true] : (string | number | boolean)[]
var [x19, y19, z19, ...a13] = [1, "hello", true];
>x19 : string | number | boolean
>y19 : string | number | boolean
>z19 : string | number | boolean
>a13 : (string | number | boolean)[]
>[1, "hello", true] : (string | number | boolean)[]
@@ -0,0 +1,64 @@
//// [declarationEmitDestructuringObjectLiteralPattern.ts]
var { } = { x: 5, y: "hello" };
var { x4 } = { x4: 5, y4: "hello" };
var { y5 } = { x5: 5, y5: "hello" };
var { x6, y6 } = { x6: 5, y6: "hello" };
var { x7: a1 } = { x7: 5, y7: "hello" };
var { y8: b1 } = { x8: 5, y8: "hello" };
var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" };
var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } };
function f15() {
var a4 = "hello";
var b4 = 1;
var c4 = true;
return { a4, b4, c4 };
}
var { a4, b4, c4 } = f15();
module m {
export var { a4, b4, c4 } = f15();
}
//// [declarationEmitDestructuringObjectLiteralPattern.js]
var _a = { x: 5, y: "hello" };
var x4 = ({ x4: 5, y4: "hello" }).x4;
var y5 = ({ x5: 5, y5: "hello" }).y5;
var _b = { x6: 5, y6: "hello" }, x6 = _b.x6, y6 = _b.y6;
var a1 = ({ x7: 5, y7: "hello" }).x7;
var b1 = ({ x8: 5, y8: "hello" }).y8;
var _c = { x9: 5, y9: "hello" }, a2 = _c.x9, b2 = _c.y9;
var _d = { a: 1, b: { a: "hello", b: { a: true } } }, x11 = _d.a, _e = _d.b, y11 = _e.a, z11 = _e.b.a;
function f15() {
var a4 = "hello";
var b4 = 1;
var c4 = true;
return { a4: a4, b4: b4, c4: c4 };
}
var _f = f15(), a4 = _f.a4, b4 = _f.b4, c4 = _f.c4;
var m;
(function (m) {
_a = f15(), m.a4 = _a.a4, m.b4 = _a.b4, m.c4 = _a.c4;
var _a;
})(m || (m = {}));
//// [declarationEmitDestructuringObjectLiteralPattern.d.ts]
declare var x4: number;
declare var y5: string;
declare var x6: number, y6: string;
declare var a1: number;
declare var b1: string;
declare var a2: number, b2: string;
declare var x11: number, y11: string, z11: boolean;
declare function f15(): {
a4: string;
b4: number;
c4: boolean;
};
declare var a4: string, b4: number, c4: boolean;
declare module m {
var a4: string, b4: number, c4: boolean;
}
@@ -0,0 +1,102 @@
=== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts ===
var { } = { x: 5, y: "hello" };
>{ x: 5, y: "hello" } : { x: number; y: string; }
>x : number
>y : string
var { x4 } = { x4: 5, y4: "hello" };
>x4 : number
>{ x4: 5, y4: "hello" } : { x4: number; y4: string; }
>x4 : number
>y4 : string
var { y5 } = { x5: 5, y5: "hello" };
>y5 : string
>{ x5: 5, y5: "hello" } : { x5: number; y5: string; }
>x5 : number
>y5 : string
var { x6, y6 } = { x6: 5, y6: "hello" };
>x6 : number
>y6 : string
>{ x6: 5, y6: "hello" } : { x6: number; y6: string; }
>x6 : number
>y6 : string
var { x7: a1 } = { x7: 5, y7: "hello" };
>x7 : unknown
>a1 : number
>{ x7: 5, y7: "hello" } : { x7: number; y7: string; }
>x7 : number
>y7 : string
var { y8: b1 } = { x8: 5, y8: "hello" };
>y8 : unknown
>b1 : string
>{ x8: 5, y8: "hello" } : { x8: number; y8: string; }
>x8 : number
>y8 : string
var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" };
>x9 : unknown
>a2 : number
>y9 : unknown
>b2 : string
>{ x9: 5, y9: "hello" } : { x9: number; y9: string; }
>x9 : number
>y9 : string
var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } };
>a : unknown
>x11 : number
>b : unknown
>a : unknown
>y11 : string
>b : unknown
>a : unknown
>z11 : boolean
>{ a: 1, b: { a: "hello", b: { a: true } } } : { a: number; b: { a: string; b: { a: boolean; }; }; }
>a : number
>b : { a: string; b: { a: boolean; }; }
>{ a: "hello", b: { a: true } } : { a: string; b: { a: boolean; }; }
>a : string
>b : { a: boolean; }
>{ a: true } : { a: boolean; }
>a : boolean
function f15() {
>f15 : () => { a4: string; b4: number; c4: boolean; }
var a4 = "hello";
>a4 : string
var b4 = 1;
>b4 : number
var c4 = true;
>c4 : boolean
return { a4, b4, c4 };
>{ a4, b4, c4 } : { a4: string; b4: number; c4: boolean; }
>a4 : string
>b4 : number
>c4 : boolean
}
var { a4, b4, c4 } = f15();
>a4 : string
>b4 : number
>c4 : boolean
>f15() : { a4: string; b4: number; c4: boolean; }
>f15 : () => { a4: string; b4: number; c4: boolean; }
module m {
>m : typeof m
export var { a4, b4, c4 } = f15();
>a4 : string
>b4 : number
>c4 : boolean
>f15() : { a4: string; b4: number; c4: boolean; }
>f15 : () => { a4: string; b4: number; c4: boolean; }
}
@@ -0,0 +1,27 @@
//// [declarationEmitDestructuringObjectLiteralPattern1.ts]
var { } = { x: 5, y: "hello" };
var { x4 } = { x4: 5, y4: "hello" };
var { y5 } = { x5: 5, y5: "hello" };
var { x6, y6 } = { x6: 5, y6: "hello" };
var { x7: a1 } = { x7: 5, y7: "hello" };
var { y8: b1 } = { x8: 5, y8: "hello" };
var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" };
//// [declarationEmitDestructuringObjectLiteralPattern1.js]
var _a = { x: 5, y: "hello" };
var x4 = ({ x4: 5, y4: "hello" }).x4;
var y5 = ({ x5: 5, y5: "hello" }).y5;
var _b = { x6: 5, y6: "hello" }, x6 = _b.x6, y6 = _b.y6;
var a1 = ({ x7: 5, y7: "hello" }).x7;
var b1 = ({ x8: 5, y8: "hello" }).y8;
var _c = { x9: 5, y9: "hello" }, a2 = _c.x9, b2 = _c.y9;
//// [declarationEmitDestructuringObjectLiteralPattern1.d.ts]
declare var x4: number;
declare var y5: string;
declare var x6: number, y6: string;
declare var a1: number;
declare var b1: string;
declare var a2: number, b2: string;
@@ -0,0 +1,49 @@
=== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts ===
var { } = { x: 5, y: "hello" };
>{ x: 5, y: "hello" } : { x: number; y: string; }
>x : number
>y : string
var { x4 } = { x4: 5, y4: "hello" };
>x4 : number
>{ x4: 5, y4: "hello" } : { x4: number; y4: string; }
>x4 : number
>y4 : string
var { y5 } = { x5: 5, y5: "hello" };
>y5 : string
>{ x5: 5, y5: "hello" } : { x5: number; y5: string; }
>x5 : number
>y5 : string
var { x6, y6 } = { x6: 5, y6: "hello" };
>x6 : number
>y6 : string
>{ x6: 5, y6: "hello" } : { x6: number; y6: string; }
>x6 : number
>y6 : string
var { x7: a1 } = { x7: 5, y7: "hello" };
>x7 : unknown
>a1 : number
>{ x7: 5, y7: "hello" } : { x7: number; y7: string; }
>x7 : number
>y7 : string
var { y8: b1 } = { x8: 5, y8: "hello" };
>y8 : unknown
>b1 : string
>{ x8: 5, y8: "hello" } : { x8: number; y8: string; }
>x8 : number
>y8 : string
var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" };
>x9 : unknown
>a2 : number
>y9 : unknown
>b2 : string
>{ x9: 5, y9: "hello" } : { x9: number; y9: string; }
>x9 : number
>y9 : string
@@ -0,0 +1,43 @@
//// [declarationEmitDestructuringObjectLiteralPattern2.ts]
var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } };
function f15() {
var a4 = "hello";
var b4 = 1;
var c4 = true;
return { a4, b4, c4 };
}
var { a4, b4, c4 } = f15();
module m {
export var { a4, b4, c4 } = f15();
}
//// [declarationEmitDestructuringObjectLiteralPattern2.js]
var _a = { a: 1, b: { a: "hello", b: { a: true } } }, x11 = _a.a, _b = _a.b, y11 = _b.a, z11 = _b.b.a;
function f15() {
var a4 = "hello";
var b4 = 1;
var c4 = true;
return { a4: a4, b4: b4, c4: c4 };
}
var _c = f15(), a4 = _c.a4, b4 = _c.b4, c4 = _c.c4;
var m;
(function (m) {
_a = f15(), m.a4 = _a.a4, m.b4 = _a.b4, m.c4 = _a.c4;
var _a;
})(m || (m = {}));
//// [declarationEmitDestructuringObjectLiteralPattern2.d.ts]
declare var x11: number, y11: string, z11: boolean;
declare function f15(): {
a4: string;
b4: number;
c4: boolean;
};
declare var a4: string, b4: number, c4: boolean;
declare module m {
var a4: string, b4: number, c4: boolean;
}
@@ -0,0 +1,55 @@
=== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern2.ts ===
var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } };
>a : unknown
>x11 : number
>b : unknown
>a : unknown
>y11 : string
>b : unknown
>a : unknown
>z11 : boolean
>{ a: 1, b: { a: "hello", b: { a: true } } } : { a: number; b: { a: string; b: { a: boolean; }; }; }
>a : number
>b : { a: string; b: { a: boolean; }; }
>{ a: "hello", b: { a: true } } : { a: string; b: { a: boolean; }; }
>a : string
>b : { a: boolean; }
>{ a: true } : { a: boolean; }
>a : boolean
function f15() {
>f15 : () => { a4: string; b4: number; c4: boolean; }
var a4 = "hello";
>a4 : string
var b4 = 1;
>b4 : number
var c4 = true;
>c4 : boolean
return { a4, b4, c4 };
>{ a4, b4, c4 } : { a4: string; b4: number; c4: boolean; }
>a4 : string
>b4 : number
>c4 : boolean
}
var { a4, b4, c4 } = f15();
>a4 : string
>b4 : number
>c4 : boolean
>f15() : { a4: string; b4: number; c4: boolean; }
>f15 : () => { a4: string; b4: number; c4: boolean; }
module m {
>m : typeof m
export var { a4, b4, c4 } = f15();
>a4 : string
>b4 : number
>c4 : boolean
>f15() : { a4: string; b4: number; c4: boolean; }
>f15 : () => { a4: string; b4: number; c4: boolean; }
}
@@ -0,0 +1,25 @@
//// [declarationEmitDestructuringOptionalBindingParametersInOverloads.ts]
function foo([x, y, z] ?: [string, number, boolean]);
function foo(...rest: any[]) {
}
function foo2( { x, y, z }?: { x: string; y: number; z: boolean });
function foo2(...rest: any[]) {
}
//// [declarationEmitDestructuringOptionalBindingParametersInOverloads.js]
function foo() {
}
function foo2() {
}
//// [declarationEmitDestructuringOptionalBindingParametersInOverloads.d.ts]
declare function foo(_0?: [string, number, boolean]): any;
declare function foo2(_0?: {
x: string;
y: number;
z: boolean;
}): any;
@@ -0,0 +1,27 @@
=== tests/cases/compiler/declarationEmitDestructuringOptionalBindingParametersInOverloads.ts ===
function foo([x, y, z] ?: [string, number, boolean]);
>foo : ([x, y, z]?: [string, number, boolean]) => any
>x : string
>y : number
>z : boolean
function foo(...rest: any[]) {
>foo : ([x, y, z]?: [string, number, boolean]) => any
>rest : any[]
}
function foo2( { x, y, z }?: { x: string; y: number; z: boolean });
>foo2 : ({ x, y, z }?: { x: string; y: number; z: boolean; }) => any
>x : string
>y : number
>z : boolean
>x : string
>y : number
>z : boolean
function foo2(...rest: any[]) {
>foo2 : ({ x, y, z }?: { x: string; y: number; z: boolean; }) => any
>rest : any[]
}
@@ -0,0 +1,28 @@
tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(2,17): error TS1187: A parameter property may not be a binding pattern.
tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(8,17): error TS1187: A parameter property may not be a binding pattern.
tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(14,17): error TS1187: A parameter property may not be a binding pattern.
==== tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts (3 errors) ====
class C1 {
constructor(public [x, y, z]: string[]) {
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1187: A parameter property may not be a binding pattern.
}
}
type TupleType1 =[string, number, boolean];
class C2 {
constructor(public [x, y, z]: TupleType1) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1187: A parameter property may not be a binding pattern.
}
}
type ObjType1 = { x: number; y: string; z: boolean }
class C3 {
constructor(public { x, y, z }: ObjType1) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1187: A parameter property may not be a binding pattern.
}
}
@@ -0,0 +1,61 @@
//// [declarationEmitDestructuringParameterProperties.ts]
class C1 {
constructor(public [x, y, z]: string[]) {
}
}
type TupleType1 =[string, number, boolean];
class C2 {
constructor(public [x, y, z]: TupleType1) {
}
}
type ObjType1 = { x: number; y: string; z: boolean }
class C3 {
constructor(public { x, y, z }: ObjType1) {
}
}
//// [declarationEmitDestructuringParameterProperties.js]
var C1 = (function () {
function C1(_a) {
var x = _a[0], y = _a[1], z = _a[2];
this.[x, y, z] = [x, y, z];
}
return C1;
})();
var C2 = (function () {
function C2(_a) {
var x = _a[0], y = _a[1], z = _a[2];
this.[x, y, z] = [x, y, z];
}
return C2;
})();
var C3 = (function () {
function C3(_a) {
var x = _a.x, y = _a.y, z = _a.z;
this.{ x, y, z } = { x, y, z };
}
return C3;
})();
//// [declarationEmitDestructuringParameterProperties.d.ts]
declare class C1 {
x: string, y: string, z: string;
constructor(_0: string[]);
}
declare type TupleType1 = [string, number, boolean];
declare class C2 {
x: string, y: number, z: boolean;
constructor(_0: TupleType1);
}
declare type ObjType1 = {
x: number;
y: string;
z: boolean;
};
declare class C3 {
x: number, y: string, z: boolean;
constructor(_0: ObjType1);
}
@@ -0,0 +1,11 @@
tests/cases/compiler/declarationEmitDestructuringPrivacyError.ts(4,20): error TS4025: Exported variable 'y' has or is using private name 'c'.
==== tests/cases/compiler/declarationEmitDestructuringPrivacyError.ts (1 errors) ====
module m {
class c {
}
export var [x, y, z] = [10, new c(), 30];
~
!!! error TS4025: Exported variable 'y' has or is using private name 'c'.
}
@@ -0,0 +1,18 @@
//// [declarationEmitDestructuringPrivacyError.ts]
module m {
class c {
}
export var [x, y, z] = [10, new c(), 30];
}
//// [declarationEmitDestructuringPrivacyError.js]
var m;
(function (m) {
var c = (function () {
function c() {
}
return c;
})();
_a = [10, new c(), 30], m.x = _a[0], m.y = _a[1], m.z = _a[2];
var _a;
})(m || (m = {}));
@@ -0,0 +1,13 @@
tests/cases/compiler/declarationEmitDestructuringWithOptionalBindingParameters.ts(1,14): error TS2463: A binding pattern parameter cannot be optional in an implementation signature.
tests/cases/compiler/declarationEmitDestructuringWithOptionalBindingParameters.ts(3,16): error TS2463: A binding pattern parameter cannot be optional in an implementation signature.
==== tests/cases/compiler/declarationEmitDestructuringWithOptionalBindingParameters.ts (2 errors) ====
function foo([x,y,z]?: [string, number, boolean]) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature.
}
function foo1( { x, y, z }?: { x: string; y: number; z: boolean }) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature.
}
@@ -0,0 +1,22 @@
//// [declarationEmitDestructuringWithOptionalBindingParameters.ts]
function foo([x,y,z]?: [string, number, boolean]) {
}
function foo1( { x, y, z }?: { x: string; y: number; z: boolean }) {
}
//// [declarationEmitDestructuringWithOptionalBindingParameters.js]
function foo(_a) {
var x = _a[0], y = _a[1], z = _a[2];
}
function foo1(_a) {
var x = _a.x, y = _a.y, z = _a.z;
}
//// [declarationEmitDestructuringWithOptionalBindingParameters.d.ts]
declare function foo(_0?: [string, number, boolean]): void;
declare function foo1(_0?: {
x: string;
y: number;
z: boolean;
}): void;
@@ -0,0 +1,10 @@
// @declaration: true
var [] = [1, "hello"]; // Dont emit anything
var [x] = [1, "hello"]; // emit x: number
var [x1, y1] = [1, "hello"]; // emit x1: number, y1: string
var [, , z1] = [0, 1, 2]; // emit z1: number
var a = [1, "hello"];
var [x2] = a; // emit x2: number | string
var [x3, y3, z3] = a; // emit x3, y3, z3
@@ -0,0 +1,10 @@
// @declaration: true
var [x10, [y10, [z10]]] = [1, ["hello", [true]]];
var [x11 = 0, y11 = ""] = [1, "hello"];
var [a11, b11, c11] = [];
var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]];
var [x13, y13] = [1, "hello"];
var [a3, b3] = [[x13, y13], { x: x13, y: y13 }];
@@ -0,0 +1,4 @@
// @declaration: true
module M {
export var [a, b] = [1, 2];
}
@@ -0,0 +1,10 @@
// @declaration: true
var [...a5] = [1, 2, 3];
var [x14, ...a6] = [1, 2, 3];
var [x15, y15, ...a7] = [1, 2, 3];
var [x16, y16, z16, ...a8] = [1, 2, 3];
var [...a9] = [1, "hello", true];
var [x17, ...a10] = [1, "hello", true];
var [x18, y18, ...a12] = [1, "hello", true];
var [x19, y19, z19, ...a13] = [1, "hello", true];
@@ -0,0 +1,23 @@
// @declaration: true
var { } = { x: 5, y: "hello" };
var { x4 } = { x4: 5, y4: "hello" };
var { y5 } = { x5: 5, y5: "hello" };
var { x6, y6 } = { x6: 5, y6: "hello" };
var { x7: a1 } = { x7: 5, y7: "hello" };
var { y8: b1 } = { x8: 5, y8: "hello" };
var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" };
var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } };
function f15() {
var a4 = "hello";
var b4 = 1;
var c4 = true;
return { a4, b4, c4 };
}
var { a4, b4, c4 } = f15();
module m {
export var { a4, b4, c4 } = f15();
}
@@ -0,0 +1,9 @@
// @declaration: true
var { } = { x: 5, y: "hello" };
var { x4 } = { x4: 5, y4: "hello" };
var { y5 } = { x5: 5, y5: "hello" };
var { x6, y6 } = { x6: 5, y6: "hello" };
var { x7: a1 } = { x7: 5, y7: "hello" };
var { y8: b1 } = { x8: 5, y8: "hello" };
var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" };
@@ -0,0 +1,15 @@
// @declaration: true
var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } };
function f15() {
var a4 = "hello";
var b4 = 1;
var c4 = true;
return { a4, b4, c4 };
}
var { a4, b4, c4 } = f15();
module m {
export var { a4, b4, c4 } = f15();
}
@@ -0,0 +1,10 @@
// @declaration: true
function foo([x, y, z] ?: [string, number, boolean]);
function foo(...rest: any[]) {
}
function foo2( { x, y, z }?: { x: string; y: number; z: boolean });
function foo2(...rest: any[]) {
}
@@ -0,0 +1,17 @@
// @declaration: true
class C1 {
constructor(public [x, y, z]: string[]) {
}
}
type TupleType1 =[string, number, boolean];
class C2 {
constructor(public [x, y, z]: TupleType1) {
}
}
type ObjType1 = { x: number; y: string; z: boolean }
class C3 {
constructor(public { x, y, z }: ObjType1) {
}
}
@@ -0,0 +1,6 @@
// @declaration: true
module m {
class c {
}
export var [x, y, z] = [10, new c(), 30];
}
@@ -0,0 +1,5 @@
// @declaration: true
function foo([x,y,z]?: [string, number, boolean]) {
}
function foo1( { x, y, z }?: { x: string; y: number; z: boolean }) {
}