errors.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /**
  2. * @typedef ErrorInfo
  3. * Info on a `parse5` error.
  4. * @property {string} reason
  5. * Reason of error.
  6. * @property {string} description
  7. * More info on error.
  8. * @property {false} [url]
  9. * Turn off if this is not documented in the html5 spec (optional).
  10. */
  11. export const errors = {
  12. /** @type {ErrorInfo} */
  13. abandonedHeadElementChild: {
  14. reason: 'Unexpected metadata element after head',
  15. description:
  16. 'Unexpected element after head. Expected the element before `</head>`',
  17. url: false
  18. },
  19. /** @type {ErrorInfo} */
  20. abruptClosingOfEmptyComment: {
  21. reason: 'Unexpected abruptly closed empty comment',
  22. description: 'Unexpected `>` or `->`. Expected `-->` to close comments'
  23. },
  24. /** @type {ErrorInfo} */
  25. abruptDoctypePublicIdentifier: {
  26. reason: 'Unexpected abruptly closed public identifier',
  27. description:
  28. 'Unexpected `>`. Expected a closing `"` or `\'` after the public identifier'
  29. },
  30. /** @type {ErrorInfo} */
  31. abruptDoctypeSystemIdentifier: {
  32. reason: 'Unexpected abruptly closed system identifier',
  33. description:
  34. 'Unexpected `>`. Expected a closing `"` or `\'` after the identifier identifier'
  35. },
  36. /** @type {ErrorInfo} */
  37. absenceOfDigitsInNumericCharacterReference: {
  38. reason: 'Unexpected non-digit at start of numeric character reference',
  39. description:
  40. 'Unexpected `%c`. Expected `[0-9]` for decimal references or `[0-9a-fA-F]` for hexadecimal references'
  41. },
  42. /** @type {ErrorInfo} */
  43. cdataInHtmlContent: {
  44. reason: 'Unexpected CDATA section in HTML',
  45. description:
  46. 'Unexpected `<![CDATA[` in HTML. Remove it, use a comment, or encode special characters instead'
  47. },
  48. /** @type {ErrorInfo} */
  49. characterReferenceOutsideUnicodeRange: {
  50. reason: 'Unexpected too big numeric character reference',
  51. description:
  52. 'Unexpectedly high character reference. Expected character references to be at most hexadecimal 10ffff (or decimal 1114111)'
  53. },
  54. /** @type {ErrorInfo} */
  55. closingOfElementWithOpenChildElements: {
  56. reason: 'Unexpected closing tag with open child elements',
  57. description:
  58. 'Unexpectedly closing tag. Expected other tags to be closed first',
  59. url: false
  60. },
  61. /** @type {ErrorInfo} */
  62. controlCharacterInInputStream: {
  63. reason: 'Unexpected control character',
  64. description:
  65. 'Unexpected control character `%x`. Expected a non-control code point, 0x00, or ASCII whitespace'
  66. },
  67. /** @type {ErrorInfo} */
  68. controlCharacterReference: {
  69. reason: 'Unexpected control character reference',
  70. description:
  71. 'Unexpectedly control character in reference. Expected a non-control code point, 0x00, or ASCII whitespace'
  72. },
  73. /** @type {ErrorInfo} */
  74. disallowedContentInNoscriptInHead: {
  75. reason: 'Disallowed content inside `<noscript>` in `<head>`',
  76. description:
  77. 'Unexpected text character `%c`. Only use text in `<noscript>`s in `<body>`',
  78. url: false
  79. },
  80. /** @type {ErrorInfo} */
  81. duplicateAttribute: {
  82. reason: 'Unexpected duplicate attribute',
  83. description:
  84. 'Unexpectedly double attribute. Expected attributes to occur only once'
  85. },
  86. /** @type {ErrorInfo} */
  87. endTagWithAttributes: {
  88. reason: 'Unexpected attribute on closing tag',
  89. description: 'Unexpected attribute. Expected `>` instead'
  90. },
  91. /** @type {ErrorInfo} */
  92. endTagWithTrailingSolidus: {
  93. reason: 'Unexpected slash at end of closing tag',
  94. description: 'Unexpected `%c-1`. Expected `>` instead'
  95. },
  96. /** @type {ErrorInfo} */
  97. endTagWithoutMatchingOpenElement: {
  98. reason: 'Unexpected unopened end tag',
  99. description: 'Unexpected end tag. Expected no end tag or another end tag',
  100. url: false
  101. },
  102. /** @type {ErrorInfo} */
  103. eofBeforeTagName: {
  104. reason: 'Unexpected end of file',
  105. description: 'Unexpected end of file. Expected tag name instead'
  106. },
  107. /** @type {ErrorInfo} */
  108. eofInCdata: {
  109. reason: 'Unexpected end of file in CDATA',
  110. description: 'Unexpected end of file. Expected `]]>` to close the CDATA'
  111. },
  112. /** @type {ErrorInfo} */
  113. eofInComment: {
  114. reason: 'Unexpected end of file in comment',
  115. description: 'Unexpected end of file. Expected `-->` to close the comment'
  116. },
  117. /** @type {ErrorInfo} */
  118. eofInDoctype: {
  119. reason: 'Unexpected end of file in doctype',
  120. description:
  121. 'Unexpected end of file. Expected a valid doctype (such as `<!doctype html>`)'
  122. },
  123. /** @type {ErrorInfo} */
  124. eofInElementThatCanContainOnlyText: {
  125. reason: 'Unexpected end of file in element that can only contain text',
  126. description: 'Unexpected end of file. Expected text or a closing tag',
  127. url: false
  128. },
  129. /** @type {ErrorInfo} */
  130. eofInScriptHtmlCommentLikeText: {
  131. reason: 'Unexpected end of file in comment inside script',
  132. description: 'Unexpected end of file. Expected `-->` to close the comment'
  133. },
  134. /** @type {ErrorInfo} */
  135. eofInTag: {
  136. reason: 'Unexpected end of file in tag',
  137. description: 'Unexpected end of file. Expected `>` to close the tag'
  138. },
  139. /** @type {ErrorInfo} */
  140. incorrectlyClosedComment: {
  141. reason: 'Incorrectly closed comment',
  142. description: 'Unexpected `%c-1`. Expected `-->` to close the comment'
  143. },
  144. /** @type {ErrorInfo} */
  145. incorrectlyOpenedComment: {
  146. reason: 'Incorrectly opened comment',
  147. description: 'Unexpected `%c`. Expected `<!--` to open the comment'
  148. },
  149. /** @type {ErrorInfo} */
  150. invalidCharacterSequenceAfterDoctypeName: {
  151. reason: 'Invalid sequence after doctype name',
  152. description: 'Unexpected sequence at `%c`. Expected `public` or `system`'
  153. },
  154. /** @type {ErrorInfo} */
  155. invalidFirstCharacterOfTagName: {
  156. reason: 'Invalid first character in tag name',
  157. description: 'Unexpected `%c`. Expected an ASCII letter instead'
  158. },
  159. /** @type {ErrorInfo} */
  160. misplacedDoctype: {
  161. reason: 'Misplaced doctype',
  162. description: 'Unexpected doctype. Expected doctype before head',
  163. url: false
  164. },
  165. /** @type {ErrorInfo} */
  166. misplacedStartTagForHeadElement: {
  167. reason: 'Misplaced `<head>` start tag',
  168. description:
  169. 'Unexpected start tag `<head>`. Expected `<head>` directly after doctype',
  170. url: false
  171. },
  172. /** @type {ErrorInfo} */
  173. missingAttributeValue: {
  174. reason: 'Missing attribute value',
  175. description:
  176. 'Unexpected `%c-1`. Expected an attribute value or no `%c-1` instead'
  177. },
  178. /** @type {ErrorInfo} */
  179. missingDoctype: {
  180. reason: 'Missing doctype before other content',
  181. description: 'Expected a `<!doctype html>` before anything else',
  182. url: false
  183. },
  184. /** @type {ErrorInfo} */
  185. missingDoctypeName: {
  186. reason: 'Missing doctype name',
  187. description: 'Unexpected doctype end at `%c`. Expected `html` instead'
  188. },
  189. /** @type {ErrorInfo} */
  190. missingDoctypePublicIdentifier: {
  191. reason: 'Missing public identifier in doctype',
  192. description: 'Unexpected `%c`. Expected identifier for `public` instead'
  193. },
  194. /** @type {ErrorInfo} */
  195. missingDoctypeSystemIdentifier: {
  196. reason: 'Missing system identifier in doctype',
  197. description:
  198. 'Unexpected `%c`. Expected identifier for `system` instead (suggested: `"about:legacy-compat"`)'
  199. },
  200. /** @type {ErrorInfo} */
  201. missingEndTagName: {
  202. reason: 'Missing name in end tag',
  203. description: 'Unexpected `%c`. Expected an ASCII letter instead'
  204. },
  205. /** @type {ErrorInfo} */
  206. missingQuoteBeforeDoctypePublicIdentifier: {
  207. reason: 'Missing quote before public identifier in doctype',
  208. description: 'Unexpected `%c`. Expected `"` or `\'` instead'
  209. },
  210. /** @type {ErrorInfo} */
  211. missingQuoteBeforeDoctypeSystemIdentifier: {
  212. reason: 'Missing quote before system identifier in doctype',
  213. description: 'Unexpected `%c`. Expected `"` or `\'` instead'
  214. },
  215. /** @type {ErrorInfo} */
  216. missingSemicolonAfterCharacterReference: {
  217. reason: 'Missing semicolon after character reference',
  218. description: 'Unexpected `%c`. Expected `;` instead'
  219. },
  220. /** @type {ErrorInfo} */
  221. missingWhitespaceAfterDoctypePublicKeyword: {
  222. reason: 'Missing whitespace after public identifier in doctype',
  223. description: 'Unexpected `%c`. Expected ASCII whitespace instead'
  224. },
  225. /** @type {ErrorInfo} */
  226. missingWhitespaceAfterDoctypeSystemKeyword: {
  227. reason: 'Missing whitespace after system identifier in doctype',
  228. description: 'Unexpected `%c`. Expected ASCII whitespace instead'
  229. },
  230. /** @type {ErrorInfo} */
  231. missingWhitespaceBeforeDoctypeName: {
  232. reason: 'Missing whitespace before doctype name',
  233. description: 'Unexpected `%c`. Expected ASCII whitespace instead'
  234. },
  235. /** @type {ErrorInfo} */
  236. missingWhitespaceBetweenAttributes: {
  237. reason: 'Missing whitespace between attributes',
  238. description: 'Unexpected `%c`. Expected ASCII whitespace instead'
  239. },
  240. /** @type {ErrorInfo} */
  241. missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers: {
  242. reason:
  243. 'Missing whitespace between public and system identifiers in doctype',
  244. description: 'Unexpected `%c`. Expected ASCII whitespace instead'
  245. },
  246. /** @type {ErrorInfo} */
  247. nestedComment: {
  248. reason: 'Unexpected nested comment',
  249. description: 'Unexpected `<!--`. Expected `-->`'
  250. },
  251. /** @type {ErrorInfo} */
  252. nestedNoscriptInHead: {
  253. reason: 'Unexpected nested `<noscript>` in `<head>`',
  254. description:
  255. 'Unexpected `<noscript>`. Expected a closing tag or a meta element',
  256. url: false
  257. },
  258. /** @type {ErrorInfo} */
  259. nonConformingDoctype: {
  260. reason: 'Unexpected non-conforming doctype declaration',
  261. description:
  262. 'Expected `<!doctype html>` or `<!doctype html system "about:legacy-compat">`',
  263. url: false
  264. },
  265. /** @type {ErrorInfo} */
  266. nonVoidHtmlElementStartTagWithTrailingSolidus: {
  267. reason: 'Unexpected trailing slash on start tag of non-void element',
  268. description: 'Unexpected `/`. Expected `>` instead'
  269. },
  270. /** @type {ErrorInfo} */
  271. noncharacterCharacterReference: {
  272. reason:
  273. 'Unexpected noncharacter code point referenced by character reference',
  274. description: 'Unexpected code point. Do not use noncharacters in HTML'
  275. },
  276. /** @type {ErrorInfo} */
  277. noncharacterInInputStream: {
  278. reason: 'Unexpected noncharacter character',
  279. description: 'Unexpected code point `%x`. Do not use noncharacters in HTML'
  280. },
  281. /** @type {ErrorInfo} */
  282. nullCharacterReference: {
  283. reason: 'Unexpected NULL character referenced by character reference',
  284. description: 'Unexpected code point. Do not use NULL characters in HTML'
  285. },
  286. /** @type {ErrorInfo} */
  287. openElementsLeftAfterEof: {
  288. reason: 'Unexpected end of file',
  289. description: 'Unexpected end of file. Expected closing tag instead',
  290. url: false
  291. },
  292. /** @type {ErrorInfo} */
  293. surrogateCharacterReference: {
  294. reason: 'Unexpected surrogate character referenced by character reference',
  295. description:
  296. 'Unexpected code point. Do not use lone surrogate characters in HTML'
  297. },
  298. /** @type {ErrorInfo} */
  299. surrogateInInputStream: {
  300. reason: 'Unexpected surrogate character',
  301. description:
  302. 'Unexpected code point `%x`. Do not use lone surrogate characters in HTML'
  303. },
  304. /** @type {ErrorInfo} */
  305. unexpectedCharacterAfterDoctypeSystemIdentifier: {
  306. reason: 'Invalid character after system identifier in doctype',
  307. description: 'Unexpected character at `%c`. Expected `>`'
  308. },
  309. /** @type {ErrorInfo} */
  310. unexpectedCharacterInAttributeName: {
  311. reason: 'Unexpected character in attribute name',
  312. description:
  313. 'Unexpected `%c`. Expected whitespace, `/`, `>`, `=`, or probably an ASCII letter'
  314. },
  315. /** @type {ErrorInfo} */
  316. unexpectedCharacterInUnquotedAttributeValue: {
  317. reason: 'Unexpected character in unquoted attribute value',
  318. description: 'Unexpected `%c`. Quote the attribute value to include it'
  319. },
  320. /** @type {ErrorInfo} */
  321. unexpectedEqualsSignBeforeAttributeName: {
  322. reason: 'Unexpected equals sign before attribute name',
  323. description: 'Unexpected `%c`. Add an attribute name before it'
  324. },
  325. /** @type {ErrorInfo} */
  326. unexpectedNullCharacter: {
  327. reason: 'Unexpected NULL character',
  328. description:
  329. 'Unexpected code point `%x`. Do not use NULL characters in HTML'
  330. },
  331. /** @type {ErrorInfo} */
  332. unexpectedQuestionMarkInsteadOfTagName: {
  333. reason: 'Unexpected question mark instead of tag name',
  334. description: 'Unexpected `%c`. Expected an ASCII letter instead'
  335. },
  336. /** @type {ErrorInfo} */
  337. unexpectedSolidusInTag: {
  338. reason: 'Unexpected slash in tag',
  339. description:
  340. 'Unexpected `%c-1`. Expected it followed by `>` or in a quoted attribute value'
  341. },
  342. /** @type {ErrorInfo} */
  343. unknownNamedCharacterReference: {
  344. reason: 'Unexpected unknown named character reference',
  345. description:
  346. 'Unexpected character reference. Expected known named character references'
  347. }
  348. }