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

Reapply the removed patch from bugfix_1183 in PR 2252. Include a test

case to show it's required.

What's going on: inside of Coffee-generated closures, calling `super()`
is implicitly making use of `this` (or explicitly doing so if you look
at the output code), so we have to pass `this` through closures as if
`@` is being accessed within the closure.  So, just add one more
condition to the list in `Closure::literalThis`
This commit is contained in:
Maxwell Krohn 2012-04-24 21:48:18 -04:00
parent c3159e48c8
commit 3e95d7f2d0
3 changed files with 17 additions and 2 deletions

View file

@ -2846,7 +2846,7 @@
return node instanceof Literal && node.value === 'arguments' && !node.asKey;
},
literalThis: function(node) {
return (node instanceof Literal && node.value === 'this' && !node.asKey) || (node instanceof Code && node.bound);
return (node instanceof Literal && node.value === 'this' && !node.asKey) || (node instanceof Code && node.bound) || (node instanceof Call && node.isSuper);
}
};

View file

@ -1931,7 +1931,8 @@ Closure =
literalThis: (node) ->
(node instanceof Literal and node.value is 'this' and not node.asKey) or
(node instanceof Code and node.bound)
(node instanceof Code and node.bound) or
(node instanceof Call and node.isSuper)
# Unfold a node's child if soak, then tuck the node under created `If`
unfoldSoak = (o, parent, name) ->

View file

@ -77,4 +77,18 @@ test "#1183: super + wrap", ->
constructor : -> super
B::m = -> r = try super()
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