Skip to content

Commit f77a98a

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

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

lib/coffeescript/nodes.js

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1755,7 +1755,9 @@ exports.Class = class Class extends Base
17551755
# NOTE Currently, only methods and static methods are valid in ES class initializers.
17561756
# When additional expressions become valid, this method should be updated to handle them.
17571757
addInitializerExpression: (node) ->
1758-
if @validInitializerMethod node
1758+
if node.unwrapAll() instanceof PassthroughLiteral
1759+
node
1760+
else if @validInitializerMethod node
17591761
@addInitializerMethod node
17601762
else
17611763
null

test/classes.coffee

Lines changed: 15 additions & 0 deletions
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)