From 2340feff875eb4b32e95abfe7526dede72ba2253 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 7 Jul 2021 15:45:24 +0100 Subject: [PATCH] support destructured shorthand for default parameters (#5059) closes #4990 --- lib/output.js | 14 +++++++++++++- test/compress/default-values.js | 6 +++--- 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" }