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:
parent
35eb58fae8
commit
3be9038028
|
@ -146,8 +146,12 @@
|
||||||
ObjRestValue: [
|
ObjRestValue: [
|
||||||
o('SimpleObjAssignable ...', function() {
|
o('SimpleObjAssignable ...', function() {
|
||||||
return new Splat(new Value($1));
|
return new Splat(new Value($1));
|
||||||
|
}), o('... SimpleObjAssignable', function() {
|
||||||
|
return new Splat(new Value($2));
|
||||||
}), o('ObjSpreadExpr ...', function() {
|
}), o('ObjSpreadExpr ...', function() {
|
||||||
return new Splat($1);
|
return new Splat($1);
|
||||||
|
}), o('... ObjSpreadExpr', function() {
|
||||||
|
return new Splat($2);
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
ObjSpreadExpr: [
|
ObjSpreadExpr: [
|
||||||
|
@ -225,6 +229,8 @@
|
||||||
return new Param($1);
|
return new Param($1);
|
||||||
}), o('ParamVar ...', function() {
|
}), o('ParamVar ...', function() {
|
||||||
return new Param($1, null, true);
|
return new Param($1, null, true);
|
||||||
|
}), o('... ParamVar', function() {
|
||||||
|
return new Param($2, null, true);
|
||||||
}), o('ParamVar = Expression', function() {
|
}), o('ParamVar = Expression', function() {
|
||||||
return new Param($1, $3);
|
return new Param($1, $3);
|
||||||
}), o('...', function() {
|
}), o('...', function() {
|
||||||
|
@ -235,6 +241,8 @@
|
||||||
Splat: [
|
Splat: [
|
||||||
o('Expression ...', function() {
|
o('Expression ...', function() {
|
||||||
return new Splat($1);
|
return new Splat($1);
|
||||||
|
}), o('... Expression', function() {
|
||||||
|
return new Splat($2);
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
SimpleAssignable: [
|
SimpleAssignable: [
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -295,7 +295,7 @@
|
||||||
}
|
}
|
||||||
start = stack.pop();
|
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 === '?') {
|
if (tag === '?') {
|
||||||
tag = token[0] = 'FUNC_EXIST';
|
tag = token[0] = 'FUNC_EXIST';
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,7 +217,9 @@ grammar =
|
||||||
# Object literal spread properties.
|
# Object literal spread properties.
|
||||||
ObjRestValue: [
|
ObjRestValue: [
|
||||||
o 'SimpleObjAssignable ...', -> new Splat new Value $1
|
o 'SimpleObjAssignable ...', -> new Splat new Value $1
|
||||||
|
o '... SimpleObjAssignable', -> new Splat new Value $2
|
||||||
o 'ObjSpreadExpr ...', -> new Splat $1
|
o 'ObjSpreadExpr ...', -> new Splat $1
|
||||||
|
o '... ObjSpreadExpr', -> new Splat $2
|
||||||
]
|
]
|
||||||
|
|
||||||
ObjSpreadExpr: [
|
ObjSpreadExpr: [
|
||||||
|
@ -291,6 +293,7 @@ grammar =
|
||||||
Param: [
|
Param: [
|
||||||
o 'ParamVar', -> new Param $1
|
o 'ParamVar', -> new Param $1
|
||||||
o 'ParamVar ...', -> new Param $1, null, on
|
o 'ParamVar ...', -> new Param $1, null, on
|
||||||
|
o '... ParamVar', -> new Param $2, null, on
|
||||||
o 'ParamVar = Expression', -> new Param $1, $3
|
o 'ParamVar = Expression', -> new Param $1, $3
|
||||||
o '...', -> new Expansion
|
o '...', -> new Expansion
|
||||||
]
|
]
|
||||||
|
@ -306,6 +309,7 @@ grammar =
|
||||||
# A splat that occurs outside of a parameter list.
|
# A splat that occurs outside of a parameter list.
|
||||||
Splat: [
|
Splat: [
|
||||||
o 'Expression ...', -> new Splat $1
|
o 'Expression ...', -> new Splat $1
|
||||||
|
o '... Expression', -> new Splat $2
|
||||||
]
|
]
|
||||||
|
|
||||||
# Variables and properties that can be assigned to.
|
# Variables and properties that can be assigned to.
|
||||||
|
|
|
@ -235,9 +235,10 @@ exports.Rewriter = class Rewriter
|
||||||
|
|
||||||
# Recognize standard implicit calls like
|
# Recognize standard implicit calls like
|
||||||
# f a, f() b, f? c, h[0] d etc.
|
# 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
|
if (tag in IMPLICIT_FUNC and token.spaced or
|
||||||
tag is '?' and i > 0 and not tokens[i - 1].spaced) and
|
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
|
nextTag in IMPLICIT_UNSPACED_CALL and
|
||||||
not nextToken.spaced and not nextToken.newLine)
|
not nextToken.spaced and not nextToken.newLine)
|
||||||
tag = token[0] = 'FUNC_EXIST' if tag is '?'
|
tag = token[0] = 'FUNC_EXIST' if tag is '?'
|
||||||
|
|
Loading…
Reference in New Issue