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() { exports.Op = (function() {
Op = (function() { Op = (function() {
function Op(_arg, _arg2, _arg3, flip) { function Op(op, first, second, flip) {
this.second = _arg3; if (first instanceof Value && first.base instanceof ObjectLiteral) {
this.first = _arg2; first = new Parens(first);
this.operator = _arg; } 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); 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; 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 this;
}; };
return Op; return Op;

View File

@@ -1167,16 +1167,17 @@ exports.Op = class Op extends Base
children: ['first', 'second'] 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() 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 @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: -> isUnary: ->
not @second not @second

View File

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