(text: string, i: number, out: Array<unknown>)
| 396 | // Continues the captured value from `i`, completing it if it ends in this |
| 397 | // chunk. Returns the index after the value, or the chunk length. |
| 398 | scan(text: string, i: number, out: Array<unknown>): number { |
| 399 | const end = this.scalar ? this.scanScalar(text, i) : this.scanNested(text, i) |
| 400 | if (end === -1) return text.length |
| 401 | const source = this.buffer + text.slice(Math.max(this.start - this.base, 0), end) |
| 402 | this.checkSize(source.length) |
| 403 | const mode = this.capture |
| 404 | this.capture = NONE |
| 405 | this.buffer = "" |
| 406 | let value: unknown |
| 407 | try { |
| 408 | value = JSON.parse(source) |
| 409 | } catch (cause) { |
| 410 | throw this.fail("Syntax", "Invalid JSON value", this.start, cause) |
| 411 | } |
| 412 | if (mode === ELEMENT) out.push(value) |
| 413 | else if (mode === KEY) this.key = value as string |
| 414 | return end |
| 415 | } |
| 416 | |
| 417 | // A scalar ends at the first delimiter, which `JSON.parse` then validates. |
| 418 | scanScalar(text: string, i: number): number { |
no test coverage detected