aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-08-18 08:57:08 +0100
committerGitHub <noreply@github.com>2021-08-18 15:57:08 +0800
commitbefb99bd7197d281417d7eb15e0f7b8ed992174d (patch)
treea8d41813ed37331ddc81c21fd48941be4ecc6723
parent02eb8baa1c6c6f1e79a6e01dfe1e3bd68937eedd (diff)
downloadtracifyjs-befb99bd7197d281417d7eb15e0f7b8ed992174d.tar.gz
tracifyjs-befb99bd7197d281417d7eb15e0f7b8ed992174d.zip
fix corner case in `inline` (#5115)
fixes #5114
-rw-r--r--lib/compress.js1
-rw-r--r--test/compress/destructured.js68
2 files changed, 69 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js
index e61954c6..3ffb4a1c 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -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),
diff --git a/test/compress/destructured.js b/test/compress/destructured.js
index 879e9529..6716f9e7 100644
--- a/test/compress/destructured.js
+++ b/test/compress/destructured.js
@@ -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"
+}