From fcde6109b0138502a445a7571adc810b5b9e68ee Mon Sep 17 00:00:00 2001 From: Richard van Velzen Date: Thu, 6 Aug 2015 21:27:46 +0200 Subject: [PATCH] Fix bad parsing of `new new x()()` constructs Fixes #739 --- lib/parse.js | 6 +++--- test/compress/new.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 test/compress/new.js diff --git a/lib/parse.js b/lib/parse.js index ab72ad2d..496a673f 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -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 index 00000000..4b2c51c3 --- /dev/null +++ b/test/compress/new.js @@ -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);" +} -- 2.34.1