Skip to content

Commit

Permalink
Use free variables for anonymous classes (#4826)
Browse files Browse the repository at this point in the history
Fixes #4822.
  • Loading branch information
connec authored and GeoffreyBooth committed Dec 28, 2017
1 parent ffbe51e commit 38f5963
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
8 changes: 4 additions & 4 deletions lib/coffeescript/nodes.js

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

10 changes: 5 additions & 5 deletions src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1871,11 +1871,6 @@ exports.ExecutableClassBody = class ExecutableClassBody extends Base
if argumentsNode = @body.contains isLiteralArguments
argumentsNode.error "Class bodies shouldn't reference arguments"

@name = @class.name ? @defaultClassVariableName
directives = @walkBody()
@setContext()

ident = new IdentifierLiteral @name
params = []
args = [new ThisLiteral]
wrapper = new Code params, @body
Expand All @@ -1885,6 +1880,11 @@ exports.ExecutableClassBody = class ExecutableClassBody extends Base

o.classScope = wrapper.makeScope o.scope

@name = @class.name ? o.classScope.freeVariable @defaultClassVariableName
ident = new IdentifierLiteral @name
directives = @walkBody()
@setContext()

if @class.hasNameClash
parent = new IdentifierLiteral o.classScope.freeVariable 'superClass'
wrapper.params.push new Param parent
Expand Down
7 changes: 7 additions & 0 deletions test/classes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1858,6 +1858,13 @@ test "#4724: backticked expression in a class body with hoisted member", ->
eq 42, a.x
eq 84, a.hoisted

test "#4822: nested anonymous classes use non-conflicting variable names", ->
Class = class
@a: class
@b: 1

eq Class.a.b, 1

test "#4827: executable class body wrappers have correct context", ->
test = ->
class @A
Expand Down

0 comments on commit 38f5963

Please sign in to comment.