erikdesjardins / babel-plugin-transform-dead-code-elimination

Babel 6 fork of babel-plugin-dead-code-elimination.
https://www.npmjs.com/package/babel-plugin-transform-dead-code-elimination
MIT License
8 stars 4 forks source link

With babel-traverse@6.10.4, erroneously eliminates some if statements #16

Closed erikdesjardins closed 8 years ago

erikdesjardins commented 8 years ago

For example (from graphql-js):

var MAX_INT = 2147483647;
var MIN_INT = -2147483648;
function coerceInt(value) {
  var num = Number(value);
  if (num === num && num <= MAX_INT && num >= MIN_INT) {
    return (num < 0 ? Math.ceil : Math.floor)(num);
  }
  return null;
}

becomes:

var MAX_INT = 2147483647;
var MIN_INT = -2147483648;
function coerceInt(value) {
  var num = Number(value);
  return null;
}

Not yet sure if it's a bug with this transform or Babel itself. Will be fixed by https://github.com/babel/babel/pull/3557