perf: use normal equality check in stead of indexOf
This commit is contained in:
parent
48fd387779
commit
25a8db2a29
@ -149,12 +149,10 @@ export default class LValParser extends NodeUtils {
|
|||||||
const arg = last.argument;
|
const arg = last.argument;
|
||||||
this.toAssignable(arg, isBinding, contextDescription);
|
this.toAssignable(arg, isBinding, contextDescription);
|
||||||
if (
|
if (
|
||||||
[
|
arg.type !== "Identifier" &&
|
||||||
"Identifier",
|
arg.type !== "MemberExpression" &&
|
||||||
"MemberExpression",
|
arg.type !== "ArrayPattern" &&
|
||||||
"ArrayPattern",
|
arg.type !== "ObjectPattern"
|
||||||
"ObjectPattern",
|
|
||||||
].indexOf(arg.type) === -1
|
|
||||||
) {
|
) {
|
||||||
this.unexpected(arg.start);
|
this.unexpected(arg.start);
|
||||||
}
|
}
|
||||||
@ -430,14 +428,13 @@ export default class LValParser extends NodeUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkToRestConversion(node: SpreadElement): void {
|
checkToRestConversion(node: SpreadElement): void {
|
||||||
const validArgumentTypes = ["Identifier", "MemberExpression"];
|
if (
|
||||||
|
node.argument.type !== "Identifier" &&
|
||||||
if (validArgumentTypes.indexOf(node.argument.type) !== -1) {
|
node.argument.type !== "MemberExpression"
|
||||||
return;
|
) {
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
checkCommaAfterRest(close: TokenType, kind: string): void {
|
||||||
if (this.match(tt.comma)) {
|
if (this.match(tt.comma)) {
|
||||||
|
|||||||
@ -7,8 +7,6 @@ import type { Comment, Node as NodeType, NodeBase } from "../types";
|
|||||||
|
|
||||||
// Start an AST node, attaching a start offset.
|
// Start an AST node, attaching a start offset.
|
||||||
|
|
||||||
const commentKeys = ["leadingComments", "trailingComments", "innerComments"];
|
|
||||||
|
|
||||||
class Node implements NodeBase {
|
class Node implements NodeBase {
|
||||||
constructor(parser: Parser, pos: number, loc: Position) {
|
constructor(parser: Parser, pos: number, loc: Position) {
|
||||||
this.type = "";
|
this.type = "";
|
||||||
@ -34,7 +32,11 @@ class Node implements NodeBase {
|
|||||||
const node2: any = new Node();
|
const node2: any = new Node();
|
||||||
Object.keys(this).forEach(key => {
|
Object.keys(this).forEach(key => {
|
||||||
// Do not clone comments that are already attached to the node
|
// Do not clone comments that are already attached to the node
|
||||||
if (commentKeys.indexOf(key) < 0) {
|
if (
|
||||||
|
key !== "leadingComments" &&
|
||||||
|
key !== "trailingComments" &&
|
||||||
|
key !== "innerComments"
|
||||||
|
) {
|
||||||
// $FlowIgnore
|
// $FlowIgnore
|
||||||
node2[key] = this[key];
|
node2[key] = this[key];
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user