Skip to content

Commit 9e9c83f

Browse files
committed
Merge pull request #3228 from marchaefner/fixClassCompilation
Avoid unnecessary wrapping of some bound functions
2 parents ab40571 + d41d87a commit 9e9c83f

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

lib/coffee-script/nodes.js

Lines changed: 21 additions & 25 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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,6 @@ exports.Code = class Code extends Base
12971297
@params = params or []
12981298
@body = body or new Block
12991299
@bound = tag is 'boundfunc'
1300-
@context = '_this' if @bound
13011300

13021301
children: ['params', 'body']
13031302

@@ -1314,10 +1313,13 @@ exports.Code = class Code extends Base
13141313
# a closure.
13151314
compileNode: (o) ->
13161315

1316+
if @bound and o.scope.method?.bound
1317+
@context = o.scope.method.context
1318+
13171319
# Handle bound functions early.
1318-
if @bound and not @wrapped and not @static
1319-
@wrapped = yes
1320-
wrapper = new Code [new Param new Literal '_this'], new Block [this]
1320+
if @bound and not @context
1321+
@context = '_this'
1322+
wrapper = new Code [new Param new Literal @context], new Block [this]
13211323
boundfunc = new Call(wrapper, [new Literal 'this'])
13221324
boundfunc.updateLocationDataIfMissing @locationData
13231325
return boundfunc.compileNode(o)
@@ -1361,9 +1363,6 @@ exports.Code = class Code extends Base
13611363
node.error "multiple parameters named '#{name}'" if name in uniqs
13621364
uniqs.push name
13631365
@body.makeReturn() unless wasEmpty or @noReturn
1364-
if @bound and o.scope.parent.method?.bound
1365-
@bound = @context = o.scope.parent.method.context
1366-
idt = o.indent
13671366
code = 'function'
13681367
code += ' ' + @name if @ctor
13691368
code += '('

0 commit comments

Comments
 (0)