Skip to content

Commit 9dc15b4

Browse files
committed
Merge pull request microsoft#4257 from Microsoft/fix3912
Fix microsoft#3912: emit declaration for binding elements correctelly
2 parents fe51b45 + 7f49375 commit 9dc15b4

File tree

5 files changed

+55
-4
lines changed

5 files changed

+55
-4
lines changed

src/compiler/declarationEmitter.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,11 +1501,8 @@ namespace ts {
15011501
// emit : declare function foo({y: [a, b, c]}: { y: [any, any, any] }) void;
15021502
writeTextOfNode(currentSourceFile, bindingElement.propertyName);
15031503
write(": ");
1504-
1505-
// If bindingElement has propertyName property, then its name must be another bindingPattern of SyntaxKind.ObjectBindingPattern
1506-
emitBindingPattern(<BindingPattern>bindingElement.name);
15071504
}
1508-
else if (bindingElement.name) {
1505+
if (bindingElement.name) {
15091506
if (isBindingPattern(bindingElement.name)) {
15101507
// If it is a nested binding pattern, we will recursively descend into each element and emit each one separately.
15111508
// In the case of rest element, we will omit rest element.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [paramterDestrcuturingDeclaration.ts]
2+
3+
interface C {
4+
({p: name}): any;
5+
new ({p: boolean}): any;
6+
}
7+
8+
9+
//// [paramterDestrcuturingDeclaration.js]
10+
11+
12+
//// [paramterDestrcuturingDeclaration.d.ts]
13+
interface C {
14+
({p: name}: {
15+
p: any;
16+
}): any;
17+
new ({p: boolean}: {
18+
p: any;
19+
}): any;
20+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/paramterDestrcuturingDeclaration.ts ===
2+
3+
interface C {
4+
>C : Symbol(C, Decl(paramterDestrcuturingDeclaration.ts, 0, 0))
5+
6+
({p: name}): any;
7+
>p : Symbol(p)
8+
>name : Symbol(name, Decl(paramterDestrcuturingDeclaration.ts, 2, 6))
9+
10+
new ({p: boolean}): any;
11+
>p : Symbol(p)
12+
>boolean : Symbol(boolean, Decl(paramterDestrcuturingDeclaration.ts, 3, 10))
13+
}
14+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/paramterDestrcuturingDeclaration.ts ===
2+
3+
interface C {
4+
>C : C
5+
6+
({p: name}): any;
7+
>p : any
8+
>name : any
9+
10+
new ({p: boolean}): any;
11+
>p : any
12+
>boolean : any
13+
}
14+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @declaration: true
2+
3+
interface C {
4+
({p: name}): any;
5+
new ({p: boolean}): any;
6+
}

0 commit comments

Comments
 (0)