1describe("unittests:: evaluation:: destructuring", () => { 2 // https://github.com/microsoft/TypeScript/issues/39205 3 describe("correct order for array destructuring evaluation and initializers", () => { 4 it("when element is undefined", () => { 5 const result = evaluator.evaluateTypeScript(` 6 export const output: any[] = []; 7 const order = (n: any): any => output.push(n); 8 let [{ [order(1)]: x } = order(0)] = []; 9 `, { target: ts.ScriptTarget.ES5 }); 10 assert.deepEqual(result.output, [0, 1]); 11 }); 12 it("when element is defined", async () => { 13 const result = evaluator.evaluateTypeScript(` 14 export const output: any[] = []; 15 const order = (n: any): any => output.push(n); 16 let [{ [order(1)]: x } = order(0)] = [{}]; 17 `, { target: ts.ScriptTarget.ES5 }); 18 assert.deepEqual(result.output, [1]); 19 }); 20 }); 21 describe("correct order for array destructuring evaluation and initializers with spread", () => { 22 it("ES5", () => { 23 const result = evaluator.evaluateTypeScript(` 24 export const output: any[] = []; 25 const order = (n: any): any => output.push(n); 26 let { [order(0)]: { [order(2)]: z } = order(1), ...w } = {} as any; 27 `, { target: ts.ScriptTarget.ES5 }); 28 assert.deepEqual(result.output, [0, 1, 2]); 29 }); 30 it("ES2015", () => { 31 const result = evaluator.evaluateTypeScript(` 32 export const output: any[] = []; 33 const order = (n: any): any => output.push(n); 34 let { [order(0)]: { [order(2)]: z } = order(1), ...w } = {} as any; 35 `, { target: ts.ScriptTarget.ES2015 }); 36 assert.deepEqual(result.output, [0, 1, 2]); 37 }); 38 }); 39 describe("correct evaluation for nested rest assignment in destructured object", () => { 40 it("ES5", () => { 41 const result = evaluator.evaluateTypeScript(` 42 let a: any, b: any, c: any = { x: { a: 1, y: 2 } }, d: any; 43 ({ x: { a, ...b } = d } = c); 44 export const output = { a, b }; 45 `, { target: ts.ScriptTarget.ES5 }); 46 assert.deepEqual(result.output, { a: 1, b: { y: 2 } }); 47 }); 48 it("ES2015", () => { 49 const result = evaluator.evaluateTypeScript(` 50 let a: any, b: any, c: any = { x: { a: 1, y: 2 } }, d: any; 51 ({ x: { a, ...b } = d } = c); 52 export const output = { a, b }; 53 `, { target: ts.ScriptTarget.ES2015 }); 54 assert.deepEqual(result.output, { a: 1, b: { y: 2 } }); 55 }); 56 it("ES2018", () => { 57 const result = evaluator.evaluateTypeScript(` 58 let a: any, b: any, c: any = { x: { a: 1, y: 2 } }, d: any; 59 ({ x: { a, ...b } = d } = c); 60 export const output = { a, b }; 61 `, { target: ts.ScriptTarget.ES2018 }); 62 assert.deepEqual(result.output, { a: 1, b: { y: 2 } }); 63 }); 64 }); 65}); 66