Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes #2331 -- bound 'super' regression

  • Loading branch information...
commit e3454ed7fb9bf8a55085b1428c7955d2221f6026 1 parent 8dcbe54
@jashkenas authored
View
5 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) {
View
3  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) ->
View
18 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
+
@michaelficarra Collaborator

@jashkenas: You should set either git or your editor to trim trailing whitespace for you automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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'
Please sign in to comment.
Something went wrong with that request. Please try again.