Closes #973. New is more careful around the do construct.

This commit is contained in:
Timothy Jones
2011-01-22 23:26:38 +13:00
parent dc6bd715b2
commit 2ca108820f
3 changed files with 14 additions and 7 deletions

View File

@@ -1550,17 +1550,20 @@
var CONVERSIONS, INVERSIONS;
__extends(Op, Base);
function Op(op, first, second, flip) {
var call;
if (op === 'in') {
return new In(first, second);
}
if (op === 'do') {
return new Call(first, first.params || []);
call = new Call(first, first.params || []);
call["do"] = true;
return call;
}
if (op === 'new') {
if (first instanceof Call) {
if (first instanceof Call && !first["do"]) {
return first.newInstance();
}
if (first instanceof Code && first.bound) {
if (first instanceof Code && first.bound || first["do"]) {
first = new Parens(first);
}
}

View File

@@ -1212,10 +1212,13 @@ exports.While = class While extends Base
exports.Op = class Op extends Base
constructor: (op, first, second, flip) ->
return new In first, second if op is 'in'
return new Call first, first.params or [] if op is 'do'
if op is 'do'
call = new Call first, first.params or []
call.do = yes
return call
if op is 'new'
return first.newInstance() if first instanceof Call
first = new Parens first if first instanceof Code and first.bound
return first.newInstance() if first instanceof Call and not first.do
first = new Parens first if first instanceof Code and first.bound or first.do
@operator = CONVERSIONS[op] or op
@first = first
@second = second

View File

@@ -368,4 +368,5 @@ test "don't wrap \"pure\" statements in a closure", ->
#### Unusual `new` Usage
test "usage of `new` is careful about where the invocation parens end up", ->
ok 'object' is typeof new try Array
eq 'object', typeof new try Array
eq 'object', typeof new do -> ->