feat: setup constants

This commit is contained in:
Sven SAULEAU 2017-11-02 09:10:26 +01:00
parent 3b540e3f5a
commit 459e289d63
No known key found for this signature in database
GPG Key ID: F5464AC83B687AD1
2 changed files with 39 additions and 12 deletions

View File

@ -4,6 +4,7 @@
import type { Options } from "../options";
import type { Position } from "../util/location";
import charCodes from "../util/charCodes";
import {
isIdentifierStart,
isIdentifierChar,
@ -328,31 +329,31 @@ export default class Tokenizer extends LocationParser {
loop: while (this.state.pos < this.input.length) {
const ch = this.input.charCodeAt(this.state.pos);
switch (ch) {
case 32: // space
case 160: // non-breaking space
case charCodes.space:
case charCodes.nonBreakingSpace:
++this.state.pos;
break;
case 13: // '\r' carriage return
case charCodes.carriageReturn:
if (this.input.charCodeAt(this.state.pos + 1) === 10) {
++this.state.pos;
}
case 10: // '\n' line feed
case 8232: // line separator
case 8233: // paragraph separator
case charCodes.lineFeed:
case charCodes.lineSeparator:
case charCodes.paragraphSeparator:
++this.state.pos;
++this.state.curLine;
this.state.lineStart = this.state.pos;
break;
case 47: // '/'
case charCodes.slash: // '/'
switch (this.input.charCodeAt(this.state.pos + 1)) {
case 42: // '*'
case charCodes.asterisk: // '*'
this.skipBlockComment();
break;
case 47:
case charCodes.slash:
this.skipLineComment(2);
break;
@ -873,7 +874,7 @@ export default class Tokenizer extends LocationParser {
val = code - 97 + 10; // a
} else if (code >= 65) {
val = code - 65 + 10; // A
} else if (code >= 48 && code <= 57) {
} else if (charCodes.isIn09(code)) {
val = code - 48; // 0-9
} else {
val = Infinity;
@ -901,7 +902,7 @@ export default class Tokenizer extends LocationParser {
this.raise(this.state.start + 2, "Expected number in radix " + radix);
if (this.hasPlugin("bigInt")) {
if (this.input.charCodeAt(this.state.pos) === 0x6e) {
if (this.input.charCodeAt(this.state.pos) === charCodes.letterN) {
// 'n'
++this.state.pos;
isBigInt = true;
@ -924,7 +925,7 @@ export default class Tokenizer extends LocationParser {
readNumber(startsWithDot: boolean): void {
const start = this.state.pos;
let octal = this.input.charCodeAt(start) === 0x30; // '0'
let octal = this.input.charCodeAt(start) === charCodes.digit0; // '0'
let isFloat = false;
let isBigInt = false;

View File

@ -0,0 +1,26 @@
// @flow
type Char = number;
const charCodes = {
space: 32,
nonBreakingSpace: 160,
carriageReturn: 13, // '\r'
lineFeed: 10, // '\n'
lineSeparator: 8232,
paragraphSeparator: 8233,
slash: 47, // '/'
asterisk: 42, // '*'
letterN: 110, // 'n'
digit0: 48, // '0'
digit9: 57, // '9'
};
export function isIn09(code: Char): boolean {
return code >= charCodes.digit0 && code <= charCodes.digit9;
}
export default charCodes;