fix corner case in `reduce_vars` (#4281)
authorAlex Lam S.L <alexlamsl@gmail.com>
Tue, 17 Nov 2020 04:59:44 +0000 (04:59 +0000)
committerGitHub <noreply@github.com>
Tue, 17 Nov 2020 04:59:44 +0000 (12:59 +0800)
fixes #4280

lib/compress.js
test/compress/destructured.js

index 7297938..a16c9a6 100644 (file)
@@ -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
                             });
index 01b2456..169bfb7 100644 (file)
@@ -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"
+}