fix corner case in `inline` (#5115)
authorAlex Lam S.L <alexlamsl@gmail.com>
Wed, 18 Aug 2021 07:57:08 +0000 (08:57 +0100)
committerGitHub <noreply@github.com>
Wed, 18 Aug 2021 07:57:08 +0000 (15:57 +0800)
fixes #5114

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

index e61954c..3ffb4a1 100644 (file)
@@ -9980,6 +9980,7 @@ merge(Compressor.prototype, {
                 operator: "=",
                 left: make_node(AST_DestructuredArray, self, {
                     elements: fn.argnames.map(function(argname) {
+                        if (argname.__unused) return make_node(AST_Hole, argname);
                         return argname.convert_symbol(AST_SymbolRef, process);
                     }),
                     rest: fn.rest && fn.rest.convert_symbol(AST_SymbolRef, process),
index 879e952..6716f9e 100644 (file)
@@ -3057,3 +3057,71 @@ issue_5087_2: {
     expect_stdout: "PASS"
     node_version: ">=6"
 }
+
+issue_5114_1: {
+    options = {
+        inline: true,
+        unused: true,
+    }
+    input: {
+        var a = "PASS";
+        (function({}, a) {})(42);
+        console.log(a);
+    }
+    expect: {
+        var a = "PASS";
+        [ {} ] = [ 42 ],
+        void 0;
+        console.log(a);
+    }
+    expect_stdout: "PASS"
+    node_version: ">=6"
+}
+
+issue_5114_2: {
+    options = {
+        inline: true,
+        pure_getters: "strict",
+        reduce_vars: true,
+        side_effects: true,
+        unused: true,
+    }
+    input: {
+        var a = "PASS";
+        (function f([], a) {
+            f.length;
+        })([]);
+        console.log(a);
+    }
+    expect: {
+        var a = "PASS";
+        0;
+        console.log(a);
+    }
+    expect_stdout: "PASS"
+    node_version: ">=6"
+}
+
+issue_5114_3: {
+    options = {
+        inline: true,
+        pure_getters: "strict",
+        reduce_vars: true,
+        side_effects: true,
+        unused: true,
+    }
+    input: {
+        var a = "PASS";
+        (function f(a, {}) {
+            f.length;
+        })(null, 42);
+        console.log(a);
+    }
+    expect: {
+        var a = "PASS";
+        0;
+        console.log(a);
+    }
+    expect_stdout: "PASS"
+    node_version: ">=6"
+}