Skip to content

Commit 63ffe0a

Browse files
brewingcodeGeoffreyBooth
authored andcommitted
Fix 5085 (#5145)
* Add test for #5085 $ cake test failed 1 and passed 1274 tests in 4.81 seconds #5085: Bug: @ reference to class not maintained in do block AssertionError [ERR_ASSERTION]: Expected undefined to equal 2 * Fix #5085: @ reference to class in "do" block Assuming that a bound Code node inside an ExecutableClassBody without a name must be a "do" block. * Additional tests #5145 (comment) Also switched to concat'g strings for test values, as opposed to incrementing numbers: makes the tests a bit easier to read.
1 parent 247b511 commit 63ffe0a

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

lib/coffeescript/nodes.js

Lines changed: 1 addition & 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1989,7 +1989,7 @@ exports.ExecutableClassBody = class ExecutableClassBody extends Base
19891989
@body.traverseChildren false, (node) =>
19901990
if node instanceof ThisLiteral
19911991
node.value = @name
1992-
else if node instanceof Code and node.bound and node.isStatic
1992+
else if node instanceof Code and node.bound and (node.isStatic or not node.name)
19931993
node.context = @name
19941994

19951995
# Make class/prototype assignments for invalid ES properties

test/classes.coffee

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,3 +1922,16 @@ test "#4609: Support new.target", ->
19221922

19231923
new Foo()
19241924
eq newTarget, yes
1925+
1926+
test "#5085: Bug: @ reference to class not maintained in do block", ->
1927+
thisFoo = 'initial foo'
1928+
thisBar = 'initial bar'
1929+
fn = (o) -> o.bar()
1930+
1931+
class A
1932+
@foo = 'foo assigned in class'
1933+
do => thisFoo = @foo
1934+
fn bar: => thisBar = @foo
1935+
1936+
eq thisFoo, 'foo assigned in class'
1937+
eq thisBar, 'foo assigned in class'

0 commit comments

Comments
 (0)