Fixes #2721, super outside of classes with extends for instance methods.

This commit is contained in:
Jeremy Ashkenas
2013-03-01 13:17:07 +13:00
parent 68718b6938
commit 6b79af2b7c
3 changed files with 17 additions and 14 deletions

View File

@@ -812,8 +812,10 @@
}
accesses.push(new Access(new Literal(name)));
return (new Value(new Literal(method.klass), accesses)).compile(o);
} else {
} else if (method.ctor) {
return "" + name + ".__super__.constructor";
} else {
return "this.constructor.__super__." + name;
}
};

View File

@@ -523,8 +523,10 @@ exports.Call = class Call extends Base
accesses.push new Access new Literal 'constructor' if method.static
accesses.push new Access new Literal name
(new Value (new Literal method.klass), accesses).compile o
else
else if method.ctor
"#{name}.__super__.constructor"
else
"this.constructor.__super__.#{name}"
# The appropriate `this` value for a `super` call.
superThis : (o) ->

View File

@@ -117,24 +117,23 @@ test "basic classes, again, but in the manual prototype style", ->
ok (new ThirdChild)['func-func']('thing') is 'dynamic-thing'
test "super with plain ol' functions as the original constructors", ->
test "super with plain ol' prototypes", ->
TopClass = (arg) ->
@prop = 'top-' + arg
this
TopClass = ->
TopClass::func = (arg) ->
'top-' + arg
SuperClass = (arg) ->
SuperClass = ->
SuperClass extends TopClass
SuperClass::func = (arg) ->
super 'super-' + arg
this
SubClass = ->
super 'sub'
this
SuperClass extends TopClass
SubClass extends SuperClass
SubClass::func = ->
super 'sub'
ok (new SubClass).prop is 'top-super-sub'
eq (new SubClass).func(), 'top-super-sub'
test "'@' referring to the current instance, and not being coerced into a call", ->
@@ -717,4 +716,4 @@ test "#2359: extending native objects that use other typed constructors requires
workingArray = new WorkingArray
ok workingArray instanceof WorkingArray
eq 'yes!', workingArray.method()
eq 'yes!', workingArray.method()