@@ -2305,8 +2305,8 @@ exports.Assign = class Assign extends Base
2305
2305
# Sort 'splatsAndExpans' so we can show error at first disallowed token.
2306
2306
objects[splatsAndExpans .sort ()[1 ]].error " multiple splats/expansions are disallowed in an assignment"
2307
2307
2308
- isSplat = splats .length
2309
- isExpans = expans .length
2308
+ isSplat = splats ? .length > 0
2309
+ isExpans = expans ? .length > 0
2310
2310
isObject = @variable .isObject ()
2311
2311
isArray = @variable .isArray ()
2312
2312
@@ -2355,7 +2355,7 @@ exports.Assign = class Assign extends Base
2355
2355
2356
2356
# "Complex" `objects` are processed in a loop.
2357
2357
# Examples: [a, b, {c, r...}, d], [a, ..., {b, r...}, c, d]
2358
- loopObjects = (objs , vvarTxt ) =>
2358
+ loopObjects = (objs , vvar , vvarTxt ) =>
2359
2359
objSpreads = hasObjSpreads objs
2360
2360
for obj, i in objs
2361
2361
# `Elision` can be skipped.
@@ -2385,16 +2385,16 @@ exports.Assign = class Assign extends Base
2385
2385
assigns .push new Assign (vvar, vval, null , param : @param , subpattern : yes ).compileToFragments o, LEVEL_LIST
2386
2386
2387
2387
# "Simple" `objects` can be split and compiled to arrays, [a, b, c] = arr, [a, b, c...] = arr
2388
- assignObjects = (objs , vvarTxt ) =>
2388
+ assignObjects = (objs , vvar , vvarTxt ) =>
2389
2389
vvar = new Value new Arr (objs, yes )
2390
2390
vval = if vvarTxt instanceof Value then vvarTxt else new Value new Literal (vvarTxt)
2391
2391
assigns .push new Assign (vvar, vval, null , param : @param , subpattern : yes ).compileToFragments o, LEVEL_LIST
2392
2392
2393
- processObjects = (objs , vvarTxt ) ->
2393
+ processObjects = (objs , vvar , vvarTxt ) ->
2394
2394
if complexObjects objs
2395
- loopObjects objs, vvarTxt
2395
+ loopObjects objs, vvar, vvarTxt
2396
2396
else
2397
- assignObjects objs, vvarTxt
2397
+ assignObjects objs, vvar, vvarTxt
2398
2398
2399
2399
# In case there is `Splat` or `Expansion` in `objects`,
2400
2400
# we can split array in two simple subarrays.
@@ -2411,7 +2411,7 @@ exports.Assign = class Assign extends Base
2411
2411
expIdx = splatsAndExpans[0 ]
2412
2412
leftObjs = objects .slice 0 , expIdx + (if isSplat then 1 else 0 )
2413
2413
rightObjs = objects .slice expIdx + 1
2414
- processObjects leftObjs, vvarText if leftObjs .length isnt 0
2414
+ processObjects leftObjs, vvar, vvarText if leftObjs .length isnt 0
2415
2415
if rightObjs .length isnt 0
2416
2416
# Slice or splice `objects`.
2417
2417
refExp = switch
@@ -2421,10 +2421,10 @@ exports.Assign = class Assign extends Base
2421
2421
restVar = refExp
2422
2422
refExp = o .scope .freeVariable ' ref'
2423
2423
assigns .push [@ makeCode (refExp + ' = ' ), restVar .compileToFragments (o, LEVEL_LIST)... ]
2424
- processObjects rightObjs, refExp
2424
+ processObjects rightObjs, vvar, refExp
2425
2425
else
2426
2426
# There is no `Splat` or `Expansion` in `objects`.
2427
- processObjects objects, vvarText
2427
+ processObjects objects, vvar, vvarText
2428
2428
assigns .push vvar unless top or @subpattern
2429
2429
fragments = @ joinFragmentArrays assigns, ' , '
2430
2430
if o .level < LEVEL_LIST then fragments else @ wrapInParentheses fragments
0 commit comments