mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Closes #973. New is more careful around the do construct.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 -> ->
|
||||
|
||||
Reference in New Issue
Block a user