Skip to content

Commit a6d4bf1

Browse files
helixbassGeoffreyBooth
authored andcommitted
handle assignment to nested nontrailing splat (#5265)
1 parent 0e51cda commit a6d4bf1

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

lib/coffeescript/nodes.js

Lines changed: 6 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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ exports.Value = class Value extends Base
13601360
isArray : -> @bareLiteral(Arr)
13611361
isRange : -> @bareLiteral(Range)
13621362
shouldCache : -> @hasProperties() or @base.shouldCache()
1363-
isAssignable : -> @hasProperties() or @base.isAssignable()
1363+
isAssignable : (opts) -> @hasProperties() or @base.isAssignable opts
13641364
isNumber : -> @bareLiteral(NumberLiteral)
13651365
isString : -> @bareLiteral(StringLiteral)
13661366
isRegex : -> @bareLiteral(RegexLiteral)
@@ -2661,12 +2661,13 @@ exports.Arr = class Arr extends Base
26612661
return yes for obj in @objects when obj instanceof Elision
26622662
no
26632663

2664-
isAssignable: ({allowExpansion, allowNontrailingSplat, allowEmptyArray = no} = {}) ->
2664+
isAssignable: (opts) ->
2665+
{allowExpansion, allowNontrailingSplat, allowEmptyArray = no} = opts ? {}
26652666
return allowEmptyArray unless @objects.length
26662667

26672668
for obj, i in @objects
26682669
return no if not allowNontrailingSplat and obj instanceof Splat and i + 1 isnt @objects.length
2669-
return no unless (allowExpansion and obj instanceof Expansion) or (obj.isAssignable() and (not obj.isAtomic or obj.isAtomic()))
2670+
return no unless (allowExpansion and obj instanceof Expansion) or (obj.isAssignable(opts) and (not obj.isAtomic or obj.isAtomic()))
26702671
yes
26712672

26722673
shouldCache: ->

test/abstract_syntax_tree.coffee

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,6 +2354,14 @@ test "AST as expected for Assign node", ->
23542354
]
23552355
right: ID 'b'
23562356

2357+
testExpression '[u, [v, ...w, x], ...{...y}, z] = a',
2358+
left:
2359+
type: 'ArrayPattern'
2360+
2361+
testExpression '{...{a: [...b, c]}} = d',
2362+
left:
2363+
type: 'ObjectPattern'
2364+
23572365
test "AST as expected for Code node", ->
23582366
testExpression '=>',
23592367
type: 'ArrowFunctionExpression'

0 commit comments

Comments
 (0)