Skip to content

Commit

Permalink
support destructured shorthand for default parameters (#5059)
Browse files Browse the repository at this point in the history
closes #4990
  • Loading branch information
alexlamsl committed Jul 7, 2021
1 parent 0c48b84 commit 2340fef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 13 additions & 1 deletion lib/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
6 changes: 3 additions & 3 deletions test/compress/default-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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"
}
Expand All @@ -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"
}
Expand Down

0 comments on commit 2340fef

Please sign in to comment.