| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 52255f5 commit ab5a480
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,7 +30,7 @@ import { | |||
| 30 | 30 | normalizePath, | |
| 31 | 31 | resolvePath, | |
| 32 | 32 | CharCode, | |
| 33 | - isTrivialAlphanum | ||
| 33 | + isAlphaOrDecimal | ||
| 34 | 34 | } from "./util"; | |
| 35 | 35 | ||
| 36 | 36 | import { | |
@@ -2347,7 +2347,7 @@ export function mangleInternalPath(path: string): string { | |||
| 2347 | 2347 | if (pos >= 0 && len - pos >= 2) { // at least one char plus dot | |
| 2348 | 2348 | let cur = pos; | |
| 2349 | 2349 | while (++cur < len) { | |
| 2350 | - if (!isTrivialAlphanum(path.charCodeAt(cur))) { | ||
| 2350 | + if (!isAlphaOrDecimal(path.charCodeAt(cur))) { | ||
| 2351 | 2351 | assert(false); // not a valid external path | |
| 2352 | 2352 | return path; | |
| 2353 | 2353 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,8 +28,8 @@ import { | |||
| 28 | 28 | isWhiteSpace, | |
| 29 | 29 | isIdentifierStart, | |
| 30 | 30 | isIdentifierPart, | |
| 31 | - isDecimalDigit, | ||
| 32 | - isOctalDigit | ||
| 31 | + isDecimal, | ||
| 32 | + isOctal | ||
| 33 | 33 | } from "./util"; | |
| 34 | 34 | ||
| 35 | 35 | /** Named token types. */ | |
@@ -703,7 +703,7 @@ export class Tokenizer extends DiagnosticEmitter { | |||
| 703 | 703 | ++pos; | |
| 704 | 704 | if (maxTokenLength > 1 && pos < end) { | |
| 705 | 705 | let chr = text.charCodeAt(pos); | |
| 706 | - if (isDecimalDigit(chr)) { | ||
| 706 | + if (isDecimal(chr)) { | ||
| 707 | 707 | this.pos = pos - 1; | |
| 708 | 708 | return Token.FLOATLITERAL; // expects a call to readFloat | |
| 709 | 709 | } | |
@@ -1177,7 +1177,7 @@ export class Tokenizer extends DiagnosticEmitter { | |||
| 1177 | 1177 | var c = text.charCodeAt(this.pos++); | |
| 1178 | 1178 | switch (c) { | |
| 1179 | 1179 | case CharCode._0: { | |
| 1180 | - if (isTaggedTemplate && this.pos < end && isDecimalDigit(text.charCodeAt(this.pos))) { | ||
| 1180 | + if (isTaggedTemplate && this.pos < end && isDecimal(text.charCodeAt(this.pos))) { | ||
| 1181 | 1181 | ++this.pos; | |
| 1182 | 1182 | return text.substring(start, this.pos); | |
| 1183 | 1183 | } | |
@@ -1331,7 +1331,7 @@ export class Tokenizer extends DiagnosticEmitter { | |||
| 1331 | 1331 | return this.readOctalInteger(); | |
| 1332 | 1332 | } | |
| 1333 | 1333 | } | |
| 1334 | - if (isOctalDigit(text.charCodeAt(pos + 1))) { | ||
| 1334 | + if (isOctal(text.charCodeAt(pos + 1))) { | ||
| 1335 | 1335 | let start = pos; | |
| 1336 | 1336 | this.pos = pos + 1; | |
| 1337 | 1337 | let value = this.readOctalInteger(); | |
@@ -1578,7 +1578,7 @@ export class Tokenizer extends DiagnosticEmitter { | |||
| 1578 | 1578 | if ( | |
| 1579 | 1579 | ++this.pos < end && | |
| 1580 | 1580 | (c = text.charCodeAt(this.pos)) == CharCode.MINUS || c == CharCode.PLUS && | |
| 1581 | - isDecimalDigit(text.charCodeAt(this.pos + 1)) | ||
| 1581 | + isDecimal(text.charCodeAt(this.pos + 1)) | ||
| 1582 | 1582 | ) { | |
| 1583 | 1583 | ++this.pos; | |
| 1584 | 1584 | } | |
@@ -1618,7 +1618,7 @@ export class Tokenizer extends DiagnosticEmitter { | |||
| 1618 | 1618 | } | |
| 1619 | 1619 | sepEnd = pos + 1; | |
| 1620 | 1620 | ++sepCount; | |
| 1621 | - } else if (!isDecimalDigit(c)) { | ||
| 1621 | + } else if (!isDecimal(c)) { | ||
| 1622 | 1622 | break; | |
| 1623 | 1623 | } | |
| 1624 | 1624 | ++pos; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -139,7 +139,7 @@ export const enum CharCode { | |||
| 139 | 139 | } | |
| 140 | 140 | ||
| 141 | 141 | /** Tests if the specified character code is some sort of line break. */ | |
| 142 | - export function isLineBreak(c: CharCode): bool { | ||
| 142 | + export function isLineBreak(c: i32): bool { | ||
| 143 | 143 | switch (c) { | |
| 144 | 144 | case CharCode.LINEFEED: | |
| 145 | 145 | case CharCode.CARRIAGERETURN: | |
@@ -175,45 +175,48 @@ export function isWhiteSpace(c: i32): bool { | |||
| 175 | 175 | } | |
| 176 | 176 | } | |
| 177 | 177 | ||
| 178 | + export function isAlpha(c: i32): bool { | ||
| 179 | + let c0 = c | 32; // unify uppercases and lowercases a|A - z|Z | ||
| 180 | + return c0 >= CharCode.a && c0 <= CharCode.z; | ||
| 181 | + } | ||
| 182 | + | ||
| 178 | 183 | /** Tests if the specified character code is a valid decimal digit. */ | |
| 179 | - export function isDecimalDigit(c: i32): bool { | ||
| 184 | + export function isDecimal(c: i32): bool { | ||
| 180 | 185 | return c >= CharCode._0 && c <= CharCode._9; | |
| 181 | 186 | } | |
| 182 | 187 | ||
| 183 | 188 | /** Tests if the specified character code is a valid octal digit. */ | |
| 184 | - export function isOctalDigit(c: i32): bool { | ||
| 189 | + export function isOctal(c: i32): bool { | ||
| 185 | 190 | return c >= CharCode._0 && c <= CharCode._7; | |
| 186 | 191 | } | |
| 187 | 192 | ||
| 188 | 193 | /** Tests if the specified character code is a valid hexadecimal digit. */ | |
| 189 | - export function isHexDigit(c: i32): bool { | ||
| 190 | - return isDecimalDigit(c) || ((c | 32) >= CharCode.a && (c | 32) <= CharCode.f); | ||
| 194 | + export function isHex(c: i32): bool { | ||
| 195 | + let c0 = c | 32; // unify uppercases and lowercases a|A - f|F | ||
| 196 | + return isDecimal(c) || (c0 >= CharCode.a && c0 <= CharCode.f); | ||
| 191 | 197 | } | |
| 192 | 198 | ||
| 193 | 199 | /** Tests if the specified character code is trivially alphanumeric. */ | |
| 194 | - export function isTrivialAlphanum(code: i32): bool { | ||
| 195 | - return code >= CharCode.a && code <= CharCode.z | ||
| 196 | - || code >= CharCode.A && code <= CharCode.Z | ||
| 197 | - || code >= CharCode._0 && code <= CharCode._9; | ||
| 200 | + export function isAlphaOrDecimal(c: i32): bool { | ||
| 201 | + return isAlpha(c) || isDecimal(c); | ||
| 198 | 202 | } | |
| 199 | 203 | ||
| 200 | 204 | /** Tests if the specified character code is a valid start of an identifier. */ | |
| 201 | 205 | export function isIdentifierStart(c: i32): bool { | |
| 202 | - let c0 = c | 32; // unify uppercases and lowercases a|A - z|Z | ||
| 203 | - return c0 >= CharCode.a && c0 <= CharCode.z | ||
| 206 | + return isAlpha(c) | ||
| 204 | 207 | || c == CharCode._ | |
| 205 | 208 | || c == CharCode.DOLLAR | |
| 206 | - || c > 0x7F && isUnicodeIdentifierStart(c); | ||
| 209 | + || c >= 170 && c <= 65500 | ||
| 210 | + && lookupInUnicodeMap(c as u16, unicodeIdentifierStart); | ||
| 207 | 211 | } | |
| 208 | 212 | ||
| 209 | 213 | /** Tests if the specified character code is a valid part of an identifier. */ | |
| 210 | 214 | export function isIdentifierPart(c: i32): bool { | |
| 211 | - const c0 = c | 32; // unify uppercases and lowercases a|A - z|Z | ||
| 212 | - return c0 >= CharCode.a && c0 <= CharCode.z | ||
| 213 | - || c >= CharCode._0 && c <= CharCode._9 | ||
| 215 | + return isAlphaOrDecimal(c) | ||
| 214 | 216 | || c == CharCode._ | |
| 215 | 217 | || c == CharCode.DOLLAR | |
| 216 | - || c > 0x7F && isUnicodeIdentifierPart(c); | ||
| 218 | + || c >= 170 && c <= 65500 | ||
| 219 | + && lookupInUnicodeMap(c as u16, unicodeIdentifierPart); | ||
| 217 | 220 | } | |
| 218 | 221 | ||
| 219 | 222 | // storing as u16 to save memory | |
@@ -354,15 +357,13 @@ const unicodeIdentifierPart: u16[] = [ | |||
| 354 | 357 | ]; | |
| 355 | 358 | ||
| 356 | 359 | function lookupInUnicodeMap(code: u16, map: u16[]): bool { | |
| 357 | - if (code < map[0]) return false; | ||
| 358 | - | ||
| 359 | 360 | var lo = 0; | |
| 360 | 361 | var hi = map.length; | |
| 361 | - var mid: i32; | ||
| 362 | + var mid: u32; | ||
| 362 | 363 | var midVal: u16; | |
| 363 | 364 | ||
| 364 | 365 | while (lo + 1 < hi) { | |
| 365 | - mid = lo + ((hi - lo) >> 1); | ||
| 366 | + mid = lo + ((hi - lo) >>> 1); | ||
| 366 | 367 | mid -= (mid & 1); | |
| 367 | 368 | midVal = map[mid]; | |
| 368 | 369 | if (midVal <= code && code <= map[mid + 1]) { | |
@@ -377,16 +378,6 @@ function lookupInUnicodeMap(code: u16, map: u16[]): bool { | |||
| 377 | 378 | return false; | |
| 378 | 379 | } | |
| 379 | 380 | ||
| 380 | - function isUnicodeIdentifierStart(code: i32): bool { | ||
| 381 | - return code < 170 || code > 65500 ? false : | ||
| 382 | - lookupInUnicodeMap(code as u16, unicodeIdentifierStart); | ||
| 383 | - } | ||
| 384 | - | ||
| 385 | - function isUnicodeIdentifierPart(code: i32): bool { | ||
| 386 | - return code < 170 || code > 65500 ? false : | ||
| 387 | - lookupInUnicodeMap(code as u16, unicodeIdentifierPart); | ||
| 388 | - } | ||
| 389 | - | ||
| 390 | 381 | const indentX1 = " "; | |
| 391 | 382 | const indentX2 = " "; | |
| 392 | 383 | const indentX4 = " "; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments