(L: Lexer, charIdx: number)
| 164 | } |
| 165 | |
| 166 | function byteAt(L: Lexer, charIdx: number): number { |
| 167 | // Fast path: ASCII-only prefix means char idx == byte idx |
| 168 | if (L.byteTable) return L.byteTable[charIdx]! |
| 169 | // Build table on first non-trivial lookup |
| 170 | const t = new Uint32Array(L.len + 1) |
| 171 | let b = 0 |
| 172 | let i = 0 |
| 173 | while (i < L.len) { |
| 174 | t[i] = b |
| 175 | const c = L.src.charCodeAt(i) |
| 176 | if (c < 0x80) { |
| 177 | b++ |
| 178 | i++ |
| 179 | } else if (c < 0x800) { |
| 180 | b += 2 |
| 181 | i++ |
| 182 | } else if (c >= 0xd800 && c <= 0xdbff) { |
| 183 | t[i + 1] = b + 2 |
| 184 | b += 4 |
| 185 | i += 2 |
| 186 | } else { |
| 187 | b += 3 |
| 188 | i++ |
| 189 | } |
| 190 | } |
| 191 | t[L.len] = b |
| 192 | L.byteTable = t |
| 193 | return t[charIdx]! |
| 194 | } |
| 195 | |
| 196 | function isWordChar(c: string): boolean { |
| 197 | // Bash word chars: alphanumeric + various punctuation that doesn't start operators |
no outgoing calls
no test coverage detected