fix corner case in reduce_vars (#4281)

fixes #4280
This commit is contained in:
Alex Lam S.L
2020-11-17 04:59:44 +00:00
committed by GitHub
parent 6dbacb5e3f
commit b9798a01a8
2 changed files with 31 additions and 1 deletions

View File

@@ -619,7 +619,15 @@ merge(Compressor.prototype, {
if (node.key instanceof AST_Node) node.key.walk(tw); if (node.key instanceof AST_Node) node.key.walk(tw);
fixed = function() { fixed = function() {
var key = node.key; var key = node.key;
return make_node(typeof key == "string" ? AST_Dot : AST_Sub, node, { var type = AST_Sub;
if (typeof key == "string") {
if (is_identifier_string(key)) {
type = AST_Dot;
} else {
key = make_node_from_constant(key, node);
}
}
return make_node(type, node, {
expression: save(), expression: save(),
property: key property: key
}); });

View File

@@ -1295,3 +1295,25 @@ fn_name_unused: {
expect_stdout: "PASS" expect_stdout: "PASS"
node_version: ">=6" node_version: ">=6"
} }
issue_4280: {
options = {
evaluate: true,
reduce_vars: true,
toplevel: true,
unsafe: true,
unused: true,
}
input: {
var {
1: a,
} = 2;
console.log(a);
}
expect: {
var {} = 2;
console.log(void 0);
}
expect_stdout: "undefined"
node_version: ">=6"
}