@@ -2120,8 +2120,9 @@ exports.Assign = class Assign extends Base
2120
2120
@variable .base .lhs = yes
2121
2121
return @ compileDestructuring o unless @variable .isAssignable ()
2122
2122
# Object destructuring. Can be removed once ES proposal hits Stage 4.
2123
- return @ compileObjectDestruct (o) if @variable .isObject () and @variable .contains (node) ->
2123
+ objDestructAnswer = @ compileObjectDestruct (o) if @variable .isObject () and @variable .contains (node) ->
2124
2124
node instanceof Obj and node .hasSplat ()
2125
+ return objDestructAnswer if objDestructAnswer
2125
2126
2126
2127
return @ compileSplice o if @variable .isSplice ()
2127
2128
return @ compileConditional o if @context in [' ||=' , ' &&=' , ' ?=' ]
@@ -2214,12 +2215,16 @@ exports.Assign = class Assign extends Base
2214
2215
traverseRest = (properties , source ) =>
2215
2216
restElements = []
2216
2217
restIndex = undefined
2218
+ source = new Value source unless source .properties ?
2217
2219
2218
2220
for prop, index in properties
2221
+ nestedSourceDefault = nestedSource = nestedProperties = null
2219
2222
setScopeVar prop .unwrap ()
2220
2223
if prop instanceof Assign
2221
2224
# prop is `k: expr`, we need to check `expr` for nested splats
2222
2225
if prop .value .isObject ? ()
2226
+ # prop is `k = {...} `
2227
+ continue unless prop .context is ' object'
2223
2228
# prop is `k: {...}`
2224
2229
nestedProperties = prop .value .base .properties
2225
2230
else if prop .value instanceof Assign and prop .value .variable .isObject ()
@@ -2245,13 +2250,19 @@ exports.Assign = class Assign extends Base
2245
2250
2246
2251
restElements
2247
2252
2248
- # Cache the value for reuse with rest elements
2249
- [@value , valueRef ] = @value .cache o
2253
+ # Cache the value for reuse with rest elements.
2254
+ if @value .shouldCache ()
2255
+ valueRefTemp = new IdentifierLiteral o .scope .freeVariable ' ref' , reserve : false
2256
+ else
2257
+ valueRefTemp = @value .base
2250
2258
2251
2259
# Find all rest elements.
2252
- restElements = traverseRest @variable .base .properties , valueRef
2260
+ restElements = traverseRest @variable .base .properties , valueRefTemp
2261
+ return no unless restElements and restElements .length > 0
2253
2262
2263
+ [@value , valueRef ] = @value .cache o
2254
2264
result = new Block [@ ]
2265
+
2255
2266
for restElement in restElements
2256
2267
value = new Call new Value (new Literal utility ' objectWithoutKeys' , o), [restElement .source , restElement .excludeProps ]
2257
2268
result .push new Assign restElement .name , value
0 commit comments