1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

Fixes #2331 -- bound 'super' regression

This commit is contained in:
Jeremy Ashkenas 2012-05-15 12:30:51 -04:00
parent 8dcbe54e55
commit e3454ed7fb
3 changed files with 20 additions and 6 deletions

View file

@ -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) {

View file

@ -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) ->

View file

@ -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'