swc
swc copied to clipboard
`es/minifier`: Unnecessary variable when inlining
Describe the feature
function square(x) {
return x * x;
}
function cube(x) {
return square(x) * x;
}
console.log(cube(a));
Produces:
var x, x1;
console.log((x1 = x = a) * x1 * x);
x1 is unnecessary here.
Weirdly enough, when enabling mangling x1 gets renamed to x which looks funny:
var x, x;
console.log((x = x = a) * x * x);
There may be some scoping issues with inlining which causes this (incorrect?) mangling behavior.
Babel plugin or link to the feature description
https://play.swc.rs/?version=1.11.18&code=H4sIAAAAAAAAA0srzUsuyczPUyguLE0sStWo0FSo5lJQKEotKS3KU6hQ0FKosOaq5eJKg6lLLk1CV4XQClWdnJ9XnJ%2BTqpeTn64BVp%2BoqWkNAMwliaVqAAAA&config=H4sIAAAAAAAAA32US3LbMAyG9zmFR%2Bts00UP0F3PwKFFUGYqEhoCdKzJ%2BO4F9bCdGMxOxAcI5I%2FH58vh0L1T3%2F0%2BfMqnHCabCfLtLBaaE9uLWDqeJ6A%2Bh4m7150yVeTtSLCYrivp2OYBuEYBvW3u3YhIsLtvthhS8PNjwh7jlIHowSZW%2BV%2BJkLiaORd4fUQZPxT7EXEEm34gxpIJiWGArHj1OI52IjBnq%2BMoagVCLUOFhcGZKeOk8uQCB0wixTN1YJ3p0YGCQoaewxm0MMklYYnkdV9lvmMHxzIMS4m%2FRcPZjsWykhMuS0Hkts%2FshIHY%2BLKI8D3jChsSrFDXNniTgUtWEr5jSI2ofwDy%2FtESJRtBu9Di4aWXWtH%2Bx8iQvLQrzwqX3tYemWAQSU0IXtG1CgOZg1bLDK70UIXt21SXgYIDA95Ln2j0I3B%2F0lLW%2BUavACmu1e6%2F2k1r%2FjZcR6FN%2F8gDWe2szSFaPjUhzfGI2gTtwcAndG0uFWBs0iyL4TI1cUkOpB%2FAaR6FNHsdTjaMZlyW41M%2FyETID80w4vG%2BGDaH623pRpuG%2B4Sve%2Fdlc%2BgiurLAbaPXqq57%2BFd3d9q37q2Nu0B%2F98gl6fU%2FUub13x0GAAA%3D
Additional context
No response
another note: thanks to the "Acesssing top-level identifiers do not have side effects." assumption, there should be no need for an intermediate variable at all, but that's another issue.
@kdy1 we have is_unresolved_ref_safe in every part of minifier. I believe the documented assumption is wrong for this.
@Austaras Do we need additional assumptions?
I believe current ones are enough.
Oh we still need to fix mangle
And the mangle issue is because playground set mangle.top_level to false. Using mangle: true would solve this issue.
It still has unnecessary variable, no?
var o, l;
console.log((l = o = a) * l * o);
Although this applies generally, so may be a different transform.
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.