@@ -2318,12 +2318,19 @@ exports.Assign = class Assign extends Base
2318
2318
2319
2319
isSplat = splats ? .length > 0
2320
2320
isExpans = expans ? .length > 0
2321
- isObject = @variable .isObject ()
2322
- isArray = @variable .isArray ()
2323
2321
2324
2322
vvar = value .compileToFragments o, LEVEL_LIST
2325
2323
vvarText = fragmentsToText vvar
2326
2324
assigns = []
2325
+ pushAssign = (variable , val ) =>
2326
+ assigns .push new Assign (variable, val, null , param : @param , subpattern : yes ).compileToFragments o, LEVEL_LIST
2327
+
2328
+ if isSplat
2329
+ splatVar = objects[splats[0 ]].name .unwrap ()
2330
+ if splatVar instanceof Arr or splatVar instanceof Obj
2331
+ splatVarRef = new IdentifierLiteral o .scope .freeVariable ' ref'
2332
+ objects[splats[0 ]].name = splatVarRef
2333
+ splatVarAssign = -> pushAssign new Value (splatVar), splatVarRef
2327
2334
2328
2335
# At this point, there are several things to destructure. So the `fn()` in
2329
2336
# `{a, b} = fn()` must be cached, for example. Make vvar into a simple
@@ -2388,13 +2395,13 @@ exports.Assign = class Assign extends Base
2388
2395
else new Value new Literal (vvarTxt), [new Index new NumberLiteral i]
2389
2396
message = isUnassignable vvar .unwrap ().value
2390
2397
vvar .error message if message
2391
- assigns . push new Assign ( vvar, vval, null , param : @param , subpattern : yes ). compileToFragments o, LEVEL_LIST
2398
+ pushAssign vvar, vval
2392
2399
2393
2400
# "Simple" `objects` can be split and compiled to arrays, [a, b, c] = arr, [a, b, c...] = arr
2394
2401
assignObjects = (objs , vvar , vvarTxt ) =>
2395
2402
vvar = new Value new Arr (objs, yes )
2396
2403
vval = if vvarTxt instanceof Value then vvarTxt else new Value new Literal (vvarTxt)
2397
- assigns . push new Assign ( vvar, vval, null , param : @param , subpattern : yes ). compileToFragments o, LEVEL_LIST
2404
+ pushAssign vvar, vval
2398
2405
2399
2406
processObjects = (objs , vvar , vvarTxt ) ->
2400
2407
if complexObjects objs
@@ -2431,6 +2438,7 @@ exports.Assign = class Assign extends Base
2431
2438
else
2432
2439
# There is no `Splat` or `Expansion` in `objects`.
2433
2440
processObjects objects, vvar, vvarText
2441
+ splatVarAssign? ()
2434
2442
assigns .push vvar unless top or @subpattern
2435
2443
fragments = @ joinFragmentArrays assigns, ' , '
2436
2444
if o .level < LEVEL_LIST then fragments else @ wrapInParentheses fragments
@@ -2592,7 +2600,7 @@ exports.Code = class Code extends Base
2592
2600
param .error ' an expansion parameter cannot be the only parameter in a function definition'
2593
2601
haveSplatParam = yes
2594
2602
if param .splat
2595
- if param .name instanceof Arr
2603
+ if param .name instanceof Arr or param . name instanceof Obj
2596
2604
# Splat arrays are treated oddly by ES; deal with them the legacy
2597
2605
# way in the function body. TODO: Should this be handled in the
2598
2606
# function parameter list, and if so, how?
0 commit comments