Where the `close` matching the `open` at `text[from]` is, or -1.
(text: string, from: number, open: string, close: string)
| 183 | |
| 184 | /** Where the `close` matching the `open` at `text[from]` is, or -1. */ |
| 185 | function matching(text: string, from: number, open: string, close: string): number { |
| 186 | let depth = 0; |
| 187 | for (let i = from; i < text.length; i++) { |
| 188 | const c = text[i]!; |
| 189 | if (c === '"' || c === "'") i = quotedEnd(text, i) - 1; |
| 190 | else if (c === open) depth++; |
| 191 | else if (c === close && --depth === 0) return i; |
| 192 | } |
| 193 | return -1; |
| 194 | } |
| 195 | |
| 196 | /** Past the string or character literal whose quote is at `i`. */ |
| 197 | function quotedEnd(text: string, i: number): number { |
no test coverage detected