Skip to content

Commit 8f62b6d

Browse files
committed
This commit fixes bug jashkenas#3, the arguments/_arguments mix-up.
1 parent 8de4a72 commit 8f62b6d

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
@@ -1682,6 +1692,9 @@ exports.Code = class Code extends Base
16821692
throw SyntaxError "multiple parameters named '#{name}'" if name in uniqs
16831693
uniqs.push name
16841694

1695+
if @icedFoundArguments and @icedNodeFlag
1696+
o.scope.assign '_arguments', 'arguments'
1697+
16851698
wasEmpty = false if @icedHasAutocbFlag
16861699
@body.makeReturn() unless wasEmpty or @noReturn
16871700
if @bound
@@ -1743,14 +1756,21 @@ exports.Code = class Code extends Base
17431756
@icedParentAwait = parent
17441757
fa_prev = o.foundAutocb
17451758
cf_prev = o.currFunc
1759+
fg_prev = o.foundArguments
1760+
faf_prev = o.foundAwaitFunc
17461761
o.foundAutocb = false
1762+
o.foundArguments = false
1763+
o.foundAwaitFunc = false
17471764
o.currFunc = @
17481765
for param in @params
17491766
if param.name instanceof Literal and param.name.value is iced.const.autocb
17501767
o.foundAutocb = true
17511768
break
17521769
@icedHasAutocbFlag = o.foundAutocb
17531770
super parent, o
1771+
@icedFoundArguments = o.foundArguments
1772+
o.foundAwaitFunc = faf_prev
1773+
o.foundArguments = fg_prev
17541774
o.foundAutocb = fa_prev
17551775
o.currFunc = cf_prev
17561776
false
@@ -2422,7 +2442,7 @@ exports.Await = class Await extends Base
24222442
p = p || this
24232443
@icedParentAwait = p
24242444
super p, o
2425-
@icedNodeFlag = o.foundAwait = true
2445+
@icedNodeFlag = o.foundAwaitFunc = o.foundAwait = true
24262446

24272447
#### IcedRuntime
24282448
#

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)