1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

Closes #970. Statements that use new are wrapped in parens to avoid the closure being used.

This commit is contained in:
Timothy Jones 2011-01-22 23:11:00 +13:00
parent 18a1e01d64
commit dc6bd715b2
3 changed files with 9 additions and 0 deletions

View file

@ -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();

View file

@ -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 ''

View file

@ -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