diff options
author | Mihai Bazon <mihai@bazon.net> | 2012-11-07 13:31:43 +0200 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2012-11-07 13:31:43 +0200 |
commit | 46be3f2bf19564a838179f523262f69dc1a9b5ac (patch) | |
tree | f9c482cff64233374169a9a26d680f25d157d212 | |
parent | 258b46f4dc0d3df2cf20c4fbd4f3dd6314977518 (diff) | |
download | tracifyjs-46be3f2bf19564a838179f523262f69dc1a9b5ac.tar.gz tracifyjs-46be3f2bf19564a838179f523262f69dc1a9b5ac.zip |
fix another small regression
we do need parens here: `new (foo.bar().baz)`, but not here: `new foo.bar.baz`
-rw-r--r-- | lib/output.js | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/output.js b/lib/output.js index ad4690d5..7309737f 100644 --- a/lib/output.js +++ b/lib/output.js @@ -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){ |