aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-11-17 04:59:44 +0000
committerGitHub <noreply@github.com>2020-11-17 12:59:44 +0800
commitb9798a01a83269a6299d1f1e28d1e8f6d51b5726 (patch)
treeaf939b872916f426d1ffe414988094bb8e893c3f
parent6dbacb5e3f4b3be40fab132575c2e5e3f820b32f (diff)
downloadtracifyjs-b9798a01a83269a6299d1f1e28d1e8f6d51b5726.tar.gz
tracifyjs-b9798a01a83269a6299d1f1e28d1e8f6d51b5726.zip
fix corner case in `reduce_vars` (#4281)
fixes #4280
-rw-r--r--lib/compress.js10
-rw-r--r--test/compress/destructured.js22
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 7297938a..a16c9a69 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -619,7 +619,15 @@ merge(Compressor.prototype, {
if (node.key instanceof AST_Node) node.key.walk(tw);
fixed = function() {
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(),
property: key
});
diff --git a/test/compress/destructured.js b/test/compress/destructured.js
index 01b24563..169bfb7d 100644
--- a/test/compress/destructured.js
+++ b/test/compress/destructured.js
@@ -1295,3 +1295,25 @@ fn_name_unused: {
expect_stdout: "PASS"
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"
+}