[Pkg-javascript-commits] [uglifyjs] 11/49: Fix unneeded parens around unary args in new expression.

Jonas Smedegaard dr at jones.dk
Fri Dec 9 11:43:25 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository uglifyjs.

commit fb049d3a81b744a5facf1f032b8b2815c410f178
Author: kzc <zaxxon2011 at gmail.com>
Date:   Sat Jul 23 11:50:44 2016 -0400

    Fix unneeded parens around unary args in new expression.
---
 lib/output.js        |  2 +-
 test/compress/new.js | 25 +++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/lib/output.js b/lib/output.js
index 324f96e..801f751 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -533,7 +533,7 @@ function OutputStream(options) {
     PARENS([ AST_Unary, AST_Undefined ], function(output){
         var p = output.parent();
         return p instanceof AST_PropAccess && p.expression === this
-            || p instanceof AST_New;
+            || p instanceof AST_Call && p.expression === this;
     });
 
     PARENS(AST_Seq, function(output){
diff --git a/test/compress/new.js b/test/compress/new.js
index 78a1026..bdf22b0 100644
--- a/test/compress/new.js
+++ b/test/compress/new.js
@@ -50,3 +50,28 @@ new_with_many_parameters: {
     }
     expect_exact: 'new foo.bar("baz");new x(/123/,456);'
 }
+
+new_constructor_with_unary_arguments: {
+    input: {
+        new x();
+        new x(-1);
+        new x(-1, -2);
+        new x(void 1, +2, -3, ~4, !5, --a, ++b, c--, d++, typeof e, delete f);
+        new (-1);     // should parse despite being invalid at runtime.
+        new (-1)();   // should parse despite being invalid at runtime.
+        new (-1)(-2); // should parse despite being invalid at runtime.
+    }
+    expect_exact: "new x;new x(-1);new x(-1,-2);new x(void 1,+2,-3,~4,!5,--a,++b,c--,d++,typeof e,delete f);new(-1);new(-1);new(-1)(-2);"
+}
+
+call_with_unary_arguments: {
+    input: {
+        x();
+        x(-1);
+        x(-1, -2);
+        x(void 1, +2, -3, ~4, !5, --a, ++b, c--, d++, typeof e, delete f);
+        (-1)();   // should parse despite being invalid at runtime.
+        (-1)(-2); // should parse despite being invalid at runtime.
+    }
+    expect_exact: "x();x(-1);x(-1,-2);x(void 1,+2,-3,~4,!5,--a,++b,c--,d++,typeof e,delete f);(-1)();(-1)(-2);"
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list