1 | import {charCodes} from "./charcodes";
|
2 | import {WHITESPACE_CHARS} from "./whitespace";
|
3 |
|
4 | function computeIsIdentifierChar(code) {
|
5 | if (code < 48) return code === 36;
|
6 | if (code < 58) return true;
|
7 | if (code < 65) return false;
|
8 | if (code < 91) return true;
|
9 | if (code < 97) return code === 95;
|
10 | if (code < 123) return true;
|
11 | if (code < 128) return false;
|
12 | throw new Error("Should not be called with non-ASCII char code.");
|
13 | }
|
14 |
|
15 | export const IS_IDENTIFIER_CHAR = new Uint8Array(65536);
|
16 | for (let i = 0; i < 128; i++) {
|
17 | IS_IDENTIFIER_CHAR[i] = computeIsIdentifierChar(i) ? 1 : 0;
|
18 | }
|
19 | for (let i = 128; i < 65536; i++) {
|
20 | IS_IDENTIFIER_CHAR[i] = 1;
|
21 | }
|
22 |
|
23 |
|
24 |
|
25 | for (const whitespaceChar of WHITESPACE_CHARS) {
|
26 | IS_IDENTIFIER_CHAR[whitespaceChar] = 0;
|
27 | }
|
28 | IS_IDENTIFIER_CHAR[0x2028] = 0;
|
29 | IS_IDENTIFIER_CHAR[0x2029] = 0;
|
30 |
|
31 | export const IS_IDENTIFIER_START = IS_IDENTIFIER_CHAR.slice();
|
32 | for (let numChar = charCodes.digit0; numChar <= charCodes.digit9; numChar++) {
|
33 | IS_IDENTIFIER_START[numChar] = 0;
|
34 | }
|