Rich-Harris / butternut

The fast, future-friendly minifier
https://butternut.now.sh
MIT License
1.17k stars 17 forks source link

wrap parameterless new expressions with params (fixes #169) #174

Open anilanar opened 7 years ago

anilanar commented 7 years ago

I mimicked UglifyJS except for the last test case with wrapped new expressions.

For new new X().Y().z

UglifyJS output: new((new X).Y().z) wrong butternut output: (new (new X).Y).z correct

To test it, use the following:

class X { 
  constructor() { 
    this.z = 1; 
    this.Y = class { 
      constructor() { 
        this.z = 2;
      }
    };
  }
}
kzc commented 7 years ago

UglifyJS output: new((new X).Y().z) wrong

Using butternut's copy of uglify-js and uglify-es...

$ node_modules/uglify-js/bin/uglifyjs -V
uglify-js 3.0.9

$ echo 'new new X().Y().z' | node_modules/uglify-js/bin/uglifyjs -b
new (new X().Y)().z;

$ echo 'new new X().Y().z' | node_modules/uglify-js/bin/uglifyjs -cm
(new((new X).Y)).z;
$ node_modules/uglify-es/bin/uglifyjs -V
uglify-es 3.0.9

$ echo 'new new X().Y().z' | node_modules/uglify-es/bin/uglifyjs -b
new (new X().Y)().z;

$ echo 'new new X().Y().z' | node_modules/uglify-es/bin/uglifyjs -cm
(new((new X).Y)).z;
adamdupuis commented 5 years ago

Can this be merged?

anilanar commented 5 years ago

@adamdupuis I think the project is on complete halt.