Skip to content

Commit

Permalink
fix corner case in collapse_vars (#5870)
Browse files Browse the repository at this point in the history
fixes #5869
  • Loading branch information
alexlamsl authored Jun 28, 2024
1 parent 8c5a899 commit 6b23899
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -3327,10 +3327,14 @@ Compressor.prototype.compress = function(node) {
}

function update_symbols(value, node) {
var clear_defined = node instanceof AST_SymbolRef && !node.defined;
var scope = node.scope || find_scope(scanner) || block_scope;
value.walk(new TreeWalker(function(node) {
if (node instanceof AST_BlockScope) return true;
if (node instanceof AST_Symbol) node.scope = scope;
if (node instanceof AST_Symbol) {
if (clear_defined && node instanceof AST_SymbolRef) node.defined = false;
node.scope = scope;
}
}));
}

Expand Down
24 changes: 24 additions & 0 deletions test/compress/collapse_vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -10333,3 +10333,27 @@ issue_1666_undefined_strict: {
}
expect_stdout: true
}

issue_5869: {
options = {
collapse_vars: true,
evaluate: true,
pure_getters: "strict",
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
var a, b, log = console.log;
log();
a.p = 0;
b = a;
log(b);
}
expect: {
var a, log = console.log;
log();
log(void (a.p = 0));
}
expect_stdout: TypeError("Cannot set properties of undefined")
}

0 comments on commit 6b23899

Please sign in to comment.