fix another small regression
authorMihai Bazon <mihai@bazon.net>
Wed, 7 Nov 2012 11:31:43 +0000 (13:31 +0200)
committerMihai Bazon <mihai@bazon.net>
Wed, 7 Nov 2012 11:31:43 +0000 (13:31 +0200)
we do need parens here: `new (foo.bar().baz)`, but not here: `new foo.bar.baz`

lib/output.js

index ad4690d..7309737 100644 (file)
@@ -470,7 +470,22 @@ function OutputStream(options) {
 
     PARENS(AST_PropAccess, function(output){
         var p = output.parent();
-        return p instanceof AST_New && p.expression === this;
+        if (p instanceof AST_New && p.expression === this) {
+            // i.e. new (foo.bar().baz)
+            //
+            // if there's one call into this subtree, then we need
+            // parens around it too, otherwise the call will be
+            // interpreted as passing the arguments to the upper New
+            // expression.
+            try {
+                this.walk(new TreeWalker(function(node){
+                    if (node instanceof AST_Call) throw p;
+                }));
+            } catch(ex) {
+                if (ex !== p) throw ex;
+                return true;
+            }
+        }
     });
 
     PARENS(AST_Call, function(output){