Permalink
Browse files

Reuse rest/spread element for object rest/spread

Fix #1588
Closes gh-1778
  • Loading branch information...
ariya committed Mar 8, 2017
1 parent 860acd2 commit 60d42ef02882b3680b0348def4be5c32ecfa5b29
View
@@ -16,8 +16,8 @@ export type Expression = ArrayExpression | ArrowFunctionExpression | AssignmentE
ThisExpression | UnaryExpression | UpdateExpression | YieldExpression;
export type FunctionParameter = AssignmentPattern | BindingIdentifier | BindingPattern;
export type ImportDeclarationSpecifier = ImportDefaultSpecifier | ImportNamespaceSpecifier | ImportSpecifier;
-export type ObjectExpressionProperty = Property | SpreadProperty;
-export type ObjectPatternProperty = Property | RestProperty;
+export type ObjectExpressionProperty = Property | SpreadElement;
+export type ObjectPatternProperty = Property | RestElement;
export type Statement = AsyncFunctionDeclaration | BreakStatement | ContinueStatement | DebuggerStatement | DoWhileStatement |
EmptyStatement | ExpressionStatement | Directive | ForStatement | ForInStatement | ForOfStatement |
FunctionDeclaration | IfStatement | ReturnStatement | SwitchStatement | ThrowStatement |
@@ -647,15 +647,6 @@ export class RestElement {
}
}
-export class RestProperty {
- readonly type: string;
- readonly argument: Expression;
- constructor(argument: Expression) {
- this.type = Syntax.RestProperty;
- this.argument = argument;
- }
-}
-
export class ReturnStatement {
readonly type: string;
readonly argument: Expression | null;
@@ -694,15 +685,6 @@ export class SpreadElement {
}
}
-export class SpreadProperty {
- readonly type: string;
- readonly argument: Expression;
- constructor(argument: Expression) {
- this.type = Syntax.SpreadProperty;
- this.argument = argument;
- }
-}
-
export class StaticMemberExpression {
readonly type: string;
readonly computed: boolean;
View
@@ -914,21 +914,14 @@ export class Parser {
return this.finalize(node, new Node.Property(kind, key as Node.PropertyKey, computed, value, method, shorthand));
}
- parseSpreadProperty(): Node.SpreadProperty {
- const node = this.createNode();
- this.expect('...');
- const arg = this.inheritCoverGrammar(this.parseAssignmentExpression);
- return this.finalize(node, new Node.SpreadProperty(arg));
- }
-
parseObjectInitializer(): Node.ObjectExpression {
const node = this.createNode();
this.expect('{');
const properties: Node.ObjectExpressionProperty[] = [];
let hasProto = { value: false };
while (!this.match('}')) {
- properties.push(this.match('...') ? this.parseSpreadProperty() : this.parseObjectProperty(hasProto));
+ properties.push(this.match('...') ? this.parseSpreadElement() : this.parseObjectProperty(hasProto));
if (!this.match('}')) {
this.expectCommaSeparator();
}
@@ -994,10 +987,6 @@ export class Parser {
expr.type = Syntax.RestElement;
this.reinterpretExpressionAsPattern(expr.argument);
break;
- case Syntax.SpreadProperty:
- expr.type = Syntax.RestProperty;
- this.reinterpretExpressionAsPattern(expr.argument);
- break;
case Syntax.ArrayExpression:
expr.type = Syntax.ArrayPattern;
for (let i = 0; i < expr.elements.length; i++) {
@@ -1010,7 +999,7 @@ export class Parser {
expr.type = Syntax.ObjectPattern;
for (let i = 0; i < expr.properties.length; i++) {
const property = expr.properties[i];
- this.reinterpretExpressionAsPattern(property.type === Syntax.SpreadProperty ? property : property.value);
+ this.reinterpretExpressionAsPattern(property.type === Syntax.SpreadElement ? property : property.value);
}
break;
case Syntax.AssignmentExpression:
@@ -1580,7 +1569,6 @@ export class Parser {
this.validateParam(options, param, param.name);
break;
case Syntax.RestElement:
- case Syntax.RestProperty:
this.checkPatternParam(options, param.argument);
break;
case Syntax.AssignmentPattern:
@@ -1596,7 +1584,7 @@ export class Parser {
case Syntax.ObjectPattern:
for (let i = 0; i < param.properties.length; i++) {
const property = param.properties[i];
- this.checkPatternParam(options, (property.type === Syntax.RestProperty) ? property : property.value);
+ this.checkPatternParam(options, (property.type === Syntax.RestElement) ? property : property.value);
}
break;
default:
@@ -1997,7 +1985,7 @@ export class Parser {
return this.finalize(node, new Node.Property('init', key, computed, value, method, shorthand));
}
- parseRestProperty(params, kind): Node.RestProperty {
+ parseRestProperty(params, kind): Node.RestElement {
const node = this.createNode();
this.expect('...');
const arg = this.parsePattern(params);
@@ -2007,7 +1995,7 @@ export class Parser {
if (!this.match('}')) {
this.throwError(Messages.PropertyAfterRestProperty);
}
- return this.finalize(node, new Node.RestProperty(arg));
+ return this.finalize(node, new Node.RestElement(arg));
}
parseObjectPattern(params, kind?: string): Node.ObjectPattern {
View
@@ -47,11 +47,9 @@ export const Syntax = {
Program: 'Program',
Property: 'Property',
RestElement: 'RestElement',
- RestProperty: 'RestProperty',
ReturnStatement: 'ReturnStatement',
SequenceExpression: 'SequenceExpression',
SpreadElement: 'SpreadElement',
- SpreadProperty: 'SpreadProperty',
Super: 'Super',
SwitchCase: 'SwitchCase',
SwitchStatement: 'SwitchStatement',
View
@@ -77,11 +77,9 @@ describe('esprima.Syntax', function () {
Program: 'Program',
Property: 'Property',
RestElement: 'RestElement',
- RestProperty: 'RestProperty',
ReturnStatement: 'ReturnStatement',
SequenceExpression: 'SequenceExpression',
SpreadElement: 'SpreadElement',
- SpreadProperty: 'SpreadProperty',
Super: 'Super',
SwitchCase: 'SwitchCase',
SwitchStatement: 'SwitchStatement',
@@ -67,7 +67,7 @@
}
},
{
- "type": "RestProperty",
+ "type": "RestElement",
"argument": {
"type": "Identifier",
"name": "y",
@@ -178,7 +178,7 @@
}
},
{
- "type": "SpreadProperty",
+ "type": "SpreadElement",
"argument": {
"type": "Identifier",
"name": "y",
@@ -140,7 +140,7 @@
}
},
{
- "type": "RestProperty",
+ "type": "RestElement",
"argument": {
"type": "Identifier",
"name": "z",
@@ -68,7 +68,7 @@
}
},
{
- "type": "RestProperty",
+ "type": "RestElement",
"argument": {
"type": "Identifier",
"name": "y",
@@ -10,7 +10,7 @@
"type": "ObjectPattern",
"properties": [
{
- "type": "RestProperty",
+ "type": "RestElement",
"argument": {
"type": "Identifier",
"name": "x",
@@ -124,7 +124,7 @@
}
},
{
- "type": "RestProperty",
+ "type": "RestElement",
"argument": {
"type": "Identifier",
"name": "z",
@@ -144,7 +144,7 @@
}
},
{
- "type": "SpreadProperty",
+ "type": "SpreadElement",
"argument": {
"type": "Identifier",
"name": "a",
@@ -532,4 +532,4 @@
}
}
]
-}
+}
@@ -86,7 +86,7 @@
}
},
{
- "type": "SpreadProperty",
+ "type": "SpreadElement",
"argument": {
"type": "Identifier",
"name": "a",
@@ -179,7 +179,7 @@
}
},
{
- "type": "SpreadProperty",
+ "type": "SpreadElement",
"argument": {
"type": "Identifier",
"name": "b",
@@ -214,7 +214,7 @@
}
},
{
- "type": "SpreadProperty",
+ "type": "SpreadElement",
"argument": {
"type": "Identifier",
"name": "a",
@@ -710,4 +710,4 @@
}
}
]
-}
+}
@@ -28,7 +28,7 @@
"type": "ObjectExpression",
"properties": [
{
- "type": "SpreadProperty",
+ "type": "SpreadElement",
"argument": {
"type": "Identifier",
"name": "y",
@@ -477,4 +477,4 @@
}
}
]
-}
+}
@@ -28,7 +28,7 @@
"type": "ObjectExpression",
"properties": [
{
- "type": "SpreadProperty",
+ "type": "SpreadElement",
"argument": {
"type": "Identifier",
"name": "x",
@@ -63,7 +63,7 @@
}
},
{
- "type": "SpreadProperty",
+ "type": "SpreadElement",
"argument": {
"type": "Identifier",
"name": "y",
@@ -361,4 +361,4 @@
}
}
]
-}
+}
@@ -28,7 +28,7 @@
"type": "ObjectExpression",
"properties": [
{
- "type": "SpreadProperty",
+ "type": "SpreadElement",
"argument": {
"type": "Identifier",
"name": "y",
@@ -382,4 +382,4 @@
}
}
]
-}
+}
@@ -28,7 +28,7 @@
"type": "ObjectExpression",
"properties": [
{
- "type": "SpreadProperty",
+ "type": "SpreadElement",
"argument": {
"type": "Identifier",
"name": "y",
@@ -234,4 +234,4 @@
}
}
]
-}
+}
@@ -28,7 +28,7 @@
"type": "ObjectExpression",
"properties": [
{
- "type": "SpreadProperty",
+ "type": "SpreadElement",
"argument": {
"type": "Identifier",
"name": "y",
@@ -63,7 +63,7 @@
}
},
{
- "type": "SpreadProperty",
+ "type": "SpreadElement",
"argument": {
"type": "ObjectExpression",
"properties": [
@@ -547,4 +547,4 @@
}
}
]
-}
+}
@@ -28,7 +28,7 @@
"type": "ObjectExpression",
"properties": [
{
- "type": "SpreadProperty",
+ "type": "SpreadElement",
"argument": {
"type": "Identifier",
"name": "undefined",
@@ -63,7 +63,7 @@
}
},
{
- "type": "SpreadProperty",
+ "type": "SpreadElement",
"argument": {
"type": "Literal",
"value": null,
@@ -342,4 +342,4 @@
}
}
]
-}
+}

0 comments on commit 60d42ef

Please sign in to comment.