Skip to content

Commit 657bdad

Browse files
GeoffreyBoothconnec
authored andcommitted
Fix jashkenas#4464: backticked expressions in class body should go in the initializer
1 parent eb12792 commit 657bdad

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

lib/coffeescript/nodes.js

+3-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

+3-4
Original file line numberDiff line numberDiff line change
@@ -1751,11 +1751,10 @@ exports.Class = class Class extends Base
17511751
new Block expressions
17521752

17531753
# Add an expression to the class initializer
1754-
#
1755-
# NOTE Currently, only methods and static methods are valid in ES class initializers.
1756-
# When additional expressions become valid, this method should be updated to handle them.
17571754
addInitializerExpression: (node) ->
1758-
if @validInitializerMethod node
1755+
if node.unwrapAll() instanceof PassthroughLiteral
1756+
node
1757+
else if @validInitializerMethod node
17591758
@addInitializerMethod node
17601759
else
17611760
null

test/classes.coffee

+15
Original file line numberDiff line numberDiff line change
@@ -1833,3 +1833,18 @@ test "#4591: super.x.y, super['x'].y", ->
18331833
eq 2, b.t
18341834
eq 2, b.s
18351835
eq 2, b.r
1836+
1837+
test "#4464: backticked expressions in class body", ->
1838+
class A
1839+
`get x() { return 42; }`
1840+
1841+
class B
1842+
`get x() { return 42; }`
1843+
constructor: ->
1844+
@y = 84
1845+
1846+
a = new A
1847+
eq 42, a.x
1848+
b = new B
1849+
eq 42, b.x
1850+
eq 84, b.y

0 commit comments

Comments
 (0)