@@ -458,10 +458,11 @@ export function* tokenize(t, opts) {
458
458
459
459
switch ( current ) {
460
460
case 0x62 : // b
461
- pop ( ) ;
461
+ current = pop ( ) ;
462
462
463
- if ( ! consume ( isHexadecimalDigit ) ) {
464
- if ( consume ( isHexadecimalDigitOrUnderscore ) ) {
463
+ if ( ! consume ( isBinaryDigit ) ) {
464
+ if ( current === 0x5f ) {
465
+ // _
465
466
( errorsInToken ??= [ ] ) . push (
466
467
mkError (
467
468
"Invalid hexadecimal number, the first character after 0x cannot be an underscore" ,
@@ -482,10 +483,11 @@ export function* tokenize(t, opts) {
482
483
yield mkToken ( T_NUMBER_BINARY ) ;
483
484
continue ;
484
485
case 0x6f : // o
485
- pop ( ) ;
486
+ current = pop ( ) ;
486
487
487
- if ( ! consume ( isHexadecimalDigit ) ) {
488
- if ( consume ( isHexadecimalDigitOrUnderscore ) ) {
488
+ if ( ! consume ( isOctalDigit ) ) {
489
+ if ( current === 0x5f ) {
490
+ // _
489
491
( errorsInToken ??= [ ] ) . push (
490
492
mkError (
491
493
"Invalid hexadecimal number, the first character after 0x cannot be an underscore" ,
@@ -506,10 +508,11 @@ export function* tokenize(t, opts) {
506
508
yield mkToken ( T_NUMBER_OCTAL ) ;
507
509
continue ;
508
510
case 0x78 : // x
509
- pop ( ) ;
511
+ current = pop ( ) ;
510
512
511
513
if ( ! consume ( isHexadecimalDigit ) ) {
512
- if ( consume ( isHexadecimalDigitOrUnderscore ) ) {
514
+ if ( current === 0x5f ) {
515
+ // _
513
516
( errorsInToken ??= [ ] ) . push (
514
517
mkError (
515
518
"Invalid hexadecimal number, the first character after 0x cannot be an underscore" ,
@@ -538,7 +541,8 @@ export function* tokenize(t, opts) {
538
541
// .
539
542
540
543
if ( ! consume ( isDecimalDigit ) ) {
541
- if ( consume ( isDecimalDigitOrUnderscore ) ) {
544
+ if ( current === 0x5f ) {
545
+ // _
542
546
( errorsInToken ??= [ ] ) . push (
543
547
mkError (
544
548
"Invalid decimal number, the part after the decimal point mustn't start on an underscore" ,
@@ -562,20 +566,22 @@ export function* tokenize(t, opts) {
562
566
consume ( isNumberSign ) ;
563
567
564
568
if ( ! consume ( isDecimalDigit ) ) {
565
- if ( consume ( isDecimalDigitOrUnderscore ) ) {
566
- zerOrMore ( isDecimalDigitOrUnderscore ) ;
569
+ if ( current === 0x5f ) {
570
+ // _
571
+ ( errorsInToken ??= [ ] ) . push (
572
+ mkError (
573
+ "Invalid decimal number, the number after the exponent mustn't start on an underscore" ,
574
+ ) ,
575
+ ) ;
576
+ } else {
577
+ zerOrMore ( isIdentifierChar ) ;
578
+
567
579
yield mkToken (
568
580
T_NUMBER_DECIMAL ,
569
- "Invalid decimal number, the number after the exponent mustn't start on an underscore " ,
581
+ "Invalid decimal number, missing a number after the exponent" ,
570
582
) ;
571
583
continue ;
572
584
}
573
-
574
- yield mkToken (
575
- T_NUMBER_DECIMAL ,
576
- "Invalid decimal number, missing a number after the exponent" ,
577
- ) ;
578
- continue ;
579
585
}
580
586
581
587
zerOrMore ( isDecimalDigitOrUnderscore ) ;
@@ -631,10 +637,11 @@ export function* tokenize(t, opts) {
631
637
632
638
switch ( current ) {
633
639
case 0x62 : // b
634
- pop ( ) ;
640
+ current = pop ( ) ;
635
641
636
642
if ( ! consume ( isBinaryDigit ) ) {
637
- if ( consume ( isBinaryDigitOrUnderscore ) ) {
643
+ if ( current === 0x5f ) {
644
+ // _
638
645
( errorsInToken ??= [ ] ) . push (
639
646
mkError (
640
647
"Invalid binary number, the first character after 0b cannot be an underscore" ,
@@ -652,10 +659,11 @@ export function* tokenize(t, opts) {
652
659
yield mkToken ( T_NUMBER_BINARY ) ;
653
660
continue ;
654
661
case 0x6f : // o
655
- pop ( ) ;
662
+ current = pop ( ) ;
656
663
657
664
if ( ! consume ( isOctalDigit ) ) {
658
- if ( consume ( isOctalDigitOrUnderscore ) ) {
665
+ if ( current === 0x5f ) {
666
+ // _
659
667
( errorsInToken ??= [ ] ) . push (
660
668
mkError (
661
669
"Invalid octal number, the first character after 0o cannot be an underscore" ,
@@ -673,10 +681,11 @@ export function* tokenize(t, opts) {
673
681
yield mkToken ( T_NUMBER_OCTAL ) ;
674
682
continue ;
675
683
case 0x78 : // x
676
- pop ( ) ;
684
+ current = pop ( ) ;
677
685
678
686
if ( ! consume ( isHexadecimalDigit ) ) {
679
- if ( consume ( isHexadecimalDigitOrUnderscore ) ) {
687
+ if ( current === 0x5f ) {
688
+ // _
680
689
( errorsInToken ??= [ ] ) . push (
681
690
mkError (
682
691
"Invalid hexadecimal number, the first character after 0x cannot be an underscore" ,
@@ -705,9 +714,20 @@ export function* tokenize(t, opts) {
705
714
// .
706
715
707
716
if ( ! consume ( isDecimalDigit ) ) {
708
- zerOrMore ( isIdentifierChar ) ;
709
- yield mkToken ( T_IDENTIFIER_STRING , "Invalid decimal number" ) ;
710
- continue ;
717
+ if ( current === 0x5f ) {
718
+ // _
719
+ ( errorsInToken ??= [ ] ) . push (
720
+ mkError (
721
+ "Invalid decimal number, the part after the decimal point mustn't start on an underscore" ,
722
+ ) ,
723
+ ) ;
724
+ } else {
725
+ ( errorsInToken ??= [ ] ) . push (
726
+ mkError (
727
+ "Invalid decimal number, a decimal point must be followed by a digit" ,
728
+ ) ,
729
+ ) ;
730
+ }
711
731
}
712
732
713
733
zerOrMore ( isDecimalDigitOrUnderscore ) ;
@@ -719,9 +739,22 @@ export function* tokenize(t, opts) {
719
739
consume ( isNumberSign ) ;
720
740
721
741
if ( ! consume ( isDecimalDigit ) ) {
722
- zerOrMore ( isIdentifierChar ) ;
723
- yield mkToken ( T_IDENTIFIER_STRING , "Invalid decimal number" ) ;
724
- continue ;
742
+ if ( current === 0x5f ) {
743
+ // _
744
+ ( errorsInToken ??= [ ] ) . push (
745
+ mkError (
746
+ "Invalid decimal number, the number after the exponent mustn't start on an underscore" ,
747
+ ) ,
748
+ ) ;
749
+ } else {
750
+ zerOrMore ( isIdentifierChar ) ;
751
+
752
+ yield mkToken (
753
+ T_NUMBER_DECIMAL ,
754
+ "Invalid decimal number, missing a number after the exponent" ,
755
+ ) ;
756
+ continue ;
757
+ }
725
758
}
726
759
727
760
zerOrMore ( isDecimalDigitOrUnderscore ) ;
0 commit comments