@@ -31,6 +31,7 @@ import {
31
31
isIdentifierPart ,
32
32
isDecimal ,
33
33
isOctal ,
34
+ isHexBase ,
34
35
isHighSurrogate ,
35
36
isLowSurrogate
36
37
} from "./util" ;
@@ -1313,30 +1314,24 @@ export class Tokenizer extends DiagnosticEmitter {
1313
1314
var end = this . end ;
1314
1315
var start = pos ;
1315
1316
var sepEnd = start ;
1316
- var value = i64_new ( 0 ) ;
1317
+ var value = i64_zero ;
1317
1318
var i64_4 = i64_new ( 4 ) ;
1318
1319
var nextValue = value ;
1319
1320
var overflowOccurred = false ;
1320
1321
1321
1322
while ( pos < end ) {
1322
1323
let c = text . charCodeAt ( pos ) ;
1323
- if ( c >= CharCode . _0 && c <= CharCode . _9 ) {
1324
- // value = (value << 4) + c - CharCode._0;
1324
+ if ( isDecimal ( c ) ) {
1325
+ // (value << 4) + c - CharCode._0
1325
1326
nextValue = i64_add (
1326
1327
i64_shl ( value , i64_4 ) ,
1327
1328
i64_new ( c - CharCode . _0 )
1328
1329
) ;
1329
- } else if ( c >= CharCode . A && c <= CharCode . F ) {
1330
- // value = (value << 4) + 10 + c - CharCode.A;
1330
+ } else if ( isHexBase ( c ) ) {
1331
+ // (value << 4) + (c | 32) + (10 - CharCode.a)
1331
1332
nextValue = i64_add (
1332
1333
i64_shl ( value , i64_4 ) ,
1333
- i64_new ( 10 + c - CharCode . A )
1334
- ) ;
1335
- } else if ( c >= CharCode . a && c <= CharCode . f ) {
1336
- // value = (value << 4) + 10 + c - CharCode.a;
1337
- nextValue = i64_add (
1338
- i64_shl ( value , i64_4 ) ,
1339
- i64_new ( 10 + c - CharCode . a )
1334
+ i64_new ( ( c | 32 ) + ( 10 - CharCode . a ) )
1340
1335
) ;
1341
1336
} else if ( c == CharCode . _ ) {
1342
1337
if ( sepEnd == pos ) {
@@ -1386,14 +1381,14 @@ export class Tokenizer extends DiagnosticEmitter {
1386
1381
var end = this . end ;
1387
1382
var start = pos ;
1388
1383
var sepEnd = start ;
1389
- var value = i64_new ( 0 ) ;
1384
+ var value = i64_zero ;
1390
1385
var i64_10 = i64_new ( 10 ) ;
1391
1386
var nextValue = value ;
1392
1387
var overflowOccurred = false ;
1393
1388
1394
1389
while ( pos < end ) {
1395
1390
let c = text . charCodeAt ( pos ) ;
1396
- if ( c >= CharCode . _0 && c <= CharCode . _9 ) {
1391
+ if ( isDecimal ( c ) ) {
1397
1392
// value = value * 10 + c - CharCode._0;
1398
1393
nextValue = i64_add (
1399
1394
i64_mul ( value , i64_10 ) ,
@@ -1451,15 +1446,15 @@ export class Tokenizer extends DiagnosticEmitter {
1451
1446
var end = this . end ;
1452
1447
var start = pos ;
1453
1448
var sepEnd = start ;
1454
- var value = i64_new ( 0 ) ;
1449
+ var value = i64_zero ;
1455
1450
var i64_3 = i64_new ( 3 ) ;
1456
1451
var nextValue = value ;
1457
1452
var overflowOccurred = false ;
1458
1453
1459
1454
while ( pos < end ) {
1460
1455
let c = text . charCodeAt ( pos ) ;
1461
- if ( c >= CharCode . _0 && c <= CharCode . _7 ) {
1462
- // value = (value << 3) + c - CharCode._0;
1456
+ if ( isOctal ( c ) ) {
1457
+ // (value << 3) + c - CharCode._0
1463
1458
nextValue = i64_add (
1464
1459
i64_shl ( value , i64_3 ) ,
1465
1460
i64_new ( c - CharCode . _0 )
@@ -1511,21 +1506,20 @@ export class Tokenizer extends DiagnosticEmitter {
1511
1506
var end = this . end ;
1512
1507
var start = pos ;
1513
1508
var sepEnd = start ;
1514
- var value = i64_new ( 0 ) ;
1515
- var i64_1 = i64_new ( 1 ) ;
1509
+ var value = i64_zero ;
1516
1510
var nextValue = value ;
1517
1511
var overflowOccurred = false ;
1518
1512
1519
1513
while ( pos < end ) {
1520
1514
let c = text . charCodeAt ( pos ) ;
1521
1515
if ( c == CharCode . _0 ) {
1522
- // value = (value << 1);
1523
- nextValue = i64_shl ( value , i64_1 ) ;
1516
+ // value << 1 | 0
1517
+ nextValue = i64_shl ( value , i64_one ) ;
1524
1518
} else if ( c == CharCode . _1 ) {
1525
- // value = (value << 1) + 1;
1526
- nextValue = i64_add (
1527
- i64_shl ( value , i64_1 ) ,
1528
- i64_1
1519
+ // value << 1 | 1
1520
+ nextValue = i64_or (
1521
+ i64_shl ( value , i64_one ) ,
1522
+ i64_one
1529
1523
) ;
1530
1524
} else if ( c == CharCode . _ ) {
1531
1525
if ( sepEnd == pos ) {
@@ -1665,12 +1659,10 @@ export class Tokenizer extends DiagnosticEmitter {
1665
1659
var end = this . end ;
1666
1660
while ( pos < end ) {
1667
1661
let c = text . charCodeAt ( pos ++ ) ;
1668
- if ( c >= CharCode . _0 && c <= CharCode . _9 ) {
1662
+ if ( isDecimal ( c ) ) {
1669
1663
value = ( value << 4 ) + c - CharCode . _0 ;
1670
- } else if ( c >= CharCode . A && c <= CharCode . F ) {
1671
- value = ( value << 4 ) + c + ( 10 - CharCode . A ) ;
1672
- } else if ( c >= CharCode . a && c <= CharCode . f ) {
1673
- value = ( value << 4 ) + c + ( 10 - CharCode . a ) ;
1664
+ } else if ( isHexBase ( c ) ) {
1665
+ value = ( value << 4 ) + ( c | 32 ) + ( 10 - CharCode . a ) ;
1674
1666
} else if ( ~ startIfTaggedTemplate ) {
1675
1667
this . pos = -- pos ;
1676
1668
return text . substring ( startIfTaggedTemplate , pos ) ;
0 commit comments