Spread syntax triple dots on either right or left (#4606)

* Spread dots on both sides: {a:1, ...obj1, obj2...},  [a..., ...b], f ...a, b...

* Optimization
This commit is contained in:
zdenko 2017-07-09 07:32:02 +02:00 committed by Geoffrey Booth
parent 35eb58fae8
commit 3be9038028
5 changed files with 187 additions and 165 deletions

View File

@ -146,8 +146,12 @@
ObjRestValue: [
o('SimpleObjAssignable ...', function() {
return new Splat(new Value($1));
}), o('... SimpleObjAssignable', function() {
return new Splat(new Value($2));
}), o('ObjSpreadExpr ...', function() {
return new Splat($1);
}), o('... ObjSpreadExpr', function() {
return new Splat($2);
})
],
ObjSpreadExpr: [
@ -225,6 +229,8 @@
return new Param($1);
}), o('ParamVar ...', function() {
return new Param($1, null, true);
}), o('... ParamVar', function() {
return new Param($2, null, true);
}), o('ParamVar = Expression', function() {
return new Param($1, $3);
}), o('...', function() {
@ -235,6 +241,8 @@
Splat: [
o('Expression ...', function() {
return new Splat($1);
}), o('... Expression', function() {
return new Splat($2);
})
],
SimpleAssignable: [

File diff suppressed because one or more lines are too long

View File

@ -295,7 +295,7 @@
}
start = stack.pop();
}
if ((indexOf.call(IMPLICIT_FUNC, tag) >= 0 && token.spaced || tag === '?' && i > 0 && !tokens[i - 1].spaced) && (indexOf.call(IMPLICIT_CALL, nextTag) >= 0 || indexOf.call(IMPLICIT_UNSPACED_CALL, nextTag) >= 0 && !nextToken.spaced && !nextToken.newLine)) {
if ((indexOf.call(IMPLICIT_FUNC, tag) >= 0 && token.spaced || tag === '?' && i > 0 && !tokens[i - 1].spaced) && (indexOf.call(IMPLICIT_CALL, nextTag) >= 0 || nextTag === '...' || indexOf.call(IMPLICIT_UNSPACED_CALL, nextTag) >= 0 && !nextToken.spaced && !nextToken.newLine)) {
if (tag === '?') {
tag = token[0] = 'FUNC_EXIST';
}

View File

@ -217,7 +217,9 @@ grammar =
# Object literal spread properties.
ObjRestValue: [
o 'SimpleObjAssignable ...', -> new Splat new Value $1
o '... SimpleObjAssignable', -> new Splat new Value $2
o 'ObjSpreadExpr ...', -> new Splat $1
o '... ObjSpreadExpr', -> new Splat $2
]
ObjSpreadExpr: [
@ -291,6 +293,7 @@ grammar =
Param: [
o 'ParamVar', -> new Param $1
o 'ParamVar ...', -> new Param $1, null, on
o '... ParamVar', -> new Param $2, null, on
o 'ParamVar = Expression', -> new Param $1, $3
o '...', -> new Expansion
]
@ -306,6 +309,7 @@ grammar =
# A splat that occurs outside of a parameter list.
Splat: [
o 'Expression ...', -> new Splat $1
o '... Expression', -> new Splat $2
]
# Variables and properties that can be assigned to.

View File

@ -235,9 +235,10 @@ exports.Rewriter = class Rewriter
# Recognize standard implicit calls like
# f a, f() b, f? c, h[0] d etc.
# Added support for spread dots on the left side: f ...a
if (tag in IMPLICIT_FUNC and token.spaced or
tag is '?' and i > 0 and not tokens[i - 1].spaced) and
(nextTag in IMPLICIT_CALL or
(nextTag in IMPLICIT_CALL or nextTag is '...' or
nextTag in IMPLICIT_UNSPACED_CALL and
not nextToken.spaced and not nextToken.newLine)
tag = token[0] = 'FUNC_EXIST' if tag is '?'