(s: string, i: number)
| 2036 | } |
| 2037 | |
| 2038 | private processingInstruction(s: string, i: number): number { |
| 2039 | const end = s.indexOf("?>", i + 2) |
| 2040 | if (end === -1) return -1 |
| 2041 | const t = scanName(s, i + 2, end) |
| 2042 | if (t === i + 2) throw this.syntax("invalid processing instruction target", i + 2) |
| 2043 | const target = s.slice(i + 2, t) |
| 2044 | if (isReservedTarget(target)) { |
| 2045 | if (target === "xml" && this.base + i === 0) return this.declaration(s, i, t, end) |
| 2046 | throw this.syntax( |
| 2047 | target === "xml" ? |
| 2048 | "the XML declaration is only allowed at the start of the document" : |
| 2049 | `processing instruction target ${target} is reserved`, |
| 2050 | i |
| 2051 | ) |
| 2052 | } |
| 2053 | if (this.namespaces && target.includes(":")) { |
| 2054 | throw this.syntax(`processing instruction target ${target} contains a colon`, i) |
| 2055 | } |
| 2056 | let data = "" |
| 2057 | if (t < end) { |
| 2058 | if (!isSpace(s.charCodeAt(t))) throw this.syntax("expected whitespace after the target", t) |
| 2059 | data = normalizeLines(s.slice(skipSpace(s, t, end), end)) |
| 2060 | } |
| 2061 | this.checkSize(i, end + 2) |
| 2062 | this.flushText() |
| 2063 | this.out.push({ _tag: "ProcessingInstruction", target, data }) |
| 2064 | return end + 2 |
| 2065 | } |
| 2066 | |
| 2067 | private declaration(s: string, i: number, t: number, end: number): number { |
| 2068 | this.checkSize(i, end + 2) |
no test coverage detected