Fix bad parsing of `new new x()()` constructs
authorRichard van Velzen <rvanvelzen@experty.com>
Thu, 6 Aug 2015 19:27:46 +0000 (21:27 +0200)
committerMihai Bazon <mihai.bazon@gmail.com>
Thu, 27 Aug 2015 09:29:36 +0000 (12:29 +0300)
Fixes #739

lib/parse.js
test/compress/new.js [new file with mode: 0644]

index ab72ad2..496a673 100644 (file)
@@ -1114,7 +1114,7 @@ function parse($TEXT, options) {
         });
     };
 
-    var new_ = function() {
+    var new_ = function(allow_calls) {
         var start = S.token;
         expect_token("operator", "new");
         var newexp = expr_atom(false), args;
@@ -1129,7 +1129,7 @@ function parse($TEXT, options) {
             expression : newexp,
             args       : args,
             end        : prev()
-        }), true);
+        }), allow_calls);
     };
 
     function as_atom_node() {
@@ -1173,7 +1173,7 @@ function parse($TEXT, options) {
 
     var expr_atom = function(allow_calls) {
         if (is("operator", "new")) {
-            return new_();
+            return new_(allow_calls);
         }
         var start = S.token;
         if (is("punc")) {
diff --git a/test/compress/new.js b/test/compress/new.js
new file mode 100644 (file)
index 0000000..4b2c51c
--- /dev/null
@@ -0,0 +1,12 @@
+new_statement: {
+    input: {
+        new x(1);
+        new x(1)(2);
+        new x(1)(2)(3);
+        new new x(1);
+        new new x(1)(2);
+        new (new x(1))(2);
+        (new new x(1))(2);
+    }
+    expect_exact: "new x(1);new x(1)(2);new x(1)(2)(3);new new x(1);new new x(1)(2);new new x(1)(2);(new new x(1))(2);"
+}