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:
parent
18a1e01d64
commit
dc6bd715b2
3 changed files with 9 additions and 0 deletions
|
@ -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();
|
||||
|
|
|
@ -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 ''
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue