( pos: Position, source: string, numberOfCharacters: number = source.length, )
| 250 | // advance by mutation without cloning (for performance reasons), since this |
| 251 | // gets called a lot in the parser |
| 252 | export function advancePositionWithMutation( |
| 253 | pos: Position, |
| 254 | source: string, |
| 255 | numberOfCharacters: number = source.length, |
| 256 | ): Position { |
| 257 | let linesCount = 0 |
| 258 | let lastNewLinePos = -1 |
| 259 | for (let i = 0; i < numberOfCharacters; i++) { |
| 260 | if (source.charCodeAt(i) === 10 /* newline char code */) { |
| 261 | linesCount++ |
| 262 | lastNewLinePos = i |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | pos.offset += numberOfCharacters |
| 267 | pos.line += linesCount |
| 268 | pos.column = |
| 269 | lastNewLinePos === -1 |
| 270 | ? pos.column + numberOfCharacters |
| 271 | : numberOfCharacters - lastNewLinePos |
| 272 | |
| 273 | return pos |
| 274 | } |
| 275 | |
| 276 | export function assert(condition: boolean, msg?: string): void { |
| 277 | /* v8 ignore next 3 */ |
no outgoing calls
no test coverage detected