Skip to content

Commit

Permalink
refactor: simplify isLookaheadRelational to isLookaheadToken_lt
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Aug 5, 2020
1 parent 4787231 commit 901ca21
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions packages/babel-parser/src/plugins/flow.js
Expand Up @@ -2873,7 +2873,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
noCalls: ?boolean,
subscriptState: N.ParseSubscriptState,
): N.Expression {
if (this.match(tt.questionDot) && this.isLookaheadRelational("<")) {
if (this.match(tt.questionDot) && this.isLookaheadToken_lt()) {
subscriptState.optionalChainMember = true;
if (noCalls) {
subscriptState.stop = true;
Expand Down Expand Up @@ -3476,15 +3476,13 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
}
isLookaheadRelational(op: "<" | ">"): boolean {
// check if the next token is a tt.relation("<")
isLookaheadToken_lt(): boolean {
const next = this.nextTokenStart();
if (this.input.charAt(next) === op) {
if (next + 1 === this.input.length) {
return true;
}
if (this.input.charCodeAt(next) === charCodes.lessThan) {
const afterNext = this.input.charCodeAt(next + 1);
return (
afterNext !== op.charCodeAt(0) && afterNext !== charCodes.equalsTo
afterNext !== charCodes.lessThan && afterNext !== charCodes.equalsTo
);
}
return false;
Expand Down

0 comments on commit 901ca21

Please sign in to comment.