Fix #569
authorRichard van Velzen <rvanvelzen1@gmail.com>
Thu, 23 Oct 2014 13:57:12 +0000 (15:57 +0200)
committerRichard van Velzen <rvanvelzen1@gmail.com>
Sun, 4 Jan 2015 12:37:59 +0000 (13:37 +0100)
When no arguments are given to `new Function()`, it should be treated as
a regular anonymous function (http://es5.github.io/#x15.3.2.1)

lib/compress.js

index f803072..2c95099 100644 (file)
@@ -1722,6 +1722,11 @@ merge(Compressor.prototype, {
                     }).transform(compressor);
                     break;
                   case "Function":
+                    // new Function() => function(){}
+                    if (self.args.length == 0) return make_node(AST_Function, self, {
+                        argnames: [],
+                        body: []
+                    });
                     if (all(self.args, function(x){ return x instanceof AST_String })) {
                         // quite a corner-case, but we can handle it:
                         //   https://github.com/mishoo/UglifyJS2/issues/203