From f682bf642ffacc6cb223bd8c8698e2534a7b6d30 Mon Sep 17 00:00:00 2001 From: satyr Date: Tue, 12 Oct 2010 04:00:57 +0900 Subject: [PATCH] followup to #717; made `new =>` actually work --- lib/nodes.js | 30 ++++++++++++++++-------------- src/nodes.coffee | 17 +++++++++-------- test/test_functions.coffee | 6 +++--- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/lib/nodes.js b/lib/nodes.js index 6006ac94..93d8d045 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -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; diff --git a/src/nodes.coffee b/src/nodes.coffee index 26221448..eb4b3dfd 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -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 diff --git a/test/test_functions.coffee b/test/test_functions.coffee index e967965b..cd068b64 100644 --- a/test/test_functions.coffee +++ b/test/test_functions.coffee @@ -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.