[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:
parent
fe2d2a99ea
commit
8d90dc0d10
41
ast/spec.md
41
ast/spec.md
@ -1,6 +1,7 @@
|
||||
These are the core Babylon AST node types.
|
||||
|
||||
- [Node objects](#node-objects)
|
||||
- [Changes](#changes)
|
||||
- [Identifier](#identifier)
|
||||
- [Literals](#literals)
|
||||
- [RegExpLiteral](#regexpliteral)
|
||||
@ -55,8 +56,6 @@ These are the core Babylon AST node types.
|
||||
- [ObjectMember](#objectmember)
|
||||
- [ObjectProperty](#objectproperty)
|
||||
- [ObjectMethod](#objectmethod)
|
||||
- [RestProperty](#restproperty)
|
||||
- [SpreadProperty](#spreadproperty)
|
||||
- [FunctionExpression](#functionexpression)
|
||||
- [Unary operations](#unary-operations)
|
||||
- [UnaryExpression](#unaryexpression)
|
||||
@ -139,6 +138,22 @@ interface Position {
|
||||
}
|
||||
```
|
||||
|
||||
# Changes
|
||||
|
||||
### Babylon 7
|
||||
|
||||
Flow: Node renamed from `ExistentialTypeParam` to `ExistsTypeAnnotation` [#322](https://github.com/babel/babylon/pull/322)
|
||||
|
||||
Flow: Node renamed from `NumericLiteralTypeAnnotation` to `NumberLiteralTypeAnnotation` [babel/babylon#332](https://github.com/babel/babylon/pull/332)
|
||||
|
||||
Flow: Node `Variance` which replaces the string value of the `variance` field on several nodes [babel/babylon#333](https://github.com/babel/babylon/pull/333)
|
||||
|
||||
Flow: `ObjectTypeIndexer` location info matches Flow's better [babel/babylon#228](https://github.com/babel/babylon/pull/228)
|
||||
|
||||
Node `ForAwaitStatement` has been removed [#349](https://github.com/babel/babylon/pull/349) in favor of modifying `ForOfStatement`
|
||||
|
||||
`RestProperty` and `SpreadProperty` have been dropped in favor of `RestElement` and `SpreadElement`.
|
||||
|
||||
# Identifier
|
||||
|
||||
```js
|
||||
@ -641,7 +656,7 @@ An array expression.
|
||||
```js
|
||||
interface ObjectExpression <: Expression {
|
||||
type: "ObjectExpression";
|
||||
properties: [ ObjectProperty | ObjectMethod | SpreadProperty ];
|
||||
properties: [ ObjectProperty | ObjectMethod | SpreadElement ];
|
||||
}
|
||||
```
|
||||
|
||||
@ -676,24 +691,6 @@ interface ObjectMethod <: ObjectMember, Function {
|
||||
}
|
||||
```
|
||||
|
||||
## RestProperty
|
||||
|
||||
```js
|
||||
interface RestProperty <: Node {
|
||||
type: "RestProperty";
|
||||
argument: Expression;
|
||||
}
|
||||
```
|
||||
|
||||
## SpreadProperty
|
||||
|
||||
```js
|
||||
interface SpreadProperty <: Node {
|
||||
type: "SpreadProperty";
|
||||
argument: Expression;
|
||||
}
|
||||
```
|
||||
|
||||
## FunctionExpression
|
||||
|
||||
```js
|
||||
@ -960,7 +957,7 @@ interface AssignmentProperty <: ObjectProperty {
|
||||
|
||||
interface ObjectPattern <: Pattern {
|
||||
type: "ObjectPattern";
|
||||
properties: [ AssignmentProperty | RestProperty ];
|
||||
properties: [ AssignmentProperty | RestPattern ];
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
3
test/fixtures/es2015/array-rest-spread/invalid-location/options.json
vendored
Normal file
3
test/fixtures/es2015/array-rest-spread/invalid-location/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "The rest element has to be the last element when destructuring (1:1)"
|
||||
}
|
||||
@ -160,7 +160,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "RestProperty",
|
||||
"type": "RestElement",
|
||||
"start": 21,
|
||||
"end": 29,
|
||||
"loc": {
|
||||
@ -218,4 +218,4 @@
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
{
|
||||
"throws": "Invalid left-hand side in assignment expression (1:1)"
|
||||
}
|
||||
@ -73,7 +73,7 @@
|
||||
},
|
||||
"properties": [
|
||||
{
|
||||
"type": "RestProperty",
|
||||
"type": "RestElement",
|
||||
"start": 5,
|
||||
"end": 9,
|
||||
"loc": {
|
||||
@ -128,4 +128,4 @@
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,4 +208,4 @@
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@
|
||||
},
|
||||
"properties": [
|
||||
{
|
||||
"type": "RestProperty",
|
||||
"type": "RestElement",
|
||||
"start": 5,
|
||||
"end": 11,
|
||||
"loc": {
|
||||
@ -240,4 +240,4 @@
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@
|
||||
},
|
||||
"properties": [
|
||||
{
|
||||
"type": "RestProperty",
|
||||
"type": "RestElement",
|
||||
"start": 6,
|
||||
"end": 18,
|
||||
"loc": {
|
||||
@ -275,4 +275,4 @@
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "RestProperty",
|
||||
"type": "RestElement",
|
||||
"start": 8,
|
||||
"end": 12,
|
||||
"loc": {
|
||||
@ -178,4 +178,4 @@
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "RestProperty",
|
||||
"type": "RestElement",
|
||||
"start": 14,
|
||||
"end": 18,
|
||||
"loc": {
|
||||
@ -184,4 +184,4 @@
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,7 +89,7 @@
|
||||
},
|
||||
"properties": [
|
||||
{
|
||||
"type": "SpreadProperty",
|
||||
"type": "SpreadElement",
|
||||
"start": 9,
|
||||
"end": 13,
|
||||
"loc": {
|
||||
@ -127,4 +127,4 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,7 +139,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "SpreadProperty",
|
||||
"type": "SpreadElement",
|
||||
"start": 8,
|
||||
"end": 12,
|
||||
"loc": {
|
||||
@ -176,4 +176,4 @@
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,7 +113,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "SpreadProperty",
|
||||
"type": "SpreadElement",
|
||||
"start": 5,
|
||||
"end": 9,
|
||||
"loc": {
|
||||
@ -200,7 +200,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "SpreadProperty",
|
||||
"type": "SpreadElement",
|
||||
"start": 14,
|
||||
"end": 18,
|
||||
"loc": {
|
||||
@ -296,4 +296,4 @@
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user