[7.0] Change RestProperty/SpreadProperty to RestElement/SpreadElement (#384)
* [7.0] Change RestProperty/SpreadProperty to RestElement/SpreadElement * Fix rest element in array pattern at invalid location
This commit is contained in:
@@ -739,7 +739,7 @@ pp.parseObj = function (isPattern, refShorthandDefaultPos) {
|
||||
|
||||
if (this.hasPlugin("objectRestSpread") && this.match(tt.ellipsis)) {
|
||||
prop = this.parseSpread(isPattern ? { start: 0 } : undefined);
|
||||
prop.type = isPattern ? "RestProperty" : "SpreadProperty";
|
||||
prop.type = isPattern ? "RestElement" : "SpreadElement";
|
||||
if (isPattern) this.toAssignable(prop.argument, true, "object pattern");
|
||||
node.properties.push(prop);
|
||||
if (isPattern) {
|
||||
|
||||
@@ -34,8 +34,8 @@ pp.toAssignable = function (node, isBinding, contextDescription) {
|
||||
this.toAssignable(node.value, isBinding, contextDescription);
|
||||
break;
|
||||
|
||||
case "SpreadProperty":
|
||||
node.type = "RestProperty";
|
||||
case "SpreadElement":
|
||||
node.type = "RestElement";
|
||||
break;
|
||||
|
||||
case "ArrayExpression":
|
||||
@@ -85,6 +85,8 @@ pp.toAssignableList = function (exprList, isBinding, contextDescription) {
|
||||
}
|
||||
for (let i = 0; i < end; i++) {
|
||||
const elt = exprList[i];
|
||||
if (elt && elt.type === "SpreadElement")
|
||||
this.raise(elt.start, "The rest element has to be the last element when destructuring");
|
||||
if (elt) this.toAssignable(elt, isBinding, contextDescription);
|
||||
}
|
||||
return exprList;
|
||||
@@ -246,10 +248,6 @@ pp.checkLVal = function (expr, isBinding, checkClashes, contextDescription) {
|
||||
this.checkLVal(expr.left, isBinding, checkClashes, "assignment pattern");
|
||||
break;
|
||||
|
||||
case "RestProperty":
|
||||
this.checkLVal(expr.argument, isBinding, checkClashes, "rest property");
|
||||
break;
|
||||
|
||||
case "RestElement":
|
||||
this.checkLVal(expr.argument, isBinding, checkClashes, "rest element");
|
||||
break;
|
||||
|
||||
@@ -941,7 +941,7 @@ pp.checkDeclaration = function(node) {
|
||||
}
|
||||
} else if (node.type === "ObjectProperty") {
|
||||
this.checkDeclaration(node.value);
|
||||
} else if (node.type === "RestElement" || node.type === "RestProperty") {
|
||||
} else if (node.type === "RestElement") {
|
||||
this.checkDeclaration(node.argument);
|
||||
} else if (node.type === "Identifier") {
|
||||
this.checkDuplicateExports(node, node.name);
|
||||
|
||||
Reference in New Issue
Block a user