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

Allow soaks and prototype shorthands in object splats (#5293)

* use normal Accessor grammar rule

* allow soaked calls

* test lhs spread
This commit is contained in:
Julian Rosse 2020-01-27 15:37:22 -08:00 committed by Geoffrey Booth
parent 6fe980e569
commit 92ad04b9b1
4 changed files with 258 additions and 261 deletions

View file

@ -415,11 +415,11 @@
o('Parenthetical'),
o('Super'),
o('This'),
o('SUPER Arguments',
o('SUPER OptFuncExist Arguments',
function() {
return new SuperCall(LOC(1)(new Super()),
$2,
false,
$3,
$2.soak,
$1);
}),
o('DYNAMIC_IMPORT Arguments',
@ -427,41 +427,29 @@
return new DynamicImportCall(LOC(1)(new DynamicImport()),
$2);
}),
o('SimpleObjAssignable Arguments',
o('SimpleObjAssignable OptFuncExist Arguments',
function() {
return new Call(new Value($1),
$2);
$3,
$2.soak);
}),
o('ObjSpreadExpr Arguments',
o('ObjSpreadExpr OptFuncExist Arguments',
function() {
return new Call($1,
$2);
$3,
$2.soak);
})
],
ObjSpreadIdentifier: [
o('SimpleObjAssignable ObjSpreadAccessor',
o('SimpleObjAssignable Accessor',
function() {
return (new Value($1)).add($2);
}),
o('ObjSpreadExpr ObjSpreadAccessor',
o('ObjSpreadExpr Accessor',
function() {
return (new Value($1)).add($2);
})
],
ObjSpreadAccessor: [
o('. Property',
function() {
return new Access($2);
}),
o('INDEX_START IndexValue INDEX_END',
function() {
return $2;
}),
o('INDEX_START INDENT IndexValue OUTDENT INDEX_END',
function() {
return $3;
})
],
// A return statement from a function body.
Return: [
o('RETURN Expression',

File diff suppressed because one or more lines are too long

View file

@ -269,21 +269,15 @@ grammar =
o 'Parenthetical'
o 'Super'
o 'This'
o 'SUPER Arguments', -> new SuperCall LOC(1)(new Super), $2, no, $1
o 'DYNAMIC_IMPORT Arguments', -> new DynamicImportCall LOC(1)(new DynamicImport), $2
o 'SimpleObjAssignable Arguments', -> new Call (new Value $1), $2
o 'ObjSpreadExpr Arguments', -> new Call $1, $2
o 'SUPER OptFuncExist Arguments', -> new SuperCall LOC(1)(new Super), $3, $2.soak, $1
o 'DYNAMIC_IMPORT Arguments', -> new DynamicImportCall LOC(1)(new DynamicImport), $2
o 'SimpleObjAssignable OptFuncExist Arguments', -> new Call (new Value $1), $3, $2.soak
o 'ObjSpreadExpr OptFuncExist Arguments', -> new Call $1, $3, $2.soak
]
ObjSpreadIdentifier: [
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
o 'INDEX_START INDENT IndexValue OUTDENT INDEX_END', -> $3
o 'SimpleObjAssignable Accessor', -> (new Value $1).add $2
o 'ObjSpreadExpr Accessor', -> (new Value $1).add $2
]
# A return statement from a function body.

View file

@ -440,3 +440,27 @@ test "#5168: allow indented property index", ->
'c'
]
}.c
test "#5291: soaks/prototype shorthands in object spread variables", ->
withPrototype =
prototype:
b: {c: 1}
eq {withPrototype::b...}.c, 1
eq {...withPrototype::b}.c, 1
withSoak =
b:
c: 2
eq {withSoak?.b...}.c, 2
eq {...withSoak?.b}.c, 2
soakedCall = ->
b:
c: 3
eq {soakedCall?().b...}.c, 3
eq {...soakedCall?().b}.c, 3
assignToPrototype =
prototype: {}
{...assignToPrototype::b} = c: 4
eq assignToPrototype::b.c, 4