refactor: avoid parsing logic on locations (#13200)

This commit is contained in:
Huáng Jùnliàng 2021-04-25 09:15:48 -04:00 committed by GitHub
parent fb908fd87e
commit 10f4d08efb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -252,16 +252,11 @@ export default (superClass: Class<Parser>): Class<Parser> =>
flowParsePredicate(): N.FlowType { flowParsePredicate(): N.FlowType {
const node = this.startNode(); const node = this.startNode();
const moduloLoc = this.state.startLoc;
const moduloPos = this.state.start; const moduloPos = this.state.start;
this.expect(tt.modulo); this.next(); // eat `%`
const checksLoc = this.state.startLoc;
this.expectContextual("checks"); this.expectContextual("checks");
// Force '%' and 'checks' to be adjacent // Force '%' and 'checks' to be adjacent
if ( if (this.state.lastTokStart > moduloPos + 1) {
moduloLoc.line !== checksLoc.line ||
moduloLoc.column !== checksLoc.column - 1
) {
this.raise(moduloPos, FlowErrors.UnexpectedSpaceBetweenModuloChecks); this.raise(moduloPos, FlowErrors.UnexpectedSpaceBetweenModuloChecks);
} }
if (this.eat(tt.parenL)) { if (this.eat(tt.parenL)) {