Skip to content

Commit 1869f31

Browse files
zdenkoGeoffreyBooth
authored andcommitted
Fix: destructuring assignment with an empty array in object (#5000)
* destructuring assignment with empty array in object * improvements
1 parent 4c0363f commit 1869f31

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

lib/coffeescript/nodes.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

+3-1
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,9 @@ exports.Obj = class Obj extends Base
14771477
message = isUnassignable prop.unwrapAll().value
14781478
prop.error message if message
14791479

1480-
prop = prop.value if prop instanceof Assign and prop.context is 'object'
1480+
prop = prop.value if prop instanceof Assign and
1481+
prop.context is 'object' and
1482+
prop.value?.base not instanceof Arr
14811483
return no unless prop.isAssignable()
14821484
yes
14831485

test/assignment.coffee

+17
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,23 @@ test "#4878: Compile error when using destructuring with a splat or expansion in
986986

987987
arrayEq bar(arr), ['a', ['b', 'c', 'd']]
988988

989+
test "destructuring assignment with an empty array in object", ->
990+
obj =
991+
a1: [1, 2]
992+
b1: 3
993+
994+
{a1:[], b1} = obj
995+
eq 'undefined', typeof a1
996+
eq b1, 3
997+
998+
obj =
999+
a2:
1000+
b2: [1, 2]
1001+
c2: 3
1002+
1003+
{a2: {b2:[]}, c2} = obj
1004+
eq 'undefined', typeof b2
1005+
eq c2, 3
9891006

9901007
test "#5004: array destructuring with accessors", ->
9911008
obj =

0 commit comments

Comments
 (0)