@@ -1108,18 +1108,14 @@ exports.Slice = class Slice extends Base
1108
1108
1109
1109
# An object literal, nothing fancy.
1110
1110
exports .Obj = class Obj extends Base
1111
- constructor : (props ,@generated = no )->
1111
+ constructor : (props ,@generated = no , @lhs = no )->
1112
1112
super ()
1113
1113
1114
1114
@objects = @properties = propsor []
1115
1115
1116
1116
children : [' properties' ]
1117
1117
1118
1118
isAssignable : ->
1119
- # Is this object the left-hand side of an assignment? If it is, this object
1120
- # is part of a destructuring assignment.
1121
- @lhs = yes
1122
-
1123
1119
for propin @properties
1124
1120
# Check for reserved words.
1125
1121
message = isUnassignable prop .unwrapAll ().value
@@ -1199,7 +1195,7 @@ exports.Obj = class Obj extends Base
1199
1195
1200
1196
# An array literal.
1201
1197
exports .Arr = class Arr extends Base
1202
- constructor : (objs )->
1198
+ constructor : (objs , @lhs = no )->
1203
1199
super ()
1204
1200
1205
1201
@objects = objsor []
@@ -1222,6 +1218,12 @@ exports.Arr = class Arr extends Base
1222
1218
o .indent += TAB
1223
1219
1224
1220
answer = []
1221
+ # If this array is the left-hand side of an assignment, all its children
1222
+ # are too.
1223
+ if @lhs
1224
+ for objin @objects
1225
+ unwrappedObj = obj .unwrapAll ()
1226
+ unwrappedObj .lhs = yes if unwrappedObjinstanceof Arror unwrappedObjinstanceof Obj
1225
1227
compiledObjs = (obj .compileToFragments o, LEVEL_LISTfor objin @objects )
1226
1228
for fragments, indexin compiledObjs
1227
1229
if index
@@ -1727,7 +1729,8 @@ exports.Assign = class Assign extends Base
1727
1729
# we've been assigned to, for correct internal references. If the variable
1728
1730
# has not been seen yet within the current scope, declare it.
1729
1731
compileNode : (o )->
1730
- if isValue = @variable instanceof Value
1732
+ isValue = @variable instanceof Value
1733
+ if isValue
1731
1734
# When compiling `@variable`, remember if it is part of a function parameter.
1732
1735
@variable .param = @param
1733
1736
@@ -1736,6 +1739,10 @@ exports.Assign = class Assign extends Base
1736
1739
# in ES and we can output it as is; otherwise we `@compileDestructuring`
1737
1740
# and convert this ES-unsupported destructuring into acceptable output.
1738
1741
if @variable .isArray ()or @variable .isObject ()
1742
+ # This is the left-hand side of an assignment; let `Arr` and `Obj`
1743
+ # know that, so that those nodes know that they’re assignable as
1744
+ # destructured variables.
1745
+ @variable .base .lhs = yes
1739
1746
return @ compileDestructuring ounless @variable .isAssignable ()
1740
1747
1741
1748
return @ compileSplice oif @variable .isSplice ()
@@ -1750,14 +1757,14 @@ exports.Assign = class Assign extends Base
1750
1757
varBase .eachName (name)=>
1751
1758
return if name .hasProperties ? ()
1752
1759
1753
- name .error messageif message = isUnassignable name .value
1760
+ message = isUnassignable name .value
1761
+ name .error messageif message
1754
1762
1755
1763
# `moduleDeclaration` can be `'import'` or `'export'`
1764
+ @ checkAssignability o, name
1756
1765
if @moduleDeclaration
1757
- @ checkAssignability o, name
1758
1766
o .scope .add name .value ,@moduleDeclaration
1759
1767
else
1760
- @ checkAssignability o, name
1761
1768
o .scope .find name .value
1762
1769
1763
1770
if @value instanceof Code
@@ -2122,6 +2129,7 @@ exports.Code = class Code extends Base
2122
2129
# Add this parameter’s reference(s) to the function scope.
2123
2130
if param .name instanceof Arror param .name instanceof Obj
2124
2131
# This parameter is destructured.
2132
+ param .name .lhs = yes
2125
2133
param .name .eachName (prop)->
2126
2134
o .scope .parameter prop .value
2127
2135
else