aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-07-07 15:45:24 +0100
committerGitHub <noreply@github.com>2021-07-07 22:45:24 +0800
commit2340feff875eb4b32e95abfe7526dede72ba2253 (patch)
tree2e6f666d5d908e4b47fb34649c6a74c85abe53a3
parent0c48b84540d0a19c41ecdb48c2ad5ea4c31c5acc (diff)
downloadtracifyjs-2340feff875eb4b32e95abfe7526dede72ba2253.tar.gz
tracifyjs-2340feff875eb4b32e95abfe7526dede72ba2253.zip
support destructured shorthand for default parameters (#5059)
closes #4990
-rw-r--r--lib/output.js14
-rw-r--r--test/compress/default-values.js6
2 files changed, 16 insertions, 4 deletions
diff --git a/lib/output.js b/lib/output.js
index 33a1b6c8..c57ff2ed 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -1629,7 +1629,19 @@ function OutputStream(options) {
var self = this;
var key = print_property_key(self, output);
var value = self.value;
- if (key && value instanceof AST_SymbolDeclaration && key == get_symbol_name(value)) return;
+ if (key) {
+ if (value instanceof AST_DefaultValue) {
+ if (value.name instanceof AST_Symbol && key == get_symbol_name(value.name)) {
+ output.space();
+ output.print("=");
+ output.space();
+ value.value.print(output);
+ return;
+ }
+ } else if (value instanceof AST_Symbol) {
+ if (key == get_symbol_name(value)) return;
+ }
+ }
output.colon();
value.print(output);
});
diff --git a/test/compress/default-values.js b/test/compress/default-values.js
index ec6a4ea5..b3662715 100644
--- a/test/compress/default-values.js
+++ b/test/compress/default-values.js
@@ -70,7 +70,7 @@ object_shorthand_assign: {
({ a = "PASS" } = 42);
console.log(a);
}
- expect_exact: '({a:a="PASS"}=42);console.log(a);'
+ expect_exact: '({a="PASS"}=42);console.log(a);'
expect_stdout: "PASS"
node_version: ">=6"
}
@@ -80,7 +80,7 @@ object_shorthand_declaration: {
var { a = "PASS" } = 42;
console.log(a);
}
- expect_exact: 'var{a:a="PASS"}=42;console.log(a);'
+ expect_exact: 'var{a="PASS"}=42;console.log(a);'
expect_stdout: "PASS"
node_version: ">=6"
}
@@ -91,7 +91,7 @@ object_shorthand_function: {
console.log(a);
})(42);
}
- expect_exact: '(function({a:a="PASS"}){console.log(a)})(42);'
+ expect_exact: '(function({a="PASS"}){console.log(a)})(42);'
expect_stdout: "PASS"
node_version: ">=6"
}