Emit destructuring in parameter

This commit is contained in:
Yui T 2015-03-19 14:36:30 -07:00
parent 79272d7cef
commit 36ea7c8d77
7 changed files with 84 additions and 8 deletions

View File

@ -1291,7 +1291,8 @@ module ts {
write("...");
}
if (isBindingPattern(node.name)) {
write("_" + indexOf((<FunctionLikeDeclaration>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);

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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);
}

View File

@ -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;

View File

@ -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 { }