(s: string, from: number, to: number)
| 57 | |
| 58 | /** Each `{…}` written directly in `[from, to)`, as its own extent. */ |
| 59 | export function* topLevelObjects(s: string, from: number, to: number): Generator<{ start: number; end: number }> { |
| 60 | for (let i = from; i < to; i++) { |
| 61 | const ch = s[i]!; |
| 62 | if (ch === '"' || ch === "'" || ch === '`') { |
| 63 | const end = skipString(s, i); |
| 64 | if (end < 0) return; |
| 65 | i = end; |
| 66 | continue; |
| 67 | } |
| 68 | if (ch === '{') { |
| 69 | const end = matchBracket(s, i); |
| 70 | if (end < 0) return; |
| 71 | yield { start: i, end }; |
| 72 | i = end; |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | /** An object's own fields — key to its value text and where the key sits. Nested structures are stepped over. */ |
| 78 | export function readFields(s: string, start: number, end: number): Map<string, { text: string; at: number }> { |
no test coverage detected