Skip to content

Commit

Permalink
drop undefined default parameter in IIFE. Closes #1366
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiosantoscode committed Apr 17, 2023
1 parent 31753d0 commit 0ddf63a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
21 changes: 14 additions & 7 deletions lib/compress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2782,13 +2782,20 @@ def_optimize(AST_DefaultAssign, function(self, compressor) {

// `[x = undefined] = foo` ---> `[x] = foo`
// `(arg = undefined) => ...` ---> `(arg) => ...` (unless `keep_fargs`)
if (
evaluateRight === undefined &&
(compressor.parent() instanceof AST_Lambda
? compressor.option("keep_fargs") === false
: true)
) {
self = self.left;
// `((arg = undefined) => ...)()` ---> `((arg) => ...)()`
let lambda, iife;
if (evaluateRight === undefined) {
if (
(lambda = compressor.parent()) instanceof AST_Lambda
? (
compressor.option("keep_fargs") === false
|| (iife = compressor.parent(1)).TYPE === "Call"
&& iife.expression === lambda
)
: true
) {
self = self.left;
}
} else if (evaluateRight !== self.right) {
evaluateRight = make_node_from_constant(evaluateRight, self.right);
self.right = best_of_expression(evaluateRight, self.right);
Expand Down
15 changes: 14 additions & 1 deletion test/compress/parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,24 @@ keep_default_arg_when_undefined: {
console.log(x.length)
}
expect: {
function x(a = undefined) { }
function x(a = void 0) { }
console.log(x.length)
}
}

drop_default_arg_when_undefined_and_iife: {
options = {
keep_fargs: true,
evaluate: true,
}
input: {
console.log((function x(a = void 0) { })())
}
expect: {
console.log((function x(a) { })())
}
}

default_values_in_destructurings: {
beautify = {
ecma: 2015
Expand Down

0 comments on commit 0ddf63a

Please sign in to comment.