Skip to content

Commit 4d4e47b

Browse files
connecGeoffreyBooth
authored andcommitted
Fix #4724 (#4737)
The handling of hoisted nodes in class bodies was incorrect, as the node was being unwrapped *before* checking if it was hoisted, meaning nodes that should have been hoisted would be output normally. This affected `PassthroughLiteral`s as they were wrapped in a `Value`.
1 parent 22fb31e commit 4d4e47b

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

lib/coffeescript/nodes.js

Lines changed: 6 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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,17 +497,19 @@ exports.Block = class Block extends Base
497497
compiledNodes = []
498498

499499
for node, index in @expressions
500+
if node.hoisted
501+
# This is a hoisted expression.
502+
# We want to compile this and ignore the result.
503+
node.compileToFragments o
504+
continue
505+
500506
node = node.unwrapAll()
501507
node = (node.unfoldSoak(o) or node)
502508
if node instanceof Block
503509
# This is a nested block. We don’t do anything special here like
504510
# enclose it in a new scope; we just compile the statements in this
505511
# block along with our own.
506512
compiledNodes.push node.compileNode o
507-
else if node.hoisted
508-
# This is a hoisted expression.
509-
# We want to compile this and ignore the result.
510-
node.compileToFragments o
511513
else if top
512514
node.front = yes
513515
fragments = node.compileToFragments o

test/classes.coffee

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,3 +1848,12 @@ test "#4464: backticked expressions in class body", ->
18481848
b = new B
18491849
eq 42, b.x
18501850
eq 84, b.y
1851+
1852+
test "#4724: backticked expression in a class body with hoisted member", ->
1853+
class A
1854+
`get x() { return 42; }`
1855+
hoisted: 84
1856+
1857+
a = new A
1858+
eq 42, a.x
1859+
eq 84, a.hoisted

0 commit comments

Comments
 (0)