mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-04-13 09:12:52 -05:00
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>
This commit is contained in:
@@ -1621,11 +1621,12 @@ export function transformDeclarations(context: TransformationContext): Transform
|
||||
if (isOmittedExpression(elem)) continue;
|
||||
if (isBindingPattern(elem.name)) {
|
||||
elems = concatenate(elems, walkBindingPattern(elem.name));
|
||||
continue;
|
||||
}
|
||||
elems = elems || [];
|
||||
elems.push(factory.createPropertyDeclaration(
|
||||
ensureModifiers(param),
|
||||
elem.name as Identifier,
|
||||
elem.name,
|
||||
/*questionOrExclamationToken*/ undefined,
|
||||
ensureType(elem),
|
||||
/*initializer*/ undefined,
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
declarationEmitNestedBindingPattern.ts(3,17): error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
declarationEmitNestedBindingPattern.ts(8,17): error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
declarationEmitNestedBindingPattern.ts(13,17): error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
declarationEmitNestedBindingPattern.ts(18,17): error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
declarationEmitNestedBindingPattern.ts(23,17): error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
declarationEmitNestedBindingPattern.ts(28,17): error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
declarationEmitNestedBindingPattern.ts(34,9): error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
declarationEmitNestedBindingPattern.ts(35,9): error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
declarationEmitNestedBindingPattern.ts(41,17): error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
declarationEmitNestedBindingPattern.ts(46,17): error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
|
||||
|
||||
==== declarationEmitNestedBindingPattern.ts (10 errors) ====
|
||||
// Nested array binding pattern
|
||||
export class C1 {
|
||||
constructor(public [[x]]: any[]) {}
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
}
|
||||
|
||||
// Nested object binding pattern
|
||||
export class C2 {
|
||||
constructor(public [{y}]: any[]) {}
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
}
|
||||
|
||||
// Multiple levels of array nesting
|
||||
export class C3 {
|
||||
constructor(public [[[z]]]: any[]) {}
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
}
|
||||
|
||||
// Mixed array and object nesting
|
||||
export class C4 {
|
||||
constructor(public [{a: [b]}]: any[]) {}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
}
|
||||
|
||||
// Object with nested array
|
||||
export class C5 {
|
||||
constructor(public {prop: [c]}: any) {}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
}
|
||||
|
||||
// Object with multiple nested levels
|
||||
export class C6 {
|
||||
constructor(public {prop: {nested: [d]}}: any) {}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
}
|
||||
|
||||
// Multiple parameters with nested patterns
|
||||
export class C7 {
|
||||
constructor(
|
||||
public [[e]]: any[],
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
public [{f}]: any[]
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
) {}
|
||||
}
|
||||
|
||||
// Nested pattern with rest element
|
||||
export class C8 {
|
||||
constructor(public [[g, ...rest]]: any[]) {}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
}
|
||||
|
||||
// Complex nested pattern
|
||||
export class C9 {
|
||||
constructor(public [[h, i], {j, k: [l]}]: any) {}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1187: A parameter property may not be declared using a binding pattern.
|
||||
}
|
||||
|
||||
142
tests/baselines/reference/declarationEmitNestedBindingPattern.js
Normal file
142
tests/baselines/reference/declarationEmitNestedBindingPattern.js
Normal file
@@ -0,0 +1,142 @@
|
||||
//// [tests/cases/compiler/declarationEmitNestedBindingPattern.ts] ////
|
||||
|
||||
//// [declarationEmitNestedBindingPattern.ts]
|
||||
// Nested array binding pattern
|
||||
export class C1 {
|
||||
constructor(public [[x]]: any[]) {}
|
||||
}
|
||||
|
||||
// Nested object binding pattern
|
||||
export class C2 {
|
||||
constructor(public [{y}]: any[]) {}
|
||||
}
|
||||
|
||||
// Multiple levels of array nesting
|
||||
export class C3 {
|
||||
constructor(public [[[z]]]: any[]) {}
|
||||
}
|
||||
|
||||
// Mixed array and object nesting
|
||||
export class C4 {
|
||||
constructor(public [{a: [b]}]: any[]) {}
|
||||
}
|
||||
|
||||
// Object with nested array
|
||||
export class C5 {
|
||||
constructor(public {prop: [c]}: any) {}
|
||||
}
|
||||
|
||||
// Object with multiple nested levels
|
||||
export class C6 {
|
||||
constructor(public {prop: {nested: [d]}}: any) {}
|
||||
}
|
||||
|
||||
// Multiple parameters with nested patterns
|
||||
export class C7 {
|
||||
constructor(
|
||||
public [[e]]: any[],
|
||||
public [{f}]: any[]
|
||||
) {}
|
||||
}
|
||||
|
||||
// Nested pattern with rest element
|
||||
export class C8 {
|
||||
constructor(public [[g, ...rest]]: any[]) {}
|
||||
}
|
||||
|
||||
// Complex nested pattern
|
||||
export class C9 {
|
||||
constructor(public [[h, i], {j, k: [l]}]: any) {}
|
||||
}
|
||||
|
||||
|
||||
//// [declarationEmitNestedBindingPattern.js]
|
||||
// Nested array binding pattern
|
||||
export class C1 {
|
||||
constructor([[x]]) {
|
||||
}
|
||||
}
|
||||
// Nested object binding pattern
|
||||
export class C2 {
|
||||
constructor([{ y }]) {
|
||||
}
|
||||
}
|
||||
// Multiple levels of array nesting
|
||||
export class C3 {
|
||||
constructor([[[z]]]) {
|
||||
}
|
||||
}
|
||||
// Mixed array and object nesting
|
||||
export class C4 {
|
||||
constructor([{ a: [b] }]) {
|
||||
}
|
||||
}
|
||||
// Object with nested array
|
||||
export class C5 {
|
||||
constructor({ prop: [c] }) {
|
||||
}
|
||||
}
|
||||
// Object with multiple nested levels
|
||||
export class C6 {
|
||||
constructor({ prop: { nested: [d] } }) {
|
||||
}
|
||||
}
|
||||
// Multiple parameters with nested patterns
|
||||
export class C7 {
|
||||
constructor([[e]], [{ f }]) {
|
||||
}
|
||||
}
|
||||
// Nested pattern with rest element
|
||||
export class C8 {
|
||||
constructor([[g, ...rest]]) {
|
||||
}
|
||||
}
|
||||
// Complex nested pattern
|
||||
export class C9 {
|
||||
constructor([[h, i], { j, k: [l] }]) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [declarationEmitNestedBindingPattern.d.ts]
|
||||
export declare class C1 {
|
||||
x: any;
|
||||
constructor([[x]]: any[]);
|
||||
}
|
||||
export declare class C2 {
|
||||
y: any;
|
||||
constructor([{ y }]: any[]);
|
||||
}
|
||||
export declare class C3 {
|
||||
z: any;
|
||||
constructor([[[z]]]: any[]);
|
||||
}
|
||||
export declare class C4 {
|
||||
b: any;
|
||||
constructor([{ a: [b] }]: any[]);
|
||||
}
|
||||
export declare class C5 {
|
||||
c: any;
|
||||
constructor({ prop: [c] }: any);
|
||||
}
|
||||
export declare class C6 {
|
||||
d: any;
|
||||
constructor({ prop: { nested: [d] } }: any);
|
||||
}
|
||||
export declare class C7 {
|
||||
e: any;
|
||||
f: any;
|
||||
constructor([[e]]: any[], [{ f }]: any[]);
|
||||
}
|
||||
export declare class C8 {
|
||||
g: any;
|
||||
rest: any;
|
||||
constructor([[g, ...rest]]: any[]);
|
||||
}
|
||||
export declare class C9 {
|
||||
h: any;
|
||||
i: any;
|
||||
j: any;
|
||||
l: any;
|
||||
constructor([[h, i], { j, k: [l] }]: any);
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
//// [tests/cases/compiler/declarationEmitNestedBindingPattern.ts] ////
|
||||
|
||||
=== declarationEmitNestedBindingPattern.ts ===
|
||||
// Nested array binding pattern
|
||||
export class C1 {
|
||||
>C1 : Symbol(C1, Decl(declarationEmitNestedBindingPattern.ts, 0, 0))
|
||||
|
||||
constructor(public [[x]]: any[]) {}
|
||||
>x : Symbol(x, Decl(declarationEmitNestedBindingPattern.ts, 2, 25))
|
||||
}
|
||||
|
||||
// Nested object binding pattern
|
||||
export class C2 {
|
||||
>C2 : Symbol(C2, Decl(declarationEmitNestedBindingPattern.ts, 3, 1))
|
||||
|
||||
constructor(public [{y}]: any[]) {}
|
||||
>y : Symbol(y, Decl(declarationEmitNestedBindingPattern.ts, 7, 25))
|
||||
}
|
||||
|
||||
// Multiple levels of array nesting
|
||||
export class C3 {
|
||||
>C3 : Symbol(C3, Decl(declarationEmitNestedBindingPattern.ts, 8, 1))
|
||||
|
||||
constructor(public [[[z]]]: any[]) {}
|
||||
>z : Symbol(z, Decl(declarationEmitNestedBindingPattern.ts, 12, 26))
|
||||
}
|
||||
|
||||
// Mixed array and object nesting
|
||||
export class C4 {
|
||||
>C4 : Symbol(C4, Decl(declarationEmitNestedBindingPattern.ts, 13, 1))
|
||||
|
||||
constructor(public [{a: [b]}]: any[]) {}
|
||||
>b : Symbol(b, Decl(declarationEmitNestedBindingPattern.ts, 17, 29))
|
||||
}
|
||||
|
||||
// Object with nested array
|
||||
export class C5 {
|
||||
>C5 : Symbol(C5, Decl(declarationEmitNestedBindingPattern.ts, 18, 1))
|
||||
|
||||
constructor(public {prop: [c]}: any) {}
|
||||
>c : Symbol(c, Decl(declarationEmitNestedBindingPattern.ts, 22, 31))
|
||||
}
|
||||
|
||||
// Object with multiple nested levels
|
||||
export class C6 {
|
||||
>C6 : Symbol(C6, Decl(declarationEmitNestedBindingPattern.ts, 23, 1))
|
||||
|
||||
constructor(public {prop: {nested: [d]}}: any) {}
|
||||
>d : Symbol(d, Decl(declarationEmitNestedBindingPattern.ts, 27, 40))
|
||||
}
|
||||
|
||||
// Multiple parameters with nested patterns
|
||||
export class C7 {
|
||||
>C7 : Symbol(C7, Decl(declarationEmitNestedBindingPattern.ts, 28, 1))
|
||||
|
||||
constructor(
|
||||
public [[e]]: any[],
|
||||
>e : Symbol(e, Decl(declarationEmitNestedBindingPattern.ts, 33, 17))
|
||||
|
||||
public [{f}]: any[]
|
||||
>f : Symbol(f, Decl(declarationEmitNestedBindingPattern.ts, 34, 17))
|
||||
|
||||
) {}
|
||||
}
|
||||
|
||||
// Nested pattern with rest element
|
||||
export class C8 {
|
||||
>C8 : Symbol(C8, Decl(declarationEmitNestedBindingPattern.ts, 36, 1))
|
||||
|
||||
constructor(public [[g, ...rest]]: any[]) {}
|
||||
>g : Symbol(g, Decl(declarationEmitNestedBindingPattern.ts, 40, 25))
|
||||
>rest : Symbol(rest, Decl(declarationEmitNestedBindingPattern.ts, 40, 27))
|
||||
}
|
||||
|
||||
// Complex nested pattern
|
||||
export class C9 {
|
||||
>C9 : Symbol(C9, Decl(declarationEmitNestedBindingPattern.ts, 41, 1))
|
||||
|
||||
constructor(public [[h, i], {j, k: [l]}]: any) {}
|
||||
>h : Symbol(h, Decl(declarationEmitNestedBindingPattern.ts, 45, 25))
|
||||
>i : Symbol(i, Decl(declarationEmitNestedBindingPattern.ts, 45, 27))
|
||||
>j : Symbol(j, Decl(declarationEmitNestedBindingPattern.ts, 45, 33))
|
||||
>l : Symbol(l, Decl(declarationEmitNestedBindingPattern.ts, 45, 40))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
//// [tests/cases/compiler/declarationEmitNestedBindingPattern.ts] ////
|
||||
|
||||
=== declarationEmitNestedBindingPattern.ts ===
|
||||
// Nested array binding pattern
|
||||
export class C1 {
|
||||
>C1 : C1
|
||||
> : ^^
|
||||
|
||||
constructor(public [[x]]: any[]) {}
|
||||
>x : any
|
||||
> : ^^^
|
||||
}
|
||||
|
||||
// Nested object binding pattern
|
||||
export class C2 {
|
||||
>C2 : C2
|
||||
> : ^^
|
||||
|
||||
constructor(public [{y}]: any[]) {}
|
||||
>y : any
|
||||
> : ^^^
|
||||
}
|
||||
|
||||
// Multiple levels of array nesting
|
||||
export class C3 {
|
||||
>C3 : C3
|
||||
> : ^^
|
||||
|
||||
constructor(public [[[z]]]: any[]) {}
|
||||
>z : any
|
||||
> : ^^^
|
||||
}
|
||||
|
||||
// Mixed array and object nesting
|
||||
export class C4 {
|
||||
>C4 : C4
|
||||
> : ^^
|
||||
|
||||
constructor(public [{a: [b]}]: any[]) {}
|
||||
>a : any
|
||||
> : ^^^
|
||||
>b : any
|
||||
> : ^^^
|
||||
}
|
||||
|
||||
// Object with nested array
|
||||
export class C5 {
|
||||
>C5 : C5
|
||||
> : ^^
|
||||
|
||||
constructor(public {prop: [c]}: any) {}
|
||||
>prop : any
|
||||
> : ^^^
|
||||
>c : any
|
||||
> : ^^^
|
||||
}
|
||||
|
||||
// Object with multiple nested levels
|
||||
export class C6 {
|
||||
>C6 : C6
|
||||
> : ^^
|
||||
|
||||
constructor(public {prop: {nested: [d]}}: any) {}
|
||||
>prop : any
|
||||
> : ^^^
|
||||
>nested : any
|
||||
> : ^^^
|
||||
>d : any
|
||||
> : ^^^
|
||||
}
|
||||
|
||||
// Multiple parameters with nested patterns
|
||||
export class C7 {
|
||||
>C7 : C7
|
||||
> : ^^
|
||||
|
||||
constructor(
|
||||
public [[e]]: any[],
|
||||
>e : any
|
||||
> : ^^^
|
||||
|
||||
public [{f}]: any[]
|
||||
>f : any
|
||||
> : ^^^
|
||||
|
||||
) {}
|
||||
}
|
||||
|
||||
// Nested pattern with rest element
|
||||
export class C8 {
|
||||
>C8 : C8
|
||||
> : ^^
|
||||
|
||||
constructor(public [[g, ...rest]]: any[]) {}
|
||||
>g : any
|
||||
> : ^^^
|
||||
>rest : any
|
||||
> : ^^^
|
||||
}
|
||||
|
||||
// Complex nested pattern
|
||||
export class C9 {
|
||||
>C9 : C9
|
||||
> : ^^
|
||||
|
||||
constructor(public [[h, i], {j, k: [l]}]: any) {}
|
||||
>h : any
|
||||
> : ^^^
|
||||
>i : any
|
||||
> : ^^^
|
||||
>j : any
|
||||
> : ^^^
|
||||
>k : any
|
||||
> : ^^^
|
||||
>l : any
|
||||
> : ^^^
|
||||
}
|
||||
|
||||
49
tests/cases/compiler/declarationEmitNestedBindingPattern.ts
Normal file
49
tests/cases/compiler/declarationEmitNestedBindingPattern.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
// @declaration: true
|
||||
|
||||
// Nested array binding pattern
|
||||
export class C1 {
|
||||
constructor(public [[x]]: any[]) {}
|
||||
}
|
||||
|
||||
// Nested object binding pattern
|
||||
export class C2 {
|
||||
constructor(public [{y}]: any[]) {}
|
||||
}
|
||||
|
||||
// Multiple levels of array nesting
|
||||
export class C3 {
|
||||
constructor(public [[[z]]]: any[]) {}
|
||||
}
|
||||
|
||||
// Mixed array and object nesting
|
||||
export class C4 {
|
||||
constructor(public [{a: [b]}]: any[]) {}
|
||||
}
|
||||
|
||||
// Object with nested array
|
||||
export class C5 {
|
||||
constructor(public {prop: [c]}: any) {}
|
||||
}
|
||||
|
||||
// Object with multiple nested levels
|
||||
export class C6 {
|
||||
constructor(public {prop: {nested: [d]}}: any) {}
|
||||
}
|
||||
|
||||
// Multiple parameters with nested patterns
|
||||
export class C7 {
|
||||
constructor(
|
||||
public [[e]]: any[],
|
||||
public [{f}]: any[]
|
||||
) {}
|
||||
}
|
||||
|
||||
// Nested pattern with rest element
|
||||
export class C8 {
|
||||
constructor(public [[g, ...rest]]: any[]) {}
|
||||
}
|
||||
|
||||
// Complex nested pattern
|
||||
export class C9 {
|
||||
constructor(public [[h, i], {j, k: [l]}]: any) {}
|
||||
}
|
||||
Reference in New Issue
Block a user