Skip to content

Commit

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

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

7 changes: 3 additions & 4 deletions src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1751,11 +1751,10 @@ exports.Class = class Class extends Base
new Block expressions

# Add an expression to the class initializer
#
# 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 657bdad

Please sign in to comment.