1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

[CS2] Fix object spread nested properties (#4611)

* fix for object spread nested properties: obj2 = {obj.c..., obj["b"]["c"]..., d: 55}

* tests
This commit is contained in:
zdenko 2017-07-23 02:44:35 +02:00 committed by Geoffrey Booth
parent 4e57ca6833
commit 557351156e
4 changed files with 260 additions and 234 deletions

View file

@ -164,10 +164,17 @@
})
],
ObjSpreadIdentifier: [
o('SimpleObjAssignable . Property', function() {
return (new Value($1)).add(new Access($3));
}), o('SimpleObjAssignable INDEX_START IndexValue INDEX_END', function() {
return (new Value($1)).add($3);
o('SimpleObjAssignable ObjSpreadAccessor', function() {
return (new Value($1)).add($2);
}), o('ObjSpreadExpr ObjSpreadAccessor', function() {
return (new Value($1)).add($2);
})
],
ObjSpreadAccessor: [
o('. Property', function() {
return new Access($2);
}), o('INDEX_START IndexValue INDEX_END', function() {
return $2;
})
],
Return: [

File diff suppressed because one or more lines are too long

View file

@ -234,8 +234,13 @@ grammar =
]
ObjSpreadIdentifier: [
o 'SimpleObjAssignable . Property', -> (new Value $1).add(new Access $3)
o 'SimpleObjAssignable INDEX_START IndexValue INDEX_END', -> (new Value $1).add($3)
o 'SimpleObjAssignable ObjSpreadAccessor', -> (new Value $1).add $2
o 'ObjSpreadExpr ObjSpreadAccessor', -> (new Value $1).add $2
]
ObjSpreadAccessor: [
o '. Property', -> new Access $2
o 'INDEX_START IndexValue INDEX_END', -> $2
]
# A return statement from a function body.

View file

@ -382,6 +382,23 @@ test "object spread properties: ES2015", ->
obj7 = {obj..., fn()..., {c: {d: 55, e: 66, f: {77}}}...}
eq obj7.c.d, 55
deepEqual obj6.c, {d: 33, e: 44, f: {g: 55}}
obj =
a:
b:
c:
d:
e: {}
obj9 = {a:1, obj.a.b.c..., g:3}
deepEqual obj9.d, {e: {}}
a = "a"
c = "c"
obj9 = {a:1, obj[a].b[c]..., g:3}
deepEqual obj9.d, {e: {}}
obj9 = {a:1, obj.a["b"].c["d"]..., g:3}
deepEqual obj9["e"], {}
test "bracket insertion when necessary", ->
[a] = [0] ? [1]