diff --git a/packages/babel-parser/src/parser/lval.js b/packages/babel-parser/src/parser/lval.js index 1a9a690388..2d1f13ad2e 100644 --- a/packages/babel-parser/src/parser/lval.js +++ b/packages/babel-parser/src/parser/lval.js @@ -149,12 +149,10 @@ export default class LValParser extends NodeUtils { const arg = last.argument; this.toAssignable(arg, isBinding, contextDescription); if ( - [ - "Identifier", - "MemberExpression", - "ArrayPattern", - "ObjectPattern", - ].indexOf(arg.type) === -1 + arg.type !== "Identifier" && + arg.type !== "MemberExpression" && + arg.type !== "ArrayPattern" && + arg.type !== "ObjectPattern" ) { this.unexpected(arg.start); } @@ -430,13 +428,12 @@ export default class LValParser extends NodeUtils { } checkToRestConversion(node: SpreadElement): void { - const validArgumentTypes = ["Identifier", "MemberExpression"]; - - if (validArgumentTypes.indexOf(node.argument.type) !== -1) { - return; + if ( + node.argument.type !== "Identifier" && + node.argument.type !== "MemberExpression" + ) { + this.raise(node.argument.start, "Invalid rest operator's argument"); } - - this.raise(node.argument.start, "Invalid rest operator's argument"); } checkCommaAfterRest(close: TokenType, kind: string): void { diff --git a/packages/babel-parser/src/parser/node.js b/packages/babel-parser/src/parser/node.js index 73223eea85..5ed447018d 100644 --- a/packages/babel-parser/src/parser/node.js +++ b/packages/babel-parser/src/parser/node.js @@ -7,8 +7,6 @@ import type { Comment, Node as NodeType, NodeBase } from "../types"; // Start an AST node, attaching a start offset. -const commentKeys = ["leadingComments", "trailingComments", "innerComments"]; - class Node implements NodeBase { constructor(parser: Parser, pos: number, loc: Position) { this.type = ""; @@ -34,7 +32,11 @@ class Node implements NodeBase { const node2: any = new Node(); Object.keys(this).forEach(key => { // Do not clone comments that are already attached to the node - if (commentKeys.indexOf(key) < 0) { + if ( + key !== "leadingComments" && + key !== "trailingComments" && + key !== "innerComments" + ) { // $FlowIgnore node2[key] = this[key]; }