@@ -2408,8 +2408,8 @@ exports.Assign = class Assign extends Base
2408
2408
# Sort 'splatsAndExpans' so we can show error at first disallowed token.
2409
2409
objects[splatsAndExpans .sort ()[1 ]].error " multiple splats/expansions are disallowed in an assignment"
2410
2410
2411
- isSplat = splats .length
2412
- isExpans = expans .length
2411
+ isSplat = splats ? .length > 0
2412
+ isExpans = expans ? .length > 0
2413
2413
isObject = @variable .isObject ()
2414
2414
isArray = @variable .isArray ()
2415
2415
@@ -2458,7 +2458,7 @@ exports.Assign = class Assign extends Base
2458
2458
2459
2459
# "Complex" `objects` are processed in a loop.
2460
2460
# Examples: [a, b, {c, r...}, d], [a, ..., {b, r...}, c, d]
2461
- loopObjects = (objs , vvarTxt ) =>
2461
+ loopObjects = (objs , vvar , vvarTxt ) =>
2462
2462
objSpreads = hasObjSpreads objs
2463
2463
for obj, i in objs
2464
2464
# `Elision` can be skipped.
@@ -2488,16 +2488,16 @@ exports.Assign = class Assign extends Base
2488
2488
assigns .push new Assign (vvar, vval, null , param : @param , subpattern : yes ).compileToFragments o, LEVEL_LIST
2489
2489
2490
2490
# "Simple" `objects` can be split and compiled to arrays, [a, b, c] = arr, [a, b, c...] = arr
2491
- assignObjects = (objs , vvarTxt ) =>
2491
+ assignObjects = (objs , vvar , vvarTxt ) =>
2492
2492
vvar = new Value new Arr (objs, yes )
2493
2493
vval = if vvarTxt instanceof Value then vvarTxt else new Value new Literal (vvarTxt)
2494
2494
assigns .push new Assign (vvar, vval, null , param : @param , subpattern : yes ).compileToFragments o, LEVEL_LIST
2495
2495
2496
- processObjects = (objs , vvarTxt ) ->
2496
+ processObjects = (objs , vvar , vvarTxt ) ->
2497
2497
if complexObjects objs
2498
- loopObjects objs, vvarTxt
2498
+ loopObjects objs, vvar, vvarTxt
2499
2499
else
2500
- assignObjects objs, vvarTxt
2500
+ assignObjects objs, vvar, vvarTxt
2501
2501
2502
2502
# In case there is `Splat` or `Expansion` in `objects`,
2503
2503
# we can split array in two simple subarrays.
@@ -2514,7 +2514,7 @@ exports.Assign = class Assign extends Base
2514
2514
expIdx = splatsAndExpans[0 ]
2515
2515
leftObjs = objects .slice 0 , expIdx + (if isSplat then 1 else 0 )
2516
2516
rightObjs = objects .slice expIdx + 1
2517
- processObjects leftObjs, vvarText if leftObjs .length isnt 0
2517
+ processObjects leftObjs, vvar, vvarText if leftObjs .length isnt 0
2518
2518
if rightObjs .length isnt 0
2519
2519
# Slice or splice `objects`.
2520
2520
refExp = switch
@@ -2524,10 +2524,10 @@ exports.Assign = class Assign extends Base
2524
2524
restVar = refExp
2525
2525
refExp = o .scope .freeVariable ' ref'
2526
2526
assigns .push [@ makeCode (refExp + ' = ' ), restVar .compileToFragments (o, LEVEL_LIST)... ]
2527
- processObjects rightObjs, refExp
2527
+ processObjects rightObjs, vvar, refExp
2528
2528
else
2529
2529
# There is no `Splat` or `Expansion` in `objects`.
2530
- processObjects objects, vvarText
2530
+ processObjects objects, vvar, vvarText
2531
2531
assigns .push vvar unless top or @subpattern
2532
2532
fragments = @ joinFragmentArrays assigns, ' , '
2533
2533
if o .level < LEVEL_LIST then fragments else @ wrapInParentheses fragments
0 commit comments