diff --git a/lib/nodes.js b/lib/nodes.js index 111b68dd..7607f4f7 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -1668,6 +1668,9 @@ if ((op === 'new' || op === 'typeof' || op === 'delete') || (op === '+' || op === '-') && this.first instanceof Op && this.first.operator === op) { parts.push(' '); } + if (op === 'new' && this.first.isStatement(o)) { + this.first = new Parens(this.first); + } parts.push(this.first.compile(o, LEVEL_OP)); if (this.flip) { parts.reverse(); diff --git a/src/nodes.coffee b/src/nodes.coffee index 088da48d..eef62cc6 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -1309,6 +1309,7 @@ exports.Op = class Op extends Base parts = [op = @operator] parts.push ' ' if op in ['new', 'typeof', 'delete'] or op in ['+', '-'] and @first instanceof Op and @first.operator is op + @first = new Parens @first if op is 'new' and @first.isStatement o parts.push @first.compile o, LEVEL_OP parts.reverse() if @flip parts.join '' diff --git a/test/function_invocation.coffee b/test/function_invocation.coffee index fe5bdbd5..de43d015 100644 --- a/test/function_invocation.coffee +++ b/test/function_invocation.coffee @@ -364,3 +364,8 @@ test "don't wrap \"pure\" statements in a closure", -> for item in items return item if item is nonce eq nonce, fn items + +#### Unusual `new` Usage + +test "usage of `new` is careful about where the invocation parens end up", -> + ok 'object' is typeof new try Array