diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern5.js b/tests/baselines/reference/declarationEmitDestructuring1.js similarity index 83% rename from tests/baselines/reference/declarationEmitDestructuringArrayPattern5.js rename to tests/baselines/reference/declarationEmitDestructuring1.js index 9e8dee3285c..9ac08032a0d 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern5.js +++ b/tests/baselines/reference/declarationEmitDestructuring1.js @@ -1,11 +1,11 @@ -//// [declarationEmitDestructuringArrayPattern5.ts] +//// [declarationEmitDestructuring1.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] +//// [declarationEmitDestructuring1.js] function foo(_a) { var a = _a[0], b = _a[1], c = _a[2]; } @@ -20,7 +20,7 @@ function baz(_a) { } -//// [declarationEmitDestructuringArrayPattern5.d.ts] +//// [declarationEmitDestructuring1.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}: { diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern5.types b/tests/baselines/reference/declarationEmitDestructuring1.types similarity index 89% rename from tests/baselines/reference/declarationEmitDestructuringArrayPattern5.types rename to tests/baselines/reference/declarationEmitDestructuring1.types index fdb2bba88ea..6b22f25b54b 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern5.types +++ b/tests/baselines/reference/declarationEmitDestructuring1.types @@ -1,4 +1,4 @@ -=== tests/cases/compiler/declarationEmitDestructuringArrayPattern5.ts === +=== tests/cases/compiler/declarationEmitDestructuring1.ts === function foo([a, b, c]: [string, string, string]): void { } >foo : ([a, b, c]: [string, string, string]) => void >a : string diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern6.js b/tests/baselines/reference/declarationEmitDestructuring2.js similarity index 88% rename from tests/baselines/reference/declarationEmitDestructuringArrayPattern6.js rename to tests/baselines/reference/declarationEmitDestructuring2.js index 803ea9fe01a..f6d3d17abe1 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern6.js +++ b/tests/baselines/reference/declarationEmitDestructuring2.js @@ -1,10 +1,10 @@ -//// [declarationEmitDestructuringArrayPattern6.ts] +//// [declarationEmitDestructuring2.ts] function f({x = 10, y: [a, b, c, d] = [1, 2, 3, 4]} = { x: 10, y: [2, 4, 6, 8] }) { } function g([a, b, c, d] = [1, 2, 3, 4]) { } function h([a, [b], [[c]], {x = 10, y: [a, b, c], z: {a1, b1}}]){ } function h1([a, [b], [[c]], {x = 10, y = [1, 2, 3], z: {a1, b1}}]){ } -//// [declarationEmitDestructuringArrayPattern6.js] +//// [declarationEmitDestructuring2.js] function f(_a) { var _b = _a === void 0 ? { x: 10, @@ -41,7 +41,7 @@ function h1(_a) { } -//// [declarationEmitDestructuringArrayPattern6.d.ts] +//// [declarationEmitDestructuring2.d.ts] declare function f({x, y: [a, b, c, d]}?: { x: number; y: [number, number, number, number]; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern6.types b/tests/baselines/reference/declarationEmitDestructuring2.types similarity index 91% rename from tests/baselines/reference/declarationEmitDestructuringArrayPattern6.types rename to tests/baselines/reference/declarationEmitDestructuring2.types index 6112094cbe5..3368d4e72fd 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern6.types +++ b/tests/baselines/reference/declarationEmitDestructuring2.types @@ -1,4 +1,4 @@ -=== tests/cases/compiler/declarationEmitDestructuringArrayPattern6.ts === +=== tests/cases/compiler/declarationEmitDestructuring2.ts === function f({x = 10, y: [a, b, c, d] = [1, 2, 3, 4]} = { x: 10, y: [2, 4, 6, 8] }) { } >f : ({x = 10, y: [a, b, c, d] = [1, 2, 3, 4]}?: { x: number; y: [number, number, number, number]; }) => void >x : number diff --git a/tests/baselines/reference/declarationEmitDestructuring3.js b/tests/baselines/reference/declarationEmitDestructuring3.js new file mode 100644 index 00000000000..66f6b071a87 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuring3.js @@ -0,0 +1,22 @@ +//// [declarationEmitDestructuring3.ts] +function bar([x, z, ...w]) { } +function foo([x, ...y] = [1, "string", true]) { } + + + +//// [declarationEmitDestructuring3.js] +function bar(_a) { + var x = _a[0], z = _a[1], w = _a.slice(2); +} +function foo(_a) { + var _b = _a === void 0 ? [ + 1, + "string", + true + ] : _a, x = _b[0], y = _b.slice(1); +} + + +//// [declarationEmitDestructuring3.d.ts] +declare function bar([x, z, ...w]: any[]): void; +declare function foo([x, ...y]?: (string | number | boolean)[]): void; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern7.types b/tests/baselines/reference/declarationEmitDestructuring3.types similarity index 78% rename from tests/baselines/reference/declarationEmitDestructuringArrayPattern7.types rename to tests/baselines/reference/declarationEmitDestructuring3.types index 8dc51bf5c78..57764f53eee 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern7.types +++ b/tests/baselines/reference/declarationEmitDestructuring3.types @@ -1,4 +1,4 @@ -=== tests/cases/compiler/declarationEmitDestructuringArrayPattern7.ts === +=== tests/cases/compiler/declarationEmitDestructuring3.ts === function bar([x, z, ...w]) { } >bar : ([x, z, ...w]: any[]) => void >x : any @@ -11,3 +11,4 @@ function foo([x, ...y] = [1, "string", true]) { } >y : (string | number | boolean)[] >[1, "string", true] : (string | number | boolean)[] + diff --git a/tests/baselines/reference/declarationEmitDestructuring4.js b/tests/baselines/reference/declarationEmitDestructuring4.js new file mode 100644 index 00000000000..5b43fbfc85e --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuring4.js @@ -0,0 +1,67 @@ +//// [declarationEmitDestructuring4.ts] +function baz([]) { } +function baz1([] = [1,2,3]) { } +function baz2([[]] = [[1,2,3]]) { } +function baz3({}) { } +function baz4({} = { x: 10 }) { } +function baz5({} = { x: 10, y: { a: 2 }, z: [1,2] }) { } + + + +//// [declarationEmitDestructuring4.js] +function baz(_a) { + var ; +} +function baz1(_a) { + var _b = _a === void 0 ? [ + 1, + 2, + 3 + ] : _a; +} +function baz2(_a) { + var _b = (_a === void 0 ? [ + [ + 1, + 2, + 3 + ] + ] : _a)[0]; +} +function baz3(_a) { + var ; +} +function baz4(_a) { + var _b = _a === void 0 ? { + x: 10 + } : _a; +} +function baz5(_a) { + var _b = _a === void 0 ? { + x: 10, + y: { + a: 2 + }, + z: [ + 1, + 2 + ] + } : _a; +} + + +//// [declarationEmitDestructuring4.d.ts] +declare function baz([]: any[]): void; +declare function baz1([]?: number[]): void; +declare function baz2([[]]?: [number[]]): void; +declare function baz3({}: {}): void; +declare function baz4({}?: { + x: number; +}): void; +declare function baz5({}?: { + x: number; + y: { + a: number; + }; + z: number[]; +}): void; diff --git a/tests/baselines/reference/declarationEmitDestructuring4.types b/tests/baselines/reference/declarationEmitDestructuring4.types new file mode 100644 index 00000000000..6602fbdcb77 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuring4.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/declarationEmitDestructuring4.ts === +function baz([]) { } +>baz : ([]: any[]) => void + +function baz1([] = [1,2,3]) { } +>baz1 : ([]?: number[]) => void +>[1,2,3] : number[] + +function baz2([[]] = [[1,2,3]]) { } +>baz2 : ([[]]?: [number[]]) => void +>[[1,2,3]] : [number[]] +>[1,2,3] : number[] + +function baz3({}) { } +>baz3 : ({}: {}) => void + +function baz4({} = { x: 10 }) { } +>baz4 : ({}?: { x: number; }) => void +>{ x: 10 } : { x: number; } +>x : number + +function baz5({} = { x: 10, y: { a: 2 }, z: [1,2] }) { } +>baz5 : ({}?: { x: number; y: { a: number; }; z: number[]; }) => void +>{ x: 10, y: { a: 2 }, z: [1,2] } : { x: number; y: { a: number; }; z: number[]; } +>x : number +>y : { a: number; } +>{ a: 2 } : { a: number; } +>a : number +>z : number[] +>[1,2] : number[] + + diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern7.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern7.js deleted file mode 100644 index 00e65b816b0..00000000000 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern7.js +++ /dev/null @@ -1,20 +0,0 @@ -//// [declarationEmitDestructuringArrayPattern7.ts] -function bar([x, z, ...w]) { } -function foo([x, ...y] = [1, "string", true]) { } - -//// [declarationEmitDestructuringArrayPattern7.js] -function bar(_a) { - var x = _a[0], z = _a[1], w = _a.slice(2); -} -function foo(_a) { - var _b = _a === void 0 ? [ - 1, - "string", - true - ] : _a, x = _b[0], y = _b.slice(1); -} - - -//// [declarationEmitDestructuringArrayPattern7.d.ts] -declare function bar([x, z, w]: any[]): void; -declare function foo([x, y]?: (string | number | boolean)[]): void; diff --git a/tests/cases/compiler/declarationEmitDestructuringArrayPattern5.ts b/tests/cases/compiler/declarationEmitDestructuring1.ts similarity index 100% rename from tests/cases/compiler/declarationEmitDestructuringArrayPattern5.ts rename to tests/cases/compiler/declarationEmitDestructuring1.ts diff --git a/tests/cases/compiler/declarationEmitDestructuringArrayPattern6.ts b/tests/cases/compiler/declarationEmitDestructuring2.ts similarity index 100% rename from tests/cases/compiler/declarationEmitDestructuringArrayPattern6.ts rename to tests/cases/compiler/declarationEmitDestructuring2.ts diff --git a/tests/cases/compiler/declarationEmitDestructuring3.ts b/tests/cases/compiler/declarationEmitDestructuring3.ts new file mode 100644 index 00000000000..78aeddb0e11 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuring3.ts @@ -0,0 +1,4 @@ +// @declaration: true +function bar([x, z, ...w]) { } +function foo([x, ...y] = [1, "string", true]) { } + diff --git a/tests/cases/compiler/declarationEmitDestructuring4.ts b/tests/cases/compiler/declarationEmitDestructuring4.ts new file mode 100644 index 00000000000..b961be2b39c --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuring4.ts @@ -0,0 +1,12 @@ +// @declaration: true +// For an array binding pattern with empty elements, +// we will not make any modification and will emit +// the similar binding pattern users' have written +function baz([]) { } +function baz1([] = [1,2,3]) { } +function baz2([[]] = [[1,2,3]]) { } + +function baz3({}) { } +function baz4({} = { x: 10 }) { } +function baz5({} = { x: 10, y: { a: 2 }, z: [1,2] }) { } + diff --git a/tests/cases/compiler/declarationEmitDestructuringArrayPattern7.ts b/tests/cases/compiler/declarationEmitDestructuringArrayPattern7.ts deleted file mode 100644 index 321c6fd4202..00000000000 --- a/tests/cases/compiler/declarationEmitDestructuringArrayPattern7.ts +++ /dev/null @@ -1,3 +0,0 @@ -// @declaration: true -function bar([x, z, ...w]) { } -function foo([x, ...y] = [1, "string", true]) { } \ No newline at end of file