Skip to content

Commit fb21fbe

Browse files
author
Zdenko Vujasinovic
committed
fix splat error with soak properties or expressions
1 parent e3c2c03 commit fb21fbe

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

lib/coffee-script/nodes.js

Lines changed: 23 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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,21 @@ exports.Splat = class Splat extends Base
18121812
assigns: (name) ->
18131813
@name.assigns name
18141814

1815+
propHasSoak: ->
1816+
return no unless @name.properties
1817+
isSoak = yes for prop in @name.properties when prop.soak
1818+
isSoak ? no
1819+
18151820
compileToFragments: (o) ->
1821+
# Check if @name is not an instance of `Value` or @name properties contains soak accessor, e.g. ?.b,
1822+
# and ensure correct compilation by wrapping the @name in `Parens`.
1823+
# Examples:
1824+
# [a?.b...] => [(a?.b)...]
1825+
# f(a.b?.c...) => f((a.b?.c)...)
1826+
# [a if b...] => [(a if b)...]
1827+
if not (@name instanceof Value) or
1828+
(not (@name.base instanceof Parens) and @propHasSoak())
1829+
@name = new Value new Parens @name
18161830
@name.compileToFragments o
18171831

18181832
unwrap: -> @name

0 commit comments

Comments
 (0)