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] Unreachable code not removed after If/Else #844

Closed
tobymao opened this issue Feb 19, 2021 · 4 comments
Closed

[Bug] Unreachable code not removed after If/Else #844

tobymao opened this issue Feb 19, 2021 · 4 comments

Comments

@tobymao
Copy link

tobymao commented Feb 19, 2021

var test = function(x) { if (x == 1 ) {
    return "a"
  } else {
    return "b"
  }

  return null;
}

test(1)

esbuild a.js --minify

var test=function(r){if(r==1)return"a";return"b";return null};test(1);

esbuild a.js --minify --bundle

(()=>{var e=function(r){if(r==1)return"a";return"b";return null};e(1);})();

In both cases, --minify should remove the final return null because it is unreachable.

@evanw
Copy link
Owner

evanw commented Feb 19, 2021

Huh, yeah that looks like a bug. Seems like it'll be easy to fix.

@evanw evanw closed this as completed in d7eb896 Feb 19, 2021
@evanw
Copy link
Owner

evanw commented Feb 19, 2021

The next release will generate this code:

var test=function(r){return r==1?"a":"b"};test(1);

@tobymao
Copy link
Author

tobymao commented Feb 19, 2021

Wow amazingly quick fix. Will this work without bundle as well? I don't use --bundle in my app.

@evanw
Copy link
Owner

evanw commented Feb 19, 2021

Yeah this shouldn’t depend on the bundle setting.

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

Successfully merging a pull request may close this issue.

2 participants