Skip to content

Commit

Permalink
Correct destructured parameter default evaluation order with an incre…
Browse files Browse the repository at this point in the history
…menting variable (or more generally any complicated parameter that isComplex)
  • Loading branch information
GeoffreyBooth committed Jan 24, 2017
1 parent dbd8274 commit 49ccded
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/coffee-script/nodes.js

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

2 changes: 1 addition & 1 deletion src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2112,7 +2112,7 @@ exports.Param = class Param extends Base
@reference = node

isComplex: ->
@name.isComplex() or @value instanceof Call
@name.isComplex() or (@value?.isComplex? and @value.isComplex())

# Iterates the name or names of a `Param`.
# In a sense, a destructured parameter represents multiple JS parameters. This
Expand Down
7 changes: 6 additions & 1 deletion test/functions.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,12 @@ test "#1038 Optimize trailing return statements", ->
return
""")

test "#4406 Destructured parameter default evaluation order", ->
test "#4406 Destructured parameter default evaluation order with incrementing variable", ->
i = 0
f = ({ a = ++i }, b = ++i) -> [a, b]
arrayEq f({}), [1, 2]

test "#4406 Destructured parameter default evaluation order with generator function", ->
current = 0
next = -> ++current
foo = ({ a = next() }, b = next()) -> [ a, b ]
Expand Down

0 comments on commit 49ccded

Please sign in to comment.