fix corner case in collapse_vars (#5870)

fixes #5869
This commit is contained in:
Alex Lam S.L
2024-06-28 21:19:58 +03:00
committed by GitHub
parent 8c5a899986
commit 6b23899ef3
2 changed files with 29 additions and 1 deletions

View File

@@ -3327,10 +3327,14 @@ Compressor.prototype.compress = function(node) {
} }
function update_symbols(value, node) { function update_symbols(value, node) {
var clear_defined = node instanceof AST_SymbolRef && !node.defined;
var scope = node.scope || find_scope(scanner) || block_scope; var scope = node.scope || find_scope(scanner) || block_scope;
value.walk(new TreeWalker(function(node) { value.walk(new TreeWalker(function(node) {
if (node instanceof AST_BlockScope) return true; 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;
}
})); }));
} }

View File

@@ -10333,3 +10333,27 @@ issue_1666_undefined_strict: {
} }
expect_stdout: true 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")
}