fix corner case in collapse_vars (#4445)

fixes #4444
This commit is contained in:
Alex Lam S.L
2020-12-24 02:56:22 +00:00
committed by GitHub
parent 6988cd9558
commit 5f269cd573
3 changed files with 36 additions and 4 deletions

View File

@@ -638,6 +638,8 @@ to be `false` and all symbol names will be omitted.
- `dead_code` (default: `true`) -- remove unreachable code
- `default_values` (default: `true`) -- drop overshadowed default values
- `directives` (default: `true`) -- remove redundant or non-standard directives
- `drop_console` (default: `false`) -- Pass `true` to discard calls to

View File

@@ -1814,16 +1814,22 @@ merge(Compressor.prototype, {
}
if (!(fn instanceof AST_Lambda)) return true;
if (def && recursive_ref(compressor, def)) return true;
if (!all(fn.argnames, function(argname) {
return !(argname instanceof AST_Destructured);
})) return true;
if (fn.collapse_scanning) return false;
fn.collapse_scanning = true;
var replace = can_replace;
can_replace = false;
var after = stop_after;
var if_hit = stop_if_hit;
if (fn instanceof AST_Arrow && fn.value) {
if (!all(fn.argnames, function(argname) {
if (argname instanceof AST_DefaultValue) {
argname.value.transform(scanner);
if (abort) return false;
argname = argname.name;
}
return !(argname instanceof AST_Destructured);
})) {
abort = true;
} else if (fn instanceof AST_Arrow && fn.value) {
fn.value.transform(scanner);
} else for (var i = 0; !abort && i < fn.body.length; i++) {
var stat = fn.body[i];

View File

@@ -950,3 +950,27 @@ mangle_arrow_2_toplevel: {
expect_stdout: "PASS"
node_version: ">=6"
}
issue_4444: {
options = {
collapse_vars: true,
}
input: {
var a = "PASS";
console.log(function(b) {
b = a;
(function(c = b.p) {})();
return a;
}());
}
expect: {
var a = "PASS";
console.log(function(b) {
b = a;
(function(c = b.p) {})();
return a;
}());
}
expect_stdout: "PASS"
node_version: ">=6"
}