Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: compound function call unsafe to combine #2619

Closed
unbyte opened this issue Oct 19, 2022 · 1 comment
Closed

bug: compound function call unsafe to combine #2619

unbyte opened this issue Oct 19, 2022 · 1 comment

Comments

@unbyte
Copy link

unbyte commented Oct 19, 2022

see: mishoo/UglifyJS#1631

TL;DR

before

{
    let pc = 0;
    function f(x) {
        pc = 200;
        return 100;
    }
    function x() {
        const t = f();
        pc += t;
        return pc;
    }
    console.log(x());
}

// output: 300

after

{let t=function(c){return n=200,100},o=function(){return n+=t(),n};r=t,e=o;let n=0;console.log(o())}

// output: 100

The reason why this bug was not found before is that the test case uses var instead of let/const, and esbuild skips inlining those variables when meets var.

@unbyte
Copy link
Author

unbyte commented Oct 19, 2022

I'm trying enabling the optimization for vars, so I may have the chance to try to fix this bug.

@evanw evanw closed this as completed in ccc8e8b Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant