@@ -226,6 +226,33 @@ describe("array destructuring optimization", () => {
226226 . expectToMatchJsResult ( ) ;
227227 } ) ;
228228
229+ test ( "array literal with side effects in elements" , ( ) => {
230+ util . testFunction `
231+ const arr = [1, 2];
232+ let i = 0;
233+ let [v1, v2] = [arr[i], arr[++i]];
234+ return { v1, v2 };
235+ ` . expectToMatchJsResult ( ) ;
236+ } ) ;
237+
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+
229256 test ( "array union" , ( ) => {
230257 util . testFunction `
231258 const array: [string] | [] = ["bar"];
0 commit comments