From e3454ed7fb9bf8a55085b1428c7955d2221f6026 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Tue, 15 May 2012 12:30:51 -0400 Subject: [PATCH] Fixes #2331 -- bound 'super' regression --- lib/coffee-script/nodes.js | 5 +++-- src/nodes.coffee | 3 ++- test/scope.coffee | 18 +++++++++++++++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/coffee-script/nodes.js b/lib/coffee-script/nodes.js index 67b0599f..7255f21d 100644 --- a/lib/coffee-script/nodes.js +++ b/lib/coffee-script/nodes.js @@ -821,8 +821,9 @@ }; Call.prototype.superThis = function(o) { - var _ref2; - return ((_ref2 = o.scope.method) != null ? _ref2.context : void 0) || "this"; + var method; + method = o.scope.method; + return (method && !method.klass && method.context) || "this"; }; Call.prototype.unfoldSoak = function(o) { diff --git a/src/nodes.coffee b/src/nodes.coffee index 37120920..1573ac55 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -525,7 +525,8 @@ exports.Call = class Call extends Base # The appropriate `this` value for a `super` call. superThis : (o) -> - o.scope.method?.context or "this" + method = o.scope.method + (method and not method.klass and method.context) or "this" # Soaked chained invocations unfold into if/else ternary structures. unfoldSoak: (o) -> diff --git a/test/scope.coffee b/test/scope.coffee index 1847f11d..e1709a47 100644 --- a/test/scope.coffee +++ b/test/scope.coffee @@ -67,28 +67,40 @@ test "#1183: super + fat arrows", -> @_i += 2 super cb - b = new B() + b = new B b.foo => eq b._i, 3 test "#1183: super + wrap", -> class A m : -> 10 + class B extends A constructor : -> super + B::m = -> r = try super() - eq (new B()).m(), 10 + + eq (new B).m(), 10 test "#1183: super + closures", -> class A constructor: -> @i = 10 foo : -> @i + class B extends A foo : -> ret = switch 1 when 0 then 0 when 1 then super() ret - eq (new B()).foo(), 10 + eq (new B).foo(), 10 +test "#2331: bound super regression", -> + class A + @value = 'A' + method: -> @constructor.value + + class B extends A + method: => super + eq (new B).method(), 'A' \ No newline at end of file