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

Dead code after return statment isn't removed during minification #580

Closed
fa93hws opened this issue Dec 6, 2020 · 1 comment
Closed

Comments

@fa93hws
Copy link

fa93hws commented Dec 6, 2020

/* eslint-disable */
function spyReport(event) {
  if (true) return;
  if (!globalState.spyListeners.length) return;
  const listeners = globalState.spyListeners;
  for (let i = 0, l = listeners.length; i < l; i++) {
    listeners[i](event);
  }
}

spyReport(asdf);

is minified to

(()=>{function n(s){return;if(!globalState.spyListeners.length)return;for(let e=0,l=t.length;e<l;e++)t[e](s)}n(asdf);})();

while it should be

(()=>{function n(s){return;}n(asdf);})();

How to reproduce?

create any.js which have the following content

/* eslint-disable */
function spyReport(event) {
  if (true) return;
  if (!globalState.spyListeners.length) return;
  const listeners = globalState.spyListeners;
  for (let i = 0, l = listeners.length; i < l; i++) {
    listeners[i](event);
  }
}

spyReport(asdf);

build it with esbuild any.js --bundle --minify --outfile=any.dist.js

esbuild version: 0.8.7
node version: v12.16.1
OS: macOS Catalina 10.15.7

@fa93hws fa93hws closed this as completed Dec 6, 2020
@fa93hws fa93hws reopened this Dec 6, 2020
@fa93hws fa93hws closed this as completed Dec 6, 2020
@fa93hws fa93hws reopened this Dec 6, 2020
@evanw
Copy link
Owner

evanw commented Dec 6, 2020

Thanks for the report. It looks like control flow liveness is not propagated to subsequent sibling statements. I'll fix this.

@evanw evanw closed this as completed in 179433f Dec 6, 2020
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

2 participants