(s: string, i: number)
| 1140 | |
| 1141 | // Returns an index of `s` at which the token has ended, or -1 |
| 1142 | scan(s: string, i: number): number { |
| 1143 | const n = s.length |
| 1144 | while (i < n) { |
| 1145 | const c = s.charCodeAt(i) |
| 1146 | switch (this.state) { |
| 1147 | case S_START: { |
| 1148 | this.state = c === LT ? S_LT : S_TEXT |
| 1149 | if (c !== LT) continue |
| 1150 | break |
| 1151 | } |
| 1152 | case S_TEXT: { |
| 1153 | return s.indexOf("<", i) |
| 1154 | } |
| 1155 | case S_LT: { |
| 1156 | if (c === BANG) { |
| 1157 | this.state = S_BANG |
| 1158 | } else if (c === QUESTION) { |
| 1159 | this.reset(S_PI) |
| 1160 | } else { |
| 1161 | this.reset(S_TAG) |
| 1162 | continue |
| 1163 | } |
| 1164 | break |
| 1165 | } |
| 1166 | case S_BANG: { |
| 1167 | if (c === DASH) this.keyword = "--" |
| 1168 | else if (c === LBRACKET) this.keyword = "[CDATA[" |
| 1169 | else if (c === 68) this.keyword = "DOCTYPE" |
| 1170 | else return i |
| 1171 | this.state = S_KEYWORD |
| 1172 | this.aux = 1 |
| 1173 | break |
| 1174 | } |
| 1175 | case S_KEYWORD: { |
| 1176 | if (c !== this.keyword.charCodeAt(this.aux)) return i |
| 1177 | if (++this.aux === this.keyword.length) { |
| 1178 | this.reset(this.keyword === "--" ? S_COMMENT : this.keyword === "DOCTYPE" ? S_DOCTYPE : S_CDATA) |
| 1179 | } |
| 1180 | break |
| 1181 | } |
| 1182 | case S_COMMENT: |
| 1183 | case S_SUBSET_COMMENT: { |
| 1184 | if (c === DASH) { |
| 1185 | this.aux++ |
| 1186 | } else if (c === GT && this.aux >= 2) { |
| 1187 | if (this.state === S_COMMENT) return i + 1 |
| 1188 | this.reset(S_SUBSET) |
| 1189 | } else { |
| 1190 | this.aux = 0 |
| 1191 | } |
| 1192 | break |
| 1193 | } |
| 1194 | case S_CDATA: { |
| 1195 | if (c === RBRACKET) this.aux++ |
| 1196 | else if (c === GT && this.aux >= 2) return i + 1 |
| 1197 | else this.aux = 0 |
| 1198 | break |
| 1199 | } |
no test coverage detected