Skip to content

Commit

Permalink
Do not evaluate the initializers of for-in and for-of. Closes #1234
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiosantoscode committed Apr 19, 2023
1 parent 7093b30 commit e072c21
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/compress/inference.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import {
AST_EmptyStatement,
AST_Expansion,
AST_False,
AST_ForIn,
AST_Function,
AST_If,
AST_Import,
Expand Down Expand Up @@ -712,6 +713,7 @@ export function is_nullish(node, compressor) {
export function is_lhs(node, parent) {
if (parent instanceof AST_Unary && unary_side_effects.has(parent.operator)) return parent.expression;
if (parent instanceof AST_Assign && parent.left === node) return node;
if (parent instanceof AST_ForIn && parent.init === node) return node;
}

(function(def_find_defs) {
Expand Down
11 changes: 11 additions & 0 deletions test/compress/loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -758,3 +758,14 @@ issue_2904: {
}
expect_stdout: "1"
}

issue_t1234: {
options = {}
input: {
for ({ x: 0 }.x of [1, 2]) console.log(123);
}
expect: {
for ({ x: 0 }.x of [1, 2]) console.log(123);
}
expect_stdout: ["123", "123"]
}

0 comments on commit e072c21

Please sign in to comment.