Skip to content

Commit

Permalink
Avoid lookahead
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki committed Feb 12, 2021
1 parent d80836c commit 370953a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 6 additions & 8 deletions packages/babel-parser/src/parser/expression.js
Expand Up @@ -515,14 +515,12 @@ export default class ExpressionParser extends LValParser {
this.next();
return this.parseAwait(startPos, startLoc);
}
if (this.isContextual("module")) {
const lookahead = this.lookahead();
if (
lookahead.type === tt.braceL &&
!this.hasPrecedingLineBreak(lookahead)
) {
return this.parseModuleExpression();
}
if (
this.isContextual("module") &&
this.lookaheadCharCode() === charCodes.leftCurlyBrace &&
!this.hasFollowingLineBreak()
) {
return this.parseModuleExpression();
}
const update = this.match(tt.incDec);
const node = this.startNode();
Expand Down
6 changes: 4 additions & 2 deletions packages/babel-parser/src/parser/util.js
Expand Up @@ -90,8 +90,10 @@ export default class UtilParser extends Tokenizer {
);
}

hasPrecedingLineBreak(state: State = this.state): boolean {
return lineBreak.test(this.input.slice(state.lastTokEnd, state.start));
hasPrecedingLineBreak(): boolean {
return lineBreak.test(
this.input.slice(this.state.lastTokEnd, this.state.start),
);
}

hasFollowingLineBreak(): boolean {
Expand Down

0 comments on commit 370953a

Please sign in to comment.