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

Regression: tree shaking wrong when var declaration+assignment is inside a conditional #2606

Closed
nifgraup opened this issue Dec 20, 2018 · 1 comment

Comments

@nifgraup
Copy link

nifgraup commented Dec 20, 2018

  • Rollup Version: 0.68.1
  • Operating System (or Browser): Linux
  • Node Version: v8.9.3

How Do We Reproduce?

test.js

// example 1
switch (test) {
  case 1:
    var hoisted = true;
  case 2:
    if (hoisted) console.log('Went also through  case 1.');
}

// example 2
if (x) {
  var h2 = true;
}
if (h2) console.log('x is true');

./bin/rollup --format cjs test.js

Expected Behavior

no tree shaking

Actual Behavior

'use strict';

// example 1
switch (test) {
  case 1:

  case 2:
    console.log('Went also through  case 1.');
}
console.log('x is true');

Regression point 187a256

@nifgraup nifgraup changed the title Regression: tree shaking wrong when variable hoisting is inside conditional statement Regression: tree shaking wrong when var declaration + assignment is inside a conditional statement Dec 20, 2018
@nifgraup nifgraup changed the title Regression: tree shaking wrong when var declaration + assignment is inside a conditional statement Regression: tree shaking wrong when var declaration+assignment is inside a conditional statement Dec 20, 2018
@nifgraup nifgraup changed the title Regression: tree shaking wrong when var declaration+assignment is inside a conditional statement Regression: tree shaking wrong when var declaration+assignment is inside a conditional Dec 20, 2018
lye pushed a commit to lye/rollup that referenced this issue Dec 21, 2018
When hoisting a var, use UNKNOWN_EXPRESSION as the initializer instead
of the actual one. This prevents the initializer from being used during
the optimization step when it hasn't yet been assigned at runtime.
@lye lye mentioned this issue Dec 21, 2018
9 tasks
lye pushed a commit to lye/rollup that referenced this issue Dec 21, 2018
When hoisting a var, use UNKNOWN_EXPRESSION as the initializer instead
of the actual one. This prevents the initializer from being used during
the optimization step when it hasn't yet been assigned at runtime.
@lukastaegert
Copy link
Member

This was fixed via #2607 in Rollup@0.68.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants