Skip to content

Commit 556cd1f

Browse files
committed
add more test cases for array destructuring side effects
1 parent 9711ecc commit 556cd1f

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

test/unit/destructuring.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,24 @@ describe("array destructuring optimization", () => {
235235
`.expectToMatchJsResult();
236236
});
237237

238+
test("array literal with many side effects in elements", () => {
239+
util.testFunction`
240+
const arr = [10, 20, 30, 40];
241+
let i = 0;
242+
let [v1, v2, v3, v4] = [arr[i++], arr[i++], arr[i++], arr[i++]];
243+
return { v1, v2, v3, v4 };
244+
`.expectToMatchJsResult();
245+
});
246+
247+
test("array literal with mixed pure and impure elements", () => {
248+
util.testFunction`
249+
const arr = [10, 20, 30];
250+
let i = 0;
251+
let [v1, v2, v3] = [1, arr[++i], 2];
252+
return { v1, v2, v3, i };
253+
`.expectToMatchJsResult();
254+
});
255+
238256
test("array union", () => {
239257
util.testFunction`
240258
const array: [string] | [] = ["bar"];

0 commit comments

Comments
 (0)