Skip to content

Commit 142d044

Browse files
committed
This commit fixes bug maxtaco#3, the arguments/_arguments mix-up.
1 parent 111121d commit 142d044

17 files changed

+72
-24
lines changed

lib/coffee-script/browser.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffee-script/cake.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffee-script/coffee-script.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffee-script/command.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffee-script/grammar.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffee-script/helpers.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffee-script/iced.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffee-script/icedlib.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffee-script/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffee-script/lexer.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffee-script/nodes.js

+25-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffee-script/optparse.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffee-script/repl.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffee-script/rewriter.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffee-script/scope.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

+26-6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ exports.Base = class Base
4545
@icedGotCpsSplitFlag = false
4646
@icedCpsPivotFlag = false
4747
@icedHasAutocbFlag = false
48+
@icedFoundArguments = false
4849

4950
@icedParentAwait = null
5051
@icedCallContinuationFlag = false
@@ -204,6 +205,7 @@ exports.Base = class Base
204205
extras += "P" if @icedCpsPivotFlag
205206
extras += "C" if @icedHasAutocbFlag
206207
extras += "D" if @icedParentAwait
208+
extras += "G" if @icedFoundArguments
207209
if extras.length
208210
extras = " (" + extras + ")"
209211
tree = '\n' + idt + name
@@ -275,10 +277,12 @@ exports.Base = class Base
275277
# copies, to push information up and down the AST. This parameter is
276278
# used with subfields:
277279
#
278-
# o.foundAutocb -- on if the parent function has an autocb
279-
# o.foundDefer -- on if defer() was found anywhere in the AST
280-
# o.foundAwait -- on if await... was found anywhere in the AST
281-
# o.currFunc -- the current func we're in
280+
# o.foundAutocb -- on if the parent function has an autocb
281+
# o.foundDefer -- on if defer() was found anywhere in the AST
282+
# o.foundAwait -- on if await... was found anywhere in the AST
283+
# o.foundAwaitFunc -- on if await found in this func
284+
# o.currFunc -- the current func we're in
285+
# o.foundArguments -- on if we found reference to 'arguments'
282286
#
283287
icedWalkAst : (p, o) ->
284288
@icedParentAwait = p
@@ -669,7 +673,7 @@ exports.Block = class Block extends Base
669673
# JavaScript without translation, such as: strings, numbers,
670674
# `true`, `false`, `null`...
671675
exports.Literal = class Literal extends Base
672-
constructor: (@value) ->
676+
constructor: (@value, @tag) ->
673677
super()
674678

675679
makeReturn: ->
@@ -687,6 +691,12 @@ exports.Literal = class Literal extends Base
687691
assigns: (name) ->
688692
name is @value
689693

694+
icedWalkAst : (parent, o) ->
695+
if @value is 'arguments' and o.foundAwaitFunc
696+
o.foundArguments = true
697+
@value = "_arguments"
698+
false
699+
690700
compileIced: (o) ->
691701
d =
692702
'continue' : iced.const.c_while
@@ -1657,6 +1667,9 @@ exports.Code = class Code extends Base
16571667
throw SyntaxError "multiple parameters named '#{name}'" if name in uniqs
16581668
uniqs.push name
16591669

1670+
if @icedFoundArguments and @icedNodeFlag
1671+
o.scope.assign '_arguments', 'arguments'
1672+
16601673
wasEmpty = false if @icedHasAutocbFlag
16611674
@body.makeReturn() unless wasEmpty or @noReturn
16621675
if @bound
@@ -1718,14 +1731,21 @@ exports.Code = class Code extends Base
17181731
@icedParentAwait = parent
17191732
fa_prev = o.foundAutocb
17201733
cf_prev = o.currFunc
1734+
fg_prev = o.foundArguments
1735+
faf_prev = o.foundAwaitFunc
17211736
o.foundAutocb = false
1737+
o.foundArguments = false
1738+
o.foundAwaitFunc = false
17221739
o.currFunc = @
17231740
for param in @params
17241741
if param.name instanceof Literal and param.name.value is iced.const.autocb
17251742
o.foundAutocb = true
17261743
break
17271744
@icedHasAutocbFlag = o.foundAutocb
17281745
super parent, o
1746+
@icedFoundArguments = o.foundArguments
1747+
o.foundAwaitFunc = faf_prev
1748+
o.foundArguments = fg_prev
17291749
o.foundAutocb = fa_prev
17301750
o.currFunc = cf_prev
17311751
false
@@ -2394,7 +2414,7 @@ exports.Await = class Await extends Base
23942414
p = p || this
23952415
@icedParentAwait = p
23962416
super p, o
2397-
@icedNodeFlag = o.foundAwait = true
2417+
@icedNodeFlag = o.foundAwaitFunc = o.foundAwait = true
23982418

23992419
#### IcedRuntime
24002420
#

test/iced.coffee

+7
Original file line numberDiff line numberDiff line change
@@ -576,3 +576,10 @@ atest "defer and object assignment", (cb) ->
576576
when 1 then baz defer { b : out[i] }
577577
when 2 then baz defer { a : out[i] }
578578
cb( out[0] is 3 and out[1] is 2 and out[2] is 1, {} )
579+
580+
atest 'defer + arguments', (cb) ->
581+
bar = (i, cb) ->
582+
await delay defer()
583+
arguments[1](arguments[0])
584+
await bar 10, defer x
585+
cb(10 is x, {})

0 commit comments

Comments
 (0)