Skip to content

Commit ad04bf7

Browse files
Fix crash in declaration emit with nested binding patterns (#63154)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
1 parent 0ed1ee5 commit ad04bf7

File tree

6 files changed

+477
-1
lines changed

6 files changed

+477
-1
lines changed

src/compiler/transformers/declarations.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1621,11 +1621,12 @@ export function transformDeclarations(context: TransformationContext): Transform
16211621
if (isOmittedExpression(elem)) continue;
16221622
if (isBindingPattern(elem.name)) {
16231623
elems = concatenate(elems, walkBindingPattern(elem.name));
1624+
continue;
16241625
}
16251626
elems = elems || [];
16261627
elems.push(factory.createPropertyDeclaration(
16271628
ensureModifiers(param),
1628-
elem.name as Identifier,
1629+
elem.name,
16291630
/*questionOrExclamationToken*/ undefined,
16301631
ensureType(elem),
16311632
/*initializer*/ undefined,
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
declarationEmitNestedBindingPattern.ts(3,17): error TS1187: A parameter property may not be declared using a binding pattern.
2+
declarationEmitNestedBindingPattern.ts(8,17): error TS1187: A parameter property may not be declared using a binding pattern.
3+
declarationEmitNestedBindingPattern.ts(13,17): error TS1187: A parameter property may not be declared using a binding pattern.
4+
declarationEmitNestedBindingPattern.ts(18,17): error TS1187: A parameter property may not be declared using a binding pattern.
5+
declarationEmitNestedBindingPattern.ts(23,17): error TS1187: A parameter property may not be declared using a binding pattern.
6+
declarationEmitNestedBindingPattern.ts(28,17): error TS1187: A parameter property may not be declared using a binding pattern.
7+
declarationEmitNestedBindingPattern.ts(34,9): error TS1187: A parameter property may not be declared using a binding pattern.
8+
declarationEmitNestedBindingPattern.ts(35,9): error TS1187: A parameter property may not be declared using a binding pattern.
9+
declarationEmitNestedBindingPattern.ts(41,17): error TS1187: A parameter property may not be declared using a binding pattern.
10+
declarationEmitNestedBindingPattern.ts(46,17): error TS1187: A parameter property may not be declared using a binding pattern.
11+
12+
13+
==== declarationEmitNestedBindingPattern.ts (10 errors) ====
14+
// Nested array binding pattern
15+
export class C1 {
16+
constructor(public [[x]]: any[]) {}
17+
~~~~~~~~~~~~~~~~~~~
18+
!!! error TS1187: A parameter property may not be declared using a binding pattern.
19+
}
20+
21+
// Nested object binding pattern
22+
export class C2 {
23+
constructor(public [{y}]: any[]) {}
24+
~~~~~~~~~~~~~~~~~~~
25+
!!! error TS1187: A parameter property may not be declared using a binding pattern.
26+
}
27+
28+
// Multiple levels of array nesting
29+
export class C3 {
30+
constructor(public [[[z]]]: any[]) {}
31+
~~~~~~~~~~~~~~~~~~~~~
32+
!!! error TS1187: A parameter property may not be declared using a binding pattern.
33+
}
34+
35+
// Mixed array and object nesting
36+
export class C4 {
37+
constructor(public [{a: [b]}]: any[]) {}
38+
~~~~~~~~~~~~~~~~~~~~~~~~
39+
!!! error TS1187: A parameter property may not be declared using a binding pattern.
40+
}
41+
42+
// Object with nested array
43+
export class C5 {
44+
constructor(public {prop: [c]}: any) {}
45+
~~~~~~~~~~~~~~~~~~~~~~~
46+
!!! error TS1187: A parameter property may not be declared using a binding pattern.
47+
}
48+
49+
// Object with multiple nested levels
50+
export class C6 {
51+
constructor(public {prop: {nested: [d]}}: any) {}
52+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53+
!!! error TS1187: A parameter property may not be declared using a binding pattern.
54+
}
55+
56+
// Multiple parameters with nested patterns
57+
export class C7 {
58+
constructor(
59+
public [[e]]: any[],
60+
~~~~~~~~~~~~~~~~~~~
61+
!!! error TS1187: A parameter property may not be declared using a binding pattern.
62+
public [{f}]: any[]
63+
~~~~~~~~~~~~~~~~~~~
64+
!!! error TS1187: A parameter property may not be declared using a binding pattern.
65+
) {}
66+
}
67+
68+
// Nested pattern with rest element
69+
export class C8 {
70+
constructor(public [[g, ...rest]]: any[]) {}
71+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72+
!!! error TS1187: A parameter property may not be declared using a binding pattern.
73+
}
74+
75+
// Complex nested pattern
76+
export class C9 {
77+
constructor(public [[h, i], {j, k: [l]}]: any) {}
78+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
79+
!!! error TS1187: A parameter property may not be declared using a binding pattern.
80+
}
81+
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
//// [tests/cases/compiler/declarationEmitNestedBindingPattern.ts] ////
2+
3+
//// [declarationEmitNestedBindingPattern.ts]
4+
// Nested array binding pattern
5+
export class C1 {
6+
constructor(public [[x]]: any[]) {}
7+
}
8+
9+
// Nested object binding pattern
10+
export class C2 {
11+
constructor(public [{y}]: any[]) {}
12+
}
13+
14+
// Multiple levels of array nesting
15+
export class C3 {
16+
constructor(public [[[z]]]: any[]) {}
17+
}
18+
19+
// Mixed array and object nesting
20+
export class C4 {
21+
constructor(public [{a: [b]}]: any[]) {}
22+
}
23+
24+
// Object with nested array
25+
export class C5 {
26+
constructor(public {prop: [c]}: any) {}
27+
}
28+
29+
// Object with multiple nested levels
30+
export class C6 {
31+
constructor(public {prop: {nested: [d]}}: any) {}
32+
}
33+
34+
// Multiple parameters with nested patterns
35+
export class C7 {
36+
constructor(
37+
public [[e]]: any[],
38+
public [{f}]: any[]
39+
) {}
40+
}
41+
42+
// Nested pattern with rest element
43+
export class C8 {
44+
constructor(public [[g, ...rest]]: any[]) {}
45+
}
46+
47+
// Complex nested pattern
48+
export class C9 {
49+
constructor(public [[h, i], {j, k: [l]}]: any) {}
50+
}
51+
52+
53+
//// [declarationEmitNestedBindingPattern.js]
54+
// Nested array binding pattern
55+
export class C1 {
56+
constructor([[x]]) {
57+
}
58+
}
59+
// Nested object binding pattern
60+
export class C2 {
61+
constructor([{ y }]) {
62+
}
63+
}
64+
// Multiple levels of array nesting
65+
export class C3 {
66+
constructor([[[z]]]) {
67+
}
68+
}
69+
// Mixed array and object nesting
70+
export class C4 {
71+
constructor([{ a: [b] }]) {
72+
}
73+
}
74+
// Object with nested array
75+
export class C5 {
76+
constructor({ prop: [c] }) {
77+
}
78+
}
79+
// Object with multiple nested levels
80+
export class C6 {
81+
constructor({ prop: { nested: [d] } }) {
82+
}
83+
}
84+
// Multiple parameters with nested patterns
85+
export class C7 {
86+
constructor([[e]], [{ f }]) {
87+
}
88+
}
89+
// Nested pattern with rest element
90+
export class C8 {
91+
constructor([[g, ...rest]]) {
92+
}
93+
}
94+
// Complex nested pattern
95+
export class C9 {
96+
constructor([[h, i], { j, k: [l] }]) {
97+
}
98+
}
99+
100+
101+
//// [declarationEmitNestedBindingPattern.d.ts]
102+
export declare class C1 {
103+
x: any;
104+
constructor([[x]]: any[]);
105+
}
106+
export declare class C2 {
107+
y: any;
108+
constructor([{ y }]: any[]);
109+
}
110+
export declare class C3 {
111+
z: any;
112+
constructor([[[z]]]: any[]);
113+
}
114+
export declare class C4 {
115+
b: any;
116+
constructor([{ a: [b] }]: any[]);
117+
}
118+
export declare class C5 {
119+
c: any;
120+
constructor({ prop: [c] }: any);
121+
}
122+
export declare class C6 {
123+
d: any;
124+
constructor({ prop: { nested: [d] } }: any);
125+
}
126+
export declare class C7 {
127+
e: any;
128+
f: any;
129+
constructor([[e]]: any[], [{ f }]: any[]);
130+
}
131+
export declare class C8 {
132+
g: any;
133+
rest: any;
134+
constructor([[g, ...rest]]: any[]);
135+
}
136+
export declare class C9 {
137+
h: any;
138+
i: any;
139+
j: any;
140+
l: any;
141+
constructor([[h, i], { j, k: [l] }]: any);
142+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//// [tests/cases/compiler/declarationEmitNestedBindingPattern.ts] ////
2+
3+
=== declarationEmitNestedBindingPattern.ts ===
4+
// Nested array binding pattern
5+
export class C1 {
6+
>C1 : Symbol(C1, Decl(declarationEmitNestedBindingPattern.ts, 0, 0))
7+
8+
constructor(public [[x]]: any[]) {}
9+
>x : Symbol(x, Decl(declarationEmitNestedBindingPattern.ts, 2, 25))
10+
}
11+
12+
// Nested object binding pattern
13+
export class C2 {
14+
>C2 : Symbol(C2, Decl(declarationEmitNestedBindingPattern.ts, 3, 1))
15+
16+
constructor(public [{y}]: any[]) {}
17+
>y : Symbol(y, Decl(declarationEmitNestedBindingPattern.ts, 7, 25))
18+
}
19+
20+
// Multiple levels of array nesting
21+
export class C3 {
22+
>C3 : Symbol(C3, Decl(declarationEmitNestedBindingPattern.ts, 8, 1))
23+
24+
constructor(public [[[z]]]: any[]) {}
25+
>z : Symbol(z, Decl(declarationEmitNestedBindingPattern.ts, 12, 26))
26+
}
27+
28+
// Mixed array and object nesting
29+
export class C4 {
30+
>C4 : Symbol(C4, Decl(declarationEmitNestedBindingPattern.ts, 13, 1))
31+
32+
constructor(public [{a: [b]}]: any[]) {}
33+
>b : Symbol(b, Decl(declarationEmitNestedBindingPattern.ts, 17, 29))
34+
}
35+
36+
// Object with nested array
37+
export class C5 {
38+
>C5 : Symbol(C5, Decl(declarationEmitNestedBindingPattern.ts, 18, 1))
39+
40+
constructor(public {prop: [c]}: any) {}
41+
>c : Symbol(c, Decl(declarationEmitNestedBindingPattern.ts, 22, 31))
42+
}
43+
44+
// Object with multiple nested levels
45+
export class C6 {
46+
>C6 : Symbol(C6, Decl(declarationEmitNestedBindingPattern.ts, 23, 1))
47+
48+
constructor(public {prop: {nested: [d]}}: any) {}
49+
>d : Symbol(d, Decl(declarationEmitNestedBindingPattern.ts, 27, 40))
50+
}
51+
52+
// Multiple parameters with nested patterns
53+
export class C7 {
54+
>C7 : Symbol(C7, Decl(declarationEmitNestedBindingPattern.ts, 28, 1))
55+
56+
constructor(
57+
public [[e]]: any[],
58+
>e : Symbol(e, Decl(declarationEmitNestedBindingPattern.ts, 33, 17))
59+
60+
public [{f}]: any[]
61+
>f : Symbol(f, Decl(declarationEmitNestedBindingPattern.ts, 34, 17))
62+
63+
) {}
64+
}
65+
66+
// Nested pattern with rest element
67+
export class C8 {
68+
>C8 : Symbol(C8, Decl(declarationEmitNestedBindingPattern.ts, 36, 1))
69+
70+
constructor(public [[g, ...rest]]: any[]) {}
71+
>g : Symbol(g, Decl(declarationEmitNestedBindingPattern.ts, 40, 25))
72+
>rest : Symbol(rest, Decl(declarationEmitNestedBindingPattern.ts, 40, 27))
73+
}
74+
75+
// Complex nested pattern
76+
export class C9 {
77+
>C9 : Symbol(C9, Decl(declarationEmitNestedBindingPattern.ts, 41, 1))
78+
79+
constructor(public [[h, i], {j, k: [l]}]: any) {}
80+
>h : Symbol(h, Decl(declarationEmitNestedBindingPattern.ts, 45, 25))
81+
>i : Symbol(i, Decl(declarationEmitNestedBindingPattern.ts, 45, 27))
82+
>j : Symbol(j, Decl(declarationEmitNestedBindingPattern.ts, 45, 33))
83+
>l : Symbol(l, Decl(declarationEmitNestedBindingPattern.ts, 45, 40))
84+
}
85+

0 commit comments

Comments
 (0)