Skip to content

Commit 69a07df

Browse files
[CS2] Fix handling of parameters that are function calls (#4427)
* Add failing test per #4406 * If a parameter is a function call, define it in an expression within the function body * Remove the space between `function` and `*` for generator functions, to follow usual ES idiom * We can collapse `isCall` into `isComplex` * Don’t need existence check here
1 parent 800116d commit 69a07df

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

lib/coffee-script/nodes.js

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,10 +1993,12 @@ exports.Code = class Code extends Base
19931993

19941994
# Assemble the output
19951995
modifiers = []
1996-
modifiers.push 'static' if @isMethod and @isStatic
1997-
modifiers.push 'async' if @isAsync
1998-
modifiers.push 'function' if not @isMethod and not @bound
1999-
modifiers.push '*' if @isGenerator
1996+
modifiers.push 'static' if @isMethod and @isStatic
1997+
modifiers.push 'async' if @isAsync
1998+
unless @isMethod or @bound
1999+
modifiers.push "function#{if @isGenerator then '*' else ''}"
2000+
else if @isGenerator
2001+
modifiers.push '*'
20002002

20012003
signature = [@makeCode '(']
20022004
for param, i in params
@@ -2110,7 +2112,7 @@ exports.Param = class Param extends Base
21102112
@reference = node
21112113

21122114
isComplex: ->
2113-
@name.isComplex()
2115+
@name.isComplex() or @value instanceof Call
21142116

21152117
# Iterates the name or names of a `Param`.
21162118
# In a sense, a destructured parameter represents multiple JS parameters. This

test/functions.coffee

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,9 @@ test "#1038 Optimize trailing return statements", ->
341341
foo()
342342
return
343343
""")
344+
345+
test "#4406 Destructured parameter default evaluation order", ->
346+
current = 0
347+
next = -> ++current
348+
foo = ({ a = next() }, b = next()) -> [ a, b ]
349+
arrayEq foo({}), [1, 2]

0 commit comments

Comments
 (0)