Skip to content

Commit 6cea181

Browse files
zdenkoGeoffreyBooth
authored andcommitted
[CS1] fix #4260 and #1349: splat error with soak properties or expressions (#4643)
* fix splat error with soak properties or expressions * Add test based on #4260 * Add test based on #1349 * remove 'void 0' replacement; add Splat::compileNode
1 parent e3c2c03 commit 6cea181

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

lib/coffee-script/nodes.js

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

src/nodes.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,7 @@ exports.Splat = class Splat extends Base
18121812
assigns: (name) ->
18131813
@name.assigns name
18141814

1815-
compileToFragments: (o) ->
1815+
compileNode: (o) ->
18161816
@name.compileToFragments o
18171817

18181818
unwrap: -> @name

test/arrays.coffee

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ test "array splat expansions with assignments", ->
3636
eq 4, b
3737
arrayEq [0,1,2,3,4], list
3838

39-
4039
test "mixed shorthand objects in array lists", ->
41-
4240
arr = [
4341
a:1
4442
'b'
@@ -58,7 +56,6 @@ test "mixed shorthand objects in array lists", ->
5856
eq arr[2].b, 1
5957
eq arr[3], 'b'
6058

61-
6259
test "array splats with nested arrays", ->
6360
nonce = {}
6461
a = [nonce]
@@ -70,6 +67,30 @@ test "array splats with nested arrays", ->
7067
list = [1, 2, a...]
7168
arrayEq list, [1, 2, [nonce]]
7269

70+
test "#4260: splat after existential operator soak", ->
71+
a = {b: [3]}
72+
foo = (a) -> [a]
73+
arrayEq [a?.b...], [3]
74+
arrayEq [c?.b ? []...], []
75+
arrayEq foo(a?.b...), [3]
76+
arrayEq foo(c?.b ? []...), [undefined]
77+
e = yes
78+
f = null
79+
arrayEq [(a if e)?.b...], [3]
80+
arrayEq [(a if f)?.b ? []...], []
81+
arrayEq foo((a if e)?.b...), [3]
82+
arrayEq foo((a if f)?.b ? []...), [undefined]
83+
84+
test "#1349: trailing if after splat", ->
85+
a = [3]
86+
b = yes
87+
c = null
88+
foo = (a) -> [a]
89+
arrayEq [a if b...], [3]
90+
arrayEq [(a if c) ? []...], []
91+
arrayEq foo((a if b)...), [3]
92+
arrayEq foo((a if c) ? []...), [undefined]
93+
7394
test "#1274: `[] = a()` compiles to `false` instead of `a()`", ->
7495
a = false
7596
fn = -> a = true

0 commit comments

Comments
 (0)