(at: number)
| 210 | |
| 211 | /** The offset after the `<script>` or `<style>` element at `at`, or -1. */ |
| 212 | const elementEnd = (at: number): number => { |
| 213 | if (!source.startsWith('script', at + 1) && !source.startsWith('style', at + 1)) return -1; |
| 214 | const known = found.get(at); |
| 215 | if (known) return known.end; |
| 216 | if (unclosedElements >= MAX_UNCLOSED_ELEMENTS) return -1; |
| 217 | elementAt.lastIndex = at; |
| 218 | const match = elementAt.exec(source); |
| 219 | if (!match) { |
| 220 | // Not this element's name (`<scripts>`), or an opening tag that never closes. |
| 221 | const next = source.charCodeAt(at + (source.startsWith('script', at + 1) ? 7 : 6)); |
| 222 | if (next === Ch.Greater || next === Ch.Slash || next <= 32) unclosedElements++; |
| 223 | return -1; |
| 224 | } |
| 225 | const tag = match[1] as 'script' | 'style'; |
| 226 | const attrs = match[2] ?? ''; |
| 227 | const content = match.groups?.content; |
| 228 | const end = at + match[0].length; |
| 229 | found.set(at, content === undefined |
| 230 | ? { tag, index: at, attrs, end } |
| 231 | : { tag, index: at, attrs, content, contentIndex: at + 1 + tag.length + attrs.length + 1, end }); |
| 232 | return end; |
| 233 | }; |
| 234 | |
| 235 | /** Whether a `<script>` or `<style>` tag, opening or closing, starts at `at`. */ |
| 236 | const isElementTag = (at: number): boolean => { |
no test coverage detected