uglifier icon indicating copy to clipboard operation
uglifier copied to clipboard

Incorrect JS with with multiple passes

Open deepfryed opened this issue 7 years ago • 6 comments

The defaults in README indicate that the compress passes is set to 1 by default, while the code has a different value.

https://github.com/lautis/uglifier/blob/master/lib/uglifier.rb#L83

This potentially an issue with UglifyJS, I have a problem where using multiple pass option tends to insert a trailing comma in for loop as below (perhaps due to incorrect loop optimization ?)

for(i=b.K,K-=i.col1.x*k+i.col2.x*z,W-=i.col1.y*k+i.col2.y*z,;;)

Source

for (;;) {
  tMat = c.normalMass;
  var xX = -(tMat.col1.x * bX + tMat.col2.x * bY);
  var xY = -(tMat.col1.y * bX + tMat.col2.y * bY);

deepfryed avatar Mar 02 '17 21:03 deepfryed

Thanks for reporting. That wasn't intentional, I'll fix the default.

lautis avatar Mar 02 '17 21:03 lautis

Fixed in https://github.com/lautis/uglifier/commit/50e8620daf75e5913a1f2336b5b274c4d07517ef, released as 3.1.3.

lautis avatar Mar 02 '17 21:03 lautis

That was quick, appreciate it :+1:

deepfryed avatar Mar 02 '17 21:03 deepfryed

@deepfryed could you post a more complete example? When I try to reproduce the example, for loop seems to be left as-is.

lautis avatar Mar 02 '17 21:03 lautis

Ran into this when precompiling Box2d at work

https://github.com/babyzone2004/tank/blob/master/box2d/src/Box2dweb.js

deepfryed avatar Mar 02 '17 22:03 deepfryed

Thanks. Indeed a bug in UglifyJS. The same reproduces with curl https://raw.githubusercontent.com/babyzone2004/tank/master/box2d/src/Box2dweb.js | uglifyjs -c passes=2 -m > box2dweb.min.js. Running UglifyJS twice does not lead to the corruption, though.

lautis avatar Mar 02 '17 22:03 lautis