(P: ParseState, startByte: number, endByte: number)
| 675 | } |
| 676 | |
| 677 | function sliceBytes(P: ParseState, startByte: number, endByte: number): string { |
| 678 | if (P.isAscii) return P.src.slice(startByte, endByte) |
| 679 | // Find char indices for byte offsets. Build byte table if needed. |
| 680 | const L = P.L |
| 681 | if (!L.byteTable) byteAt(L, 0) |
| 682 | const t = L.byteTable! |
| 683 | // Binary search for char index where byte offset matches |
| 684 | let lo = 0 |
| 685 | let hi = P.src.length |
| 686 | while (lo < hi) { |
| 687 | const m = (lo + hi) >>> 1 |
| 688 | if (t[m]! < startByte) lo = m + 1 |
| 689 | else hi = m |
| 690 | } |
| 691 | const sc = lo |
| 692 | lo = sc |
| 693 | hi = P.src.length |
| 694 | while (lo < hi) { |
| 695 | const m = (lo + hi) >>> 1 |
| 696 | if (t[m]! < endByte) lo = m + 1 |
| 697 | else hi = m |
| 698 | } |
| 699 | return P.src.slice(sc, lo) |
| 700 | } |
| 701 | |
| 702 | function leaf(P: ParseState, type: string, tok: Token): TsNode { |
| 703 | return mk(P, type, tok.start, tok.end, []) |
no test coverage detected