followup to #717; made `new =>` actually work

This commit is contained in:
satyr 2010-10-12 04:00:57 +09:00
parent 5ed69a5a58
commit f682bf642f
3 changed files with 28 additions and 25 deletions

View File

@ -1342,22 +1342,24 @@
})();
exports.Op = (function() {
Op = (function() {
function Op(_arg, _arg2, _arg3, flip) {
this.second = _arg3;
this.first = _arg2;
this.operator = _arg;
function Op(op, first, second, flip) {
if (first instanceof Value && first.base instanceof ObjectLiteral) {
first = new Parens(first);
} else if (op === 'new') {
if (first instanceof Call) {
return first.newInstance();
}
if (first instanceof Code && first.bound) {
first = new Parens(first);
}
}
Op.__super__.constructor.call(this);
this.operator = this.CONVERSIONS[this.operator] || this.operator;
this.operator = this.CONVERSIONS[op] || op;
(this.first = first).tags.operation = true;
if (second) {
(this.second = second).tags.operation = true;
}
this.flip = !!flip;
if (this.first instanceof Value && this.first.base instanceof ObjectLiteral) {
this.first = new Parens(this.first);
} else if (this.operator === 'new' && this.first instanceof Call) {
return this.first.newInstance();
}
this.first.tags.operation = true;
if (this.second) {
this.second.tags.operation = true;
}
return this;
};
return Op;

View File

@ -1167,16 +1167,17 @@ exports.Op = class Op extends Base
children: ['first', 'second']
constructor: (@operator, @first, @second, flip) ->
constructor: (op, first, second, flip) ->
if first instanceof Value and first.base instanceof ObjectLiteral
first = new Parens first
else if op is 'new'
return first.newInstance() if first instanceof Call
first = new Parens first if first instanceof Code and first.bound
super()
@operator = @CONVERSIONS[@operator] or @operator
@operator = @CONVERSIONS[op] or op
(@first = first ).tags.operation = yes
(@second = second).tags.operation = yes if second
@flip = !!flip
if @first instanceof Value and @first.base instanceof ObjectLiteral
@first = new Parens @first
else if @operator is 'new' and @first instanceof Call
return @first.newInstance()
@first.tags.operation = yes
@second.tags.operation = yes if @second
isUnary: ->
not @second

View File

@ -258,9 +258,9 @@ ok new Date().constructor is Date
#717: `new` works against bare function
me = this
new -> ok this isnt me
new => ok this is me
eq Date, new ->
eq this, new => this
Date
#751: Implicit objects with number arguments.