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 c4b6d27
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 33 deletions.
12 changes: 8 additions & 4 deletions lib/coffee-script/browser.js

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

9 changes: 6 additions & 3 deletions lib/coffee-script/coffee-script.js

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

15 changes: 10 additions & 5 deletions lib/coffee-script/lexer.js

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

37 changes: 24 additions & 13 deletions lib/coffee-script/nodes.js

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

3 changes: 2 additions & 1 deletion lib/coffee-script/optparse.js

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

3 changes: 2 additions & 1 deletion lib/coffee-script/repl.js

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

3 changes: 2 additions & 1 deletion lib/coffee-script/scope.js

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

9 changes: 6 additions & 3 deletions lib/coffee-script/sourcemap.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 c4b6d27

Please sign in to comment.