Use charCodes at more places in the parser (#8176)
This commit is contained in:
parent
ba98cf782a
commit
07c88e6f0b
@ -1811,7 +1811,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
// ensure that inside flow types, we bypass the jsx parser plugin
|
// ensure that inside flow types, we bypass the jsx parser plugin
|
||||||
readToken(code: number): void {
|
readToken(code: number): void {
|
||||||
const next = this.input.charCodeAt(this.state.pos + 1);
|
const next = this.input.charCodeAt(this.state.pos + 1);
|
||||||
if (this.state.inType && (code === 62 || code === 60)) {
|
if (
|
||||||
|
this.state.inType &&
|
||||||
|
(code === charCodes.greaterThan || code === charCodes.lessThan)
|
||||||
|
) {
|
||||||
return this.finishOp(tt.relational, 1);
|
return this.finishOp(tt.relational, 1);
|
||||||
} else if (isIteratorStart(code, next)) {
|
} else if (isIteratorStart(code, next)) {
|
||||||
this.state.isIterator = true;
|
this.state.isIterator = true;
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
|
import * as charCodes from "charcodes";
|
||||||
|
|
||||||
function makePredicate(words: string): (str: string) => boolean {
|
function makePredicate(words: string): (str: string) => boolean {
|
||||||
const wordsArr = words.split(" ");
|
const wordsArr = words.split(" ");
|
||||||
return function(str) {
|
return function(str) {
|
||||||
@ -75,10 +77,10 @@ function isInAstralSet(code: number, set: $ReadOnlyArray<number>): boolean {
|
|||||||
// Test whether a given character code starts an identifier.
|
// Test whether a given character code starts an identifier.
|
||||||
|
|
||||||
export function isIdentifierStart(code: number): boolean {
|
export function isIdentifierStart(code: number): boolean {
|
||||||
if (code < 65) return code === 36;
|
if (code < charCodes.uppercaseA) return code === charCodes.dollarSign;
|
||||||
if (code < 91) return true;
|
if (code <= charCodes.uppercaseZ) return true;
|
||||||
if (code < 97) return code === 95;
|
if (code < charCodes.lowercaseA) return code === charCodes.underscore;
|
||||||
if (code < 123) return true;
|
if (code <= charCodes.lowercaseZ) return true;
|
||||||
if (code <= 0xffff) {
|
if (code <= 0xffff) {
|
||||||
return (
|
return (
|
||||||
code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code))
|
code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code))
|
||||||
@ -87,21 +89,21 @@ export function isIdentifierStart(code: number): boolean {
|
|||||||
return isInAstralSet(code, astralIdentifierStartCodes);
|
return isInAstralSet(code, astralIdentifierStartCodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test whether a current state character code and next character code is @
|
// Test whether a current state character code and next character code is @
|
||||||
|
|
||||||
export function isIteratorStart(current: number, next: number): boolean {
|
export function isIteratorStart(current: number, next: number): boolean {
|
||||||
return current === 64 && next === 64;
|
return current === charCodes.atSign && next === charCodes.atSign;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test whether a given character is part of an identifier.
|
// Test whether a given character is part of an identifier.
|
||||||
|
|
||||||
export function isIdentifierChar(code: number): boolean {
|
export function isIdentifierChar(code: number): boolean {
|
||||||
if (code < 48) return code === 36;
|
if (code < charCodes.digit0) return code === charCodes.dollarSign;
|
||||||
if (code < 58) return true;
|
if (code < charCodes.colon) return true;
|
||||||
if (code < 65) return false;
|
if (code < charCodes.uppercaseA) return false;
|
||||||
if (code < 91) return true;
|
if (code <= charCodes.uppercaseZ) return true;
|
||||||
if (code < 97) return code === 95;
|
if (code < charCodes.lowercaseA) return code === charCodes.underscore;
|
||||||
if (code < 123) return true;
|
if (code <= charCodes.lowercaseZ) return true;
|
||||||
if (code <= 0xffff) {
|
if (code <= 0xffff) {
|
||||||
return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
|
return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user