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

when WhileStatement replaced by ForStatement, the Identifier in ForStatement.test is conflict with mangled vars #822

Closed
fishbar opened this issue Apr 24, 2018 · 2 comments · Fixed by #830
Labels
bug Confirmed bug has PR Has an open PR that fixes this issue
Milestone

Comments

@fishbar
Copy link

fishbar commented Apr 24, 2018

babel-core: 6.26.0
babel-preset-minify: 0.4.0
default config

Input Code

here is the code fragment from D3.js

function d3_svg_line(projection) {
  var x = d3_geom_pointX, y = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
  function line(data) {
    var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x);
    function segment() {
      segments.push("M", interpolate(projection(points), tension));
    }
    while (++i < n) {
      if (defined.call(this, d = data[i], i)) {
        points.push([ +fx.call(this, d, i)]);
      } else if (points.length) {
        segment();
        points = [];
      }
    }
    if (points.length) segment();
    return segments.length ? segments.join("") : null;
  }
  return line;
}

Actual Output

for human reading, i'v beautify the minified code and add comment it

function a(a) {
  var b = d3_geom_pointX,
    c = d3_geom_pointY,
    e = d3_true,
    d = d3_svg_lineLinear,
    f = d.key;
  return function(c) {
    function f() {
      /** BUG: the Identifier d is defined at the top function scope **/
      h.push("M", d(a(j), .7))
    }
   /**
     * BUG:  but the Identifier d is re-defined at the ForStatment.test,  conflict
     */
    for (var g, h = [], j = [], d = -1, i = c.length, k = d3_functor(b); ++d < i;) e.call(this, g = c[d], d) ? j.push([+k.call(this, g, d)]) : j.length && (f(), j = []);
    return j.length && f(), h.length ? h.join("") : null
  }
}

Details

it seems #713 miss this case.

when rollback to babel-preset-minify:0.2.0 or 0.3.0, everything goes fine.

when i disable mangle, the output seems work fine

does it possible to force mangle after simplify?

@fishbar
Copy link
Author

fishbar commented Apr 26, 2018

ping @boopathi

@mntnoe
Copy link

mntnoe commented Apr 26, 2018

We are experiencing a similar issue for the hoist-non-react-statics package. In the exported function, a variable from outside is reused/reassigned in the for loop, which make subsequent calls fail. Downgrading to 0.3.0 as a workaround for now.

@boopathi boopathi added the bug Confirmed bug label May 1, 2018
@boopathi boopathi added this to the 1.0 milestone May 2, 2018
@boopathi boopathi added the has PR Has an open PR that fixes this issue label May 2, 2018
boopathi added a commit that referenced this issue May 3, 2018
…830)

* fix: do not update references for constant violations renaming

fix #822

* add constant violations to references in mangler collect phase
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug has PR Has an open PR that fixes this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants