-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Labels
Milestone
Description
Describe the feature
Feature Request: Minify and Inline Nested Function Calls
Input Code
const profile = (_s, fn) => {
return fn();
};
profile("trace1", () => {
someFunction({
args1: profile("trace2", () => JSON.stringify(someObj)), // if this line removed, the issue will not reproduce
args2: JSON.stringify(someObj),
})
});
Desired Output
someFunction({
args1: JSON.stringify(someObj),
args2: JSON.stringify(someObj)
});
Actual Output
const s = (s, r)=>r();
s("trace1", ()=>{
someFunction({
args1: s("trace2", ()=>JSON.stringify(someObj)),
args2: JSON.stringify(someObj)
});
});
Summary
Currently, swc does not fully inline and minify code when there are nested calls to a function. It appears that the nested invocation prevents successful inlining, so the minified output still contains the wrapper function. Ideally, the minifier should be able to inline these nested calls when their result is statically determinable and remove the wrappers, resulting in cleaner output.
Babel plugin or link to the feature description
No response
Additional context
It seems that the bug or limitation is caused by nested calls to the profiling function. If the inner profile
call is removed, inlining works as expected. Please investigate improvements to the minifier so that it can handle such nested patterns.