mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Fixes #2721, super outside of classes with extends for instance methods.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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) ->
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user