Skip to content

Commit

Permalink
do not inject IIFE's own arguments into the IIFE when they contain `a…
Browse files Browse the repository at this point in the history
…wait`. Closes #1489
  • Loading branch information
fabiosantoscode committed Feb 15, 2024
1 parent d32e177 commit c42d7df
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/compress/tighten-body.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,14 @@ export function tighten_body(statements, compressor) {
return found;
}

function arg_is_injectable(arg) {
if (arg instanceof AST_Expansion) return false;
const contains_await = walk(arg, (node) => {
if (node instanceof AST_Await) return walk_abort;
});
if (contains_await) return false;
return true;
}
function extract_args() {
var iife, fn = compressor.self();
if (is_func_expr(fn)
Expand All @@ -582,7 +590,8 @@ export function tighten_body(statements, compressor) {
&& !fn.pinned()
&& (iife = compressor.parent()) instanceof AST_Call
&& iife.expression === fn
&& iife.args.every((arg) => !(arg instanceof AST_Expansion))) {
&& iife.args.every(arg_is_injectable)
) {
var fn_strict = compressor.has_directive("use strict");
if (fn_strict && !member(fn_strict, fn.body))
fn_strict = false;
Expand Down
14 changes: 14 additions & 0 deletions test/compress/collapse_vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -2124,6 +2124,20 @@ iife_2: {
}
}

iife_async: {
options = { unused: true, collapse_vars: true }
input: {
(async function(s) {
return ((s, a) => s + a)(s, await new Promise(() => {}))
})();
}
expect: {
(async function(s) {
return ((s, a) => s + a)(void 0, await new Promise(() => {}))
})();
}
}

var_defs: {
options = {
booleans: true,
Expand Down

0 comments on commit c42d7df

Please sign in to comment.