()
| 680 | // =========================================================================== |
| 681 | |
| 682 | function readName(): string { |
| 683 | const start = pos; |
| 684 | |
| 685 | // First character must be NameStartChar |
| 686 | if (pos < len) { |
| 687 | const firstCode = input.charCodeAt(pos); |
| 688 | // Fast ASCII NameStartChar check |
| 689 | if ( |
| 690 | (firstCode >= 97 && firstCode <= 122) || // a-z |
| 691 | (firstCode >= 65 && firstCode <= 90) || // A-Z |
| 692 | firstCode === 95 || // _ |
| 693 | firstCode === 58 // : |
| 694 | ) { |
| 695 | pos++; |
| 696 | } else if (firstCode > 127) { |
| 697 | // Non-ASCII: use codePointAt for proper surrogate pair handling |
| 698 | // Astral plane characters (U+10000+) are represented as surrogate pairs |
| 699 | const codePoint = input.codePointAt(pos)!; |
| 700 | if (isNameStartChar(codePoint)) { |
| 701 | // Advance by 1 for BMP chars, 2 for astral plane (surrogate pairs) |
| 702 | pos += codePoint > 0xFFFF ? 2 : 1; |
| 703 | } else { |
| 704 | // Not a valid name start character |
| 705 | return ""; |
| 706 | } |
| 707 | } else { |
| 708 | // Not a valid name start character |
| 709 | return ""; |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | // Remaining characters: NameChar |
| 714 | while (pos < len) { |
| 715 | const code = input.charCodeAt(pos); |
| 716 | // Fast ASCII NameChar check (inline for performance) |
| 717 | if ( |
| 718 | (code >= 97 && code <= 122) || // a-z |
| 719 | (code >= 65 && code <= 90) || // A-Z |
| 720 | (code >= 48 && code <= 57) || // 0-9 |
| 721 | code === 95 || // _ |
| 722 | code === 58 || // : |
| 723 | code === 46 || // . |
| 724 | code === 45 // - |
| 725 | ) { |
| 726 | pos++; |
| 727 | continue; |
| 728 | } |
| 729 | // Non-ASCII: use codePointAt for proper surrogate pair handling |
| 730 | if (code > 127) { |
| 731 | const codePoint = input.codePointAt(pos)!; |
| 732 | if (isNameChar(codePoint)) { |
| 733 | // Advance by 1 for BMP chars, 2 for astral plane (surrogate pairs) |
| 734 | pos += codePoint > 0xFFFF ? 2 : 1; |
| 735 | continue; |
| 736 | } |
| 737 | } |
| 738 | break; |
| 739 | } |
no test coverage detected