Skip to content

Commit aefe5d2

Browse files
committed
This commit fixes bug #3, the arguments/_arguments mix-up.
1 parent 911d61e commit aefe5d2

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
@@ -668,7 +672,7 @@ exports.Block = class Block extends Base
668672
# JavaScript without translation, such as: strings, numbers,
669673
# `true`, `false`, `null`...
670674
exports.Literal = class Literal extends Base
671-
constructor: (@value) ->
675+
constructor: (@value, @tag) ->
672676
super()
673677

674678
makeReturn: ->
@@ -686,6 +690,12 @@ exports.Literal = class Literal extends Base
686690
assigns: (name) ->
687691
name is @value
688692

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

1687+
if @icedFoundArguments and @icedNodeFlag
1688+
o.scope.assign '_arguments', 'arguments'
1689+
16771690
wasEmpty = false if @icedHasAutocbFlag
16781691
@body.makeReturn() unless wasEmpty or @noReturn
16791692
if @bound
@@ -1735,14 +1748,21 @@ exports.Code = class Code extends Base
17351748
@icedParentAwait = parent
17361749
fa_prev = o.foundAutocb
17371750
cf_prev = o.currFunc
1751+
fg_prev = o.foundArguments
1752+
faf_prev = o.foundAwaitFunc
17381753
o.foundAutocb = false
1754+
o.foundArguments = false
1755+
o.foundAwaitFunc = false
17391756
o.currFunc = @
17401757
for param in @params
17411758
if param.name instanceof Literal and param.name.value is iced.const.autocb
17421759
o.foundAutocb = true
17431760
break
17441761
@icedHasAutocbFlag = o.foundAutocb
17451762
super parent, o
1763+
@icedFoundArguments = o.foundArguments
1764+
o.foundAwaitFunc = faf_prev
1765+
o.foundArguments = fg_prev
17461766
o.foundAutocb = fa_prev
17471767
o.currFunc = cf_prev
17481768
false
@@ -2420,7 +2440,7 @@ exports.Await = class Await extends Base
24202440
p = p || this
24212441
@icedParentAwait = p
24222442
super p, o
2423-
@icedNodeFlag = o.foundAwait = true
2443+
@icedNodeFlag = o.foundAwaitFunc = o.foundAwait = true
24242444

24252445
#### IcedRuntime
24262446
#

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)