Skip to content

Commit 36ea7c8

Browse files
author
Yui T
committed
Emit destructuring in parameter
1 parent 79272d7 commit 36ea7c8

7 files changed

+84
-8
lines changed

src/compiler/declarationEmitter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,8 @@ module ts {
12911291
write("...");
12921292
}
12931293
if (isBindingPattern(node.name)) {
1294-
write("_" + indexOf((<FunctionLikeDeclaration>node.parent).parameters, node));
1294+
// By emitting binding pattern as binding pattern in function parameters, language service can provide better signature help
1295+
write(getTextOfNode(node.name));
12951296
}
12961297
else {
12971298
writeTextOfNode(currentSourceFile, node.name);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//// [declarationEmitDestructuringArrayPattern5.ts]
2+
function foo([a, b, c]: [string, string, string]): void { }
3+
function far([a, [b], [[c]]]: [number, boolean[], string[][]]): void { }
4+
function bar({a1, b1, c1}: { a1: number, b1: boolean, c1: string }): void { }
5+
function baz({a2, b2: {b1, c1}}: { a2: number, b2: { b1: boolean, c1: string } }): void { }
6+
7+
8+
//// [declarationEmitDestructuringArrayPattern5.js]
9+
function foo(_a) {
10+
var a = _a[0], b = _a[1], c = _a[2];
11+
}
12+
function far(_a) {
13+
var a = _a[0], b = _a[1][0], c = _a[2][0][0];
14+
}
15+
function bar(_a) {
16+
var a1 = _a.a1, b1 = _a.b1, c1 = _a.c1;
17+
}
18+
function baz(_a) {
19+
var a2 = _a.a2, _b = _a.b2, b1 = _b.b1, c1 = _b.c1;
20+
}
21+
22+
23+
//// [declarationEmitDestructuringArrayPattern5.d.ts]
24+
declare function foo([a, b, c]: [string, string, string]): void;
25+
declare function far([a, [b], [[c]]]: [number, boolean[], string[][]]): void;
26+
declare function bar({a1, b1, c1}: {
27+
a1: number;
28+
b1: boolean;
29+
c1: string;
30+
}): void;
31+
declare function baz({a2, b2: {b1, c1}}: {
32+
a2: number;
33+
b2: {
34+
b1: boolean;
35+
c1: string;
36+
};
37+
}): void;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
=== tests/cases/compiler/declarationEmitDestructuringArrayPattern5.ts ===
2+
function foo([a, b, c]: [string, string, string]): void { }
3+
>foo : ([a, b, c]: [string, string, string]) => void
4+
>a : string
5+
>b : string
6+
>c : string
7+
8+
function far([a, [b], [[c]]]: [number, boolean[], string[][]]): void { }
9+
>far : ([a, [b], [[c]]]: [number, boolean[], string[][]]) => void
10+
>a : number
11+
>b : boolean
12+
>c : string
13+
14+
function bar({a1, b1, c1}: { a1: number, b1: boolean, c1: string }): void { }
15+
>bar : ({a1, b1, c1}: { a1: number; b1: boolean; c1: string; }) => void
16+
>a1 : number
17+
>b1 : boolean
18+
>c1 : string
19+
>a1 : number
20+
>b1 : boolean
21+
>c1 : string
22+
23+
function baz({a2, b2: {b1, c1}}: { a2: number, b2: { b1: boolean, c1: string } }): void { }
24+
>baz : ({a2, b2: {b1, c1}}: { a2: number; b2: { b1: boolean; c1: string; }; }) => void
25+
>a2 : number
26+
>b2 : unknown
27+
>b1 : boolean
28+
>c1 : string
29+
>a2 : number
30+
>b2 : { b1: boolean; c1: string; }
31+
>b1 : boolean
32+
>c1 : string
33+

tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ function foo2() {
2525

2626

2727
//// [declarationEmitDestructuringOptionalBindingParametersInOverloads.d.ts]
28-
declare function foo(_0?: [string, number, boolean]): any;
29-
declare function foo2(_0?: {
28+
declare function foo([x, y, z]?: [string, number, boolean]): any;
29+
declare function foo2({ x, y, z }?: {
3030
x: string;
3131
y: number;
3232
z: boolean;

tests/baselines/reference/declarationEmitDestructuringParameterProperties.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ var C3 = (function () {
4343
//// [declarationEmitDestructuringParameterProperties.d.ts]
4444
declare class C1 {
4545
x: string, y: string, z: string;
46-
constructor(_0: string[]);
46+
constructor([x, y, z]: string[]);
4747
}
4848
declare type TupleType1 = [string, number, boolean];
4949
declare class C2 {
5050
x: string, y: number, z: boolean;
51-
constructor(_0: TupleType1);
51+
constructor([x, y, z]: TupleType1);
5252
}
5353
declare type ObjType1 = {
5454
x: number;
@@ -57,5 +57,5 @@ declare type ObjType1 = {
5757
};
5858
declare class C3 {
5959
x: number, y: string, z: boolean;
60-
constructor(_0: ObjType1);
60+
constructor({ x, y, z }: ObjType1);
6161
}

tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ function foo1(_a) {
1414

1515

1616
//// [declarationEmitDestructuringWithOptionalBindingParameters.d.ts]
17-
declare function foo(_0?: [string, number, boolean]): void;
18-
declare function foo1(_0?: {
17+
declare function foo([x,y,z]?: [string, number, boolean]): void;
18+
declare function foo1({ x, y, z }?: {
1919
x: string;
2020
y: number;
2121
z: boolean;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @declaration: true
2+
function foo([a, b, c]: [string, string, string]): void { }
3+
function far([a, [b], [[c]]]: [number, boolean[], string[][]]): void { }
4+
function bar({a1, b1, c1}: { a1: number, b1: boolean, c1: string }): void { }
5+
function baz({a2, b2: {b1, c1}}: { a2: number, b2: { b1: boolean, c1: string } }): void { }

0 commit comments

Comments
 (0)