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

Incorrect tree-shaking with switch + default #3177

Closed
jbt opened this issue Oct 19, 2019 · 1 comment · Fixed by #3178
Closed

Incorrect tree-shaking with switch + default #3177

jbt opened this issue Oct 19, 2019 · 1 comment · Fixed by #3178

Comments

@jbt
Copy link

jbt commented Oct 19, 2019

  • Rollup Version: 1.25
  • Operating System (or Browser):
  • Node Version:

How Do We Reproduce?

The following code gets aggressively tree-shaken and all the functional parts get removed:

var bar;
switch (foo) {
	default:
		bar = 1;
}

console.log(bar)

REPL version

Expected Behavior

Output code should be pretty much the same as input code

Actual Behavior

Pretty much everything important gets accidentally removed:

'use strict';

switch (foo) {
	}

This is a reduced case of a bug that's causing ReactDOM to break in 1.25 (it's fine with 1.23, and was broken in 1.24 due to #3168) - the functional parts of commitAttachRef get removed: Reduced REPL version. It looks like 1.24 actually treats this behaviour fine - REPL - so perhaps this bug arose out of the fix for #3168.

@lukastaegert
Copy link
Member

Thanks a lot for spotting this. The issue was a simple oversight with weird effects that only showed in very particular situations. To be precise, the switch statement is included due to a side-effect in the condition (in this case because it is an unknown global) at a point where the cases themselves have no side-effect (because the console.log is not yet included) resulting in no code after the switch statement being included, preventing the side-effect (in fact, the statement was treated like a throw). Fix at #3178

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