Skip to content

Commit 669e7fe

Browse files
Merge pull request #3791 from lydell/issue-3502
Fix #3502: Define param variables when expansion
2 parents 4bf45ff + 4c2c472 commit 669e7fe

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

lib/coffee-script/nodes.js

+3-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

+2-2
Original file line numberDiff line numberDiff line change
@@ -1360,8 +1360,8 @@ exports.Code = class Code extends Base
13601360
for param in @params when param not instanceof Expansion
13611361
o.scope.parameter param.asReference o
13621362
for param in @params when param.splat or param instanceof Expansion
1363-
for {name: p} in @params when param not instanceof Expansion
1364-
if p.value then o.scope.add p.value, 'var', yes
1363+
for p in @params when p not instanceof Expansion and p.name.value
1364+
o.scope.add p.name.value, 'var', yes
13651365
splats = new Assign new Value(new Arr(p.asReference o for p in @params)),
13661366
new Value new Literal 'arguments'
13671367
break

test/functions.coffee

+14
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,20 @@ test "#156: parameter lists with expansion in array destructuring", ->
198198
last
199199
eq 3, expandArray 1, 2, 3, [1, 2, 3]
200200

201+
test "#3502: variable definitions and expansion", ->
202+
a = b = 0
203+
f = (a, ..., b) -> [a, b]
204+
arrayEq [1, 5], f 1, 2, 3, 4, 5
205+
eq 0, a
206+
eq 0, b
207+
208+
test "variable definitions and splat", ->
209+
a = b = 0
210+
f = (a, middle..., b) -> [a, middle, b]
211+
arrayEq [1, [2, 3, 4], 5], f 1, 2, 3, 4, 5
212+
eq 0, a
213+
eq 0, b
214+
201215
test "default values with function calls", ->
202216
doesNotThrow -> CoffeeScript.compile "(x = f()) ->"
203217

0 commit comments

Comments
 (0)