Skip to content

Commit

Permalink
Fix #4464: backticked expressions in class body should go in the init…
Browse files Browse the repository at this point in the history
…ializer
  • Loading branch information
GeoffreyBooth authored and connec committed Sep 20, 2017
1 parent eb12792 commit f77a98a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/coffeescript/nodes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1755,7 +1755,9 @@ exports.Class = class Class extends Base
# NOTE Currently, only methods and static methods are valid in ES class initializers.
# When additional expressions become valid, this method should be updated to handle them.
addInitializerExpression: (node) ->
if @validInitializerMethod node
if node.unwrapAll() instanceof PassthroughLiteral
node
else if @validInitializerMethod node
@addInitializerMethod node
else
null
Expand Down
15 changes: 15 additions & 0 deletions test/classes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1833,3 +1833,18 @@ test "#4591: super.x.y, super['x'].y", ->
eq 2, b.t
eq 2, b.s
eq 2, b.r

test "#4464: backticked expressions in class body", ->
class A
`get x() { return 42; }`

class B
`get x() { return 42; }`
constructor: ->
@y = 84

a = new A
eq 42, a.x
b = new B
eq 42, b.x
eq 84, b.y

0 comments on commit f77a98a

Please sign in to comment.