Skip to content

Commit 2491d32

Browse files
author
Zdenko Vujasinovic
committed
fix assign in nested properties
fix assign in nested properties
1 parent 1a6477a commit 2491d32

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

lib/coffeescript/nodes.js

Lines changed: 16 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,8 +2122,9 @@ exports.Assign = class Assign extends Base
21222122
@variable.base.lhs = yes
21232123
return @compileDestructuring o unless @variable.isAssignable()
21242124
# Object destructuring. Can be removed once ES proposal hits Stage 4.
2125-
return @compileObjectDestruct(o) if @variable.isObject() and @variable.contains (node) ->
2125+
objDestructAnswer = @compileObjectDestruct(o) if @variable.isObject() and @variable.contains (node) ->
21262126
node instanceof Obj and node.hasSplat()
2127+
return objDestructAnswer if objDestructAnswer
21272128

21282129
return @compileSplice o if @variable.isSplice()
21292130
return @compileConditional o if @context in ['||=', '&&=', '?=']
@@ -2224,8 +2225,12 @@ exports.Assign = class Assign extends Base
22242225
if prop instanceof Assign
22252226
# prop is `k: expr`, we need to check `expr` for nested splats
22262227
if prop.value.isObject?()
2227-
# prop is `k: {...}`
2228-
nestedProperties = prop.value.base.properties
2228+
if prop.operatorToken.unwrap().value is ':'
2229+
# prop is `k: {...}`
2230+
nestedProperties = prop.value.base.properties
2231+
if prop.operatorToken.unwrap().value is '='
2232+
# prop is `k = {...} `
2233+
continue
22292234
else if prop.value instanceof Assign and prop.value.variable.isObject()
22302235
# prop is `k: {...} = default`
22312236
nestedProperties = prop.value.variable.base.properties
@@ -2254,8 +2259,10 @@ exports.Assign = class Assign extends Base
22542259

22552260
# Find all rest elements.
22562261
restElements = traverseRest @variable.base.properties, valueRef
2262+
return false unless restElements and restElements.length > 0
22572263

22582264
result = new Block [@]
2265+
22592266
for restElement in restElements
22602267
value = new Call new Value(new Literal utility 'objectWithoutKeys', o), [restElement.source, restElement.excludeProps]
22612268
result.push new Assign restElement.name, value

0 commit comments

Comments
 (0)