Skip to content

Commit aea0f25

Browse files
author
Marc Häfner
committed
Fixes #3232 -- Tag all class properties static
(and remove duplicate `context` assigment)
1 parent 138c25f commit aea0f25

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

lib/coffee-script/nodes.js

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,10 @@ exports.Value = class Value extends Base
509509
isSplice: ->
510510
last(@properties) instanceof Slice
511511

512+
looksStatic: (className) ->
513+
@base.value is className and @properties.length and
514+
@properties[0].name?.value isnt 'prototype'
515+
512516
# The value can be unwrapped as its inner node, if there are no attached
513517
# properties.
514518
unwrap: ->
@@ -1036,8 +1040,6 @@ exports.Class = class Class extends Base
10361040
else
10371041
if assign.variable.this
10381042
func.static = yes
1039-
if func.bound
1040-
func.context = name
10411043
else
10421044
assign.variable = new Value(new Literal(name), [(new Access new Literal 'prototype'), new Access base])
10431045
if func instanceof Code and func.bound
@@ -1046,14 +1048,17 @@ exports.Class = class Class extends Base
10461048
assign
10471049
compact exprs
10481050

1049-
# Walk the body of the class, looking for prototype properties to be converted.
1051+
# Walk the body of the class, looking for prototype properties to be converted
1052+
# and tagging static assignments.
10501053
walkBody: (name, o) ->
10511054
@traverseChildren false, (child) =>
10521055
cont = true
10531056
return false if child instanceof Class
10541057
if child instanceof Block
10551058
for node, i in exps = child.expressions
1056-
if node instanceof Value and node.isObject(true)
1059+
if node instanceof Assign and node.variable.looksStatic name
1060+
node.value.static = yes
1061+
else if node instanceof Value and node.isObject(true)
10571062
cont = false
10581063
exps[i] = @addProperties node, name, o
10591064
child.expressions = exps = flatten exps

test/classes.coffee

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,3 +816,15 @@ test "#2949: super in static method with reserved name", ->
816816
@static: -> super
817817

818818
eq Bar.static(), 'baz'
819+
820+
test "#3232: super in static methods (not object-assigned)", ->
821+
class Foo
822+
@baz = -> true
823+
@qux = -> true
824+
825+
class Bar extends Foo
826+
@baz = -> super
827+
Bar.qux = -> super
828+
829+
ok Bar.baz()
830+
ok Bar.qux()

0 commit comments

Comments
 (0)