[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:
Henry Zhu
2017-02-28 12:31:58 -05:00
committed by GitHub
parent fe2d2a99ea
commit 8d90dc0d10
17 changed files with 48 additions and 53 deletions

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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);