Skip to content

Commit 78abc4b

Browse files
committed
fix(es/minifier): fix inlining of hoisted functions in param
1 parent 4848301 commit 78abc4b

File tree

3 files changed

+18
-28
lines changed

3 files changed

+18
-28
lines changed

crates/swc_ecma_minifier/src/compress/optimize/inline.rs

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -317,33 +317,13 @@ impl Optimizer<'_> {
317317
..
318318
} = **usage;
319319
let mut inc_usage = || {
320-
if let Some(i) = match &*init {
321-
// The condition above filters `init` for literals, idents, and arrow
322-
// functions.
323-
Expr::Ident(i) => Some(i),
324-
Expr::Arrow(arr) => match &*arr.body {
325-
BlockStmtOrExpr::Expr(e) => match &**e {
326-
Expr::Call(i) => i.callee.as_expr().and_then(|e| e.as_ident()),
327-
_ => None,
328-
},
329-
BlockStmtOrExpr::BlockStmt(BlockStmt { stmts, .. }) => {
330-
if let &[Stmt::Return(ReturnStmt { arg: Some(arg), .. })] =
331-
&&**stmts
332-
{
333-
match &**arg {
334-
Expr::Call(i) => {
335-
i.callee.as_expr().and_then(|e| e.as_ident())
336-
}
337-
_ => None,
338-
}
339-
} else {
340-
None
341-
}
342-
}
343-
},
344-
_ => None,
345-
} {
346-
if let Some(u) = self.data.vars.get_mut(&i.to_id()) {
320+
for (i, _) in collect_infects_from(
321+
&*init,
322+
AliasConfig::default()
323+
.marks(Some(self.marks))
324+
.need_all(true),
325+
) {
326+
if let Some(u) = self.data.vars.get_mut(&i) {
347327
u.flags |= flags & VarUsageInfoFlags::USED_AS_ARG;
348328
u.flags |= flags & VarUsageInfoFlags::USED_AS_REF;
349329
u.flags |= flags & VarUsageInfoFlags::INDEXED_WITH_DYNAMIC_KEY;

crates/swc_ecma_minifier/tests/fixture/issues/11158/input.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@
77
b = `tmp-${gen()}-b`;
88
console.log(a, b);
99
})();
10+
11+
(() => {
12+
const gen = () => g(foo(12));
13+
function foo(length) {
14+
return length;
15+
}
16+
const a = `tmp-${gen()}-a`,
17+
b = `tmp-${gen()}-b`;
18+
console.log(a, b);
19+
})();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
console.log("tmp-12-a", "tmp-12-b");
1+
console.log("tmp-12-a", "tmp-12-b"), console.log(`tmp-${g(12)}-a`, `tmp-${g(12)}-b`);

0 commit comments

Comments
 (0)