parse5 6.0.0 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/common/doctype.d.ts +5 -0
  3. package/dist/cjs/common/doctype.js +120 -0
  4. package/dist/cjs/common/error-codes.d.ts +68 -0
  5. package/dist/cjs/common/error-codes.js +67 -0
  6. package/dist/cjs/common/foreign-content.d.ts +10 -0
  7. package/dist/cjs/common/foreign-content.js +239 -0
  8. package/dist/cjs/common/html.d.ts +288 -0
  9. package/dist/cjs/common/html.js +529 -0
  10. package/dist/cjs/common/token.d.ts +85 -0
  11. package/dist/cjs/common/token.js +25 -0
  12. package/dist/cjs/common/unicode.d.ts +49 -0
  13. package/dist/cjs/common/unicode.js +77 -0
  14. package/dist/cjs/index.d.ts +60 -0
  15. package/dist/cjs/index.js +55 -0
  16. package/dist/cjs/parser/formatting-element-list.d.ts +37 -0
  17. package/dist/cjs/parser/formatting-element-list.js +115 -0
  18. package/dist/cjs/parser/index.d.ts +157 -0
  19. package/dist/cjs/parser/index.js +3053 -0
  20. package/dist/cjs/parser/open-element-stack.d.ts +53 -0
  21. package/dist/cjs/parser/open-element-stack.js +316 -0
  22. package/dist/cjs/serializer/index.d.ts +61 -0
  23. package/dist/cjs/serializer/index.js +173 -0
  24. package/dist/cjs/tokenizer/index.d.ts +248 -0
  25. package/dist/cjs/tokenizer/index.js +2907 -0
  26. package/dist/cjs/tokenizer/preprocessor.d.ts +37 -0
  27. package/dist/cjs/tokenizer/preprocessor.js +198 -0
  28. package/dist/cjs/tree-adapters/default.d.ts +85 -0
  29. package/dist/cjs/tree-adapters/default.js +177 -0
  30. package/dist/cjs/tree-adapters/interface.d.ts +250 -0
  31. package/dist/cjs/tree-adapters/interface.js +3 -0
  32. package/dist/common/doctype.d.ts +5 -0
  33. package/{lib → dist}/common/doctype.js +25 -72
  34. package/dist/common/error-codes.d.ts +68 -0
  35. package/dist/common/error-codes.js +64 -0
  36. package/dist/common/foreign-content.d.ts +10 -0
  37. package/dist/common/foreign-content.js +230 -0
  38. package/dist/common/html.d.ts +288 -0
  39. package/dist/common/html.js +523 -0
  40. package/dist/common/token.d.ts +85 -0
  41. package/dist/common/token.js +21 -0
  42. package/dist/common/unicode.d.ts +49 -0
  43. package/dist/common/unicode.js +69 -0
  44. package/dist/index.d.ts +60 -0
  45. package/dist/index.js +44 -0
  46. package/dist/parser/formatting-element-list.d.ts +37 -0
  47. package/dist/parser/formatting-element-list.js +111 -0
  48. package/dist/parser/index.d.ts +157 -0
  49. package/dist/parser/index.js +3058 -0
  50. package/dist/parser/open-element-stack.d.ts +53 -0
  51. package/dist/parser/open-element-stack.js +312 -0
  52. package/dist/serializer/index.d.ts +61 -0
  53. package/dist/serializer/index.js +168 -0
  54. package/dist/tokenizer/index.d.ts +248 -0
  55. package/dist/tokenizer/index.js +2903 -0
  56. package/dist/tokenizer/preprocessor.d.ts +37 -0
  57. package/dist/tokenizer/preprocessor.js +194 -0
  58. package/dist/tree-adapters/default.d.ts +85 -0
  59. package/dist/tree-adapters/default.js +174 -0
  60. package/dist/tree-adapters/interface.d.ts +250 -0
  61. package/dist/tree-adapters/interface.js +2 -0
  62. package/package.json +19 -5
  63. package/lib/common/error-codes.js +0 -65
  64. package/lib/common/foreign-content.js +0 -265
  65. package/lib/common/html.js +0 -272
  66. package/lib/common/unicode.js +0 -109
  67. package/lib/extensions/error-reporting/mixin-base.js +0 -43
  68. package/lib/extensions/error-reporting/parser-mixin.js +0 -52
  69. package/lib/extensions/error-reporting/preprocessor-mixin.js +0 -24
  70. package/lib/extensions/error-reporting/tokenizer-mixin.js +0 -17
  71. package/lib/extensions/location-info/open-element-stack-mixin.js +0 -35
  72. package/lib/extensions/location-info/parser-mixin.js +0 -223
  73. package/lib/extensions/location-info/tokenizer-mixin.js +0 -146
  74. package/lib/extensions/position-tracking/preprocessor-mixin.js +0 -64
  75. package/lib/index.js +0 -29
  76. package/lib/parser/formatting-element-list.js +0 -181
  77. package/lib/parser/index.js +0 -2956
  78. package/lib/parser/open-element-stack.js +0 -482
  79. package/lib/serializer/index.js +0 -176
  80. package/lib/tokenizer/index.js +0 -2196
  81. package/lib/tokenizer/named-entity-data.js +0 -5
  82. package/lib/tokenizer/preprocessor.js +0 -159
  83. package/lib/tree-adapters/default.js +0 -221
  84. package/lib/utils/merge-options.js +0 -13
  85. package/lib/utils/mixin.js +0 -39
@@ -0,0 +1,3053 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Parser = void 0;
4
+ const index_js_1 = require("../tokenizer/index.js");
5
+ const open_element_stack_js_1 = require("./open-element-stack.js");
6
+ const formatting_element_list_js_1 = require("./formatting-element-list.js");
7
+ const default_js_1 = require("../tree-adapters/default.js");
8
+ const doctype = require("../common/doctype.js");
9
+ const foreignContent = require("../common/foreign-content.js");
10
+ const error_codes_js_1 = require("../common/error-codes.js");
11
+ const unicode = require("../common/unicode.js");
12
+ const html_js_1 = require("../common/html.js");
13
+ const token_js_1 = require("../common/token.js");
14
+ //Misc constants
15
+ const HIDDEN_INPUT_TYPE = 'hidden';
16
+ //Adoption agency loops iteration count
17
+ const AA_OUTER_LOOP_ITER = 8;
18
+ const AA_INNER_LOOP_ITER = 3;
19
+ //Insertion modes
20
+ var InsertionMode;
21
+ (function (InsertionMode) {
22
+ InsertionMode[InsertionMode["INITIAL"] = 0] = "INITIAL";
23
+ InsertionMode[InsertionMode["BEFORE_HTML"] = 1] = "BEFORE_HTML";
24
+ InsertionMode[InsertionMode["BEFORE_HEAD"] = 2] = "BEFORE_HEAD";
25
+ InsertionMode[InsertionMode["IN_HEAD"] = 3] = "IN_HEAD";
26
+ InsertionMode[InsertionMode["IN_HEAD_NO_SCRIPT"] = 4] = "IN_HEAD_NO_SCRIPT";
27
+ InsertionMode[InsertionMode["AFTER_HEAD"] = 5] = "AFTER_HEAD";
28
+ InsertionMode[InsertionMode["IN_BODY"] = 6] = "IN_BODY";
29
+ InsertionMode[InsertionMode["TEXT"] = 7] = "TEXT";
30
+ InsertionMode[InsertionMode["IN_TABLE"] = 8] = "IN_TABLE";
31
+ InsertionMode[InsertionMode["IN_TABLE_TEXT"] = 9] = "IN_TABLE_TEXT";
32
+ InsertionMode[InsertionMode["IN_CAPTION"] = 10] = "IN_CAPTION";
33
+ InsertionMode[InsertionMode["IN_COLUMN_GROUP"] = 11] = "IN_COLUMN_GROUP";
34
+ InsertionMode[InsertionMode["IN_TABLE_BODY"] = 12] = "IN_TABLE_BODY";
35
+ InsertionMode[InsertionMode["IN_ROW"] = 13] = "IN_ROW";
36
+ InsertionMode[InsertionMode["IN_CELL"] = 14] = "IN_CELL";
37
+ InsertionMode[InsertionMode["IN_SELECT"] = 15] = "IN_SELECT";
38
+ InsertionMode[InsertionMode["IN_SELECT_IN_TABLE"] = 16] = "IN_SELECT_IN_TABLE";
39
+ InsertionMode[InsertionMode["IN_TEMPLATE"] = 17] = "IN_TEMPLATE";
40
+ InsertionMode[InsertionMode["AFTER_BODY"] = 18] = "AFTER_BODY";
41
+ InsertionMode[InsertionMode["IN_FRAMESET"] = 19] = "IN_FRAMESET";
42
+ InsertionMode[InsertionMode["AFTER_FRAMESET"] = 20] = "AFTER_FRAMESET";
43
+ InsertionMode[InsertionMode["AFTER_AFTER_BODY"] = 21] = "AFTER_AFTER_BODY";
44
+ InsertionMode[InsertionMode["AFTER_AFTER_FRAMESET"] = 22] = "AFTER_AFTER_FRAMESET";
45
+ })(InsertionMode || (InsertionMode = {}));
46
+ const BASE_LOC = {
47
+ startLine: -1,
48
+ startCol: -1,
49
+ startOffset: -1,
50
+ endLine: -1,
51
+ endCol: -1,
52
+ endOffset: -1,
53
+ };
54
+ const TABLE_STRUCTURE_TAGS = new Set([html_js_1.TAG_ID.TABLE, html_js_1.TAG_ID.TBODY, html_js_1.TAG_ID.TFOOT, html_js_1.TAG_ID.THEAD, html_js_1.TAG_ID.TR]);
55
+ const defaultParserOptions = {
56
+ scriptingEnabled: true,
57
+ sourceCodeLocationInfo: false,
58
+ treeAdapter: default_js_1.defaultTreeAdapter,
59
+ onParseError: null,
60
+ };
61
+ //Parser
62
+ class Parser {
63
+ constructor(options, document, fragmentContext = null, scriptHandler = null) {
64
+ this.fragmentContext = fragmentContext;
65
+ this.scriptHandler = scriptHandler;
66
+ this.currentToken = null;
67
+ this.stopped = false;
68
+ this.insertionMode = InsertionMode.INITIAL;
69
+ this.originalInsertionMode = InsertionMode.INITIAL;
70
+ this.headElement = null;
71
+ this.formElement = null;
72
+ /** Indicates that the current node is not an element in the HTML namespace */
73
+ this.currentNotInHTML = false;
74
+ /**
75
+ * The template insertion mode stack is maintained from the left.
76
+ * Ie. the topmost element will always have index 0.
77
+ */
78
+ this.tmplInsertionModeStack = [];
79
+ this.pendingCharacterTokens = [];
80
+ this.hasNonWhitespacePendingCharacterToken = false;
81
+ this.framesetOk = true;
82
+ this.skipNextNewLine = false;
83
+ this.fosterParentingEnabled = false;
84
+ this.options = Object.assign(Object.assign({}, defaultParserOptions), options);
85
+ this.treeAdapter = this.options.treeAdapter;
86
+ this.onParseError = this.options.onParseError;
87
+ // Always enable location info if we report parse errors.
88
+ if (this.onParseError) {
89
+ this.options.sourceCodeLocationInfo = true;
90
+ }
91
+ this.document = document !== null && document !== void 0 ? document : this.treeAdapter.createDocument();
92
+ this.tokenizer = new index_js_1.Tokenizer(this.options, this);
93
+ this.activeFormattingElements = new formatting_element_list_js_1.FormattingElementList(this.treeAdapter);
94
+ this.fragmentContextID = fragmentContext ? (0, html_js_1.getTagID)(this.treeAdapter.getTagName(fragmentContext)) : html_js_1.TAG_ID.UNKNOWN;
95
+ this._setContextModes(fragmentContext !== null && fragmentContext !== void 0 ? fragmentContext : this.document, this.fragmentContextID);
96
+ this.openElements = new open_element_stack_js_1.OpenElementStack(this.document, this.treeAdapter, this);
97
+ }
98
+ // API
99
+ static parse(html, options) {
100
+ const parser = new this(options);
101
+ parser.tokenizer.write(html, true);
102
+ return parser.document;
103
+ }
104
+ static getFragmentParser(fragmentContext, options) {
105
+ const opts = Object.assign(Object.assign({}, defaultParserOptions), options);
106
+ //NOTE: use a <template> element as the fragment context if no context element was provided,
107
+ //so we will parse in a "forgiving" manner
108
+ fragmentContext !== null && fragmentContext !== void 0 ? fragmentContext : (fragmentContext = opts.treeAdapter.createElement(html_js_1.TAG_NAMES.TEMPLATE, html_js_1.NS.HTML, []));
109
+ //NOTE: create a fake element which will be used as the `document` for fragment parsing.
110
+ //This is important for jsdom, where a new `document` cannot be created. This led to
111
+ //fragment parsing messing with the main `document`.
112
+ const documentMock = opts.treeAdapter.createElement('documentmock', html_js_1.NS.HTML, []);
113
+ const parser = new this(opts, documentMock, fragmentContext);
114
+ if (parser.fragmentContextID === html_js_1.TAG_ID.TEMPLATE) {
115
+ parser.tmplInsertionModeStack.unshift(InsertionMode.IN_TEMPLATE);
116
+ }
117
+ parser._initTokenizerForFragmentParsing();
118
+ parser._insertFakeRootElement();
119
+ parser._resetInsertionMode();
120
+ parser._findFormInFragmentContext();
121
+ return parser;
122
+ }
123
+ getFragment() {
124
+ const rootElement = this.treeAdapter.getFirstChild(this.document);
125
+ const fragment = this.treeAdapter.createDocumentFragment();
126
+ this._adoptNodes(rootElement, fragment);
127
+ return fragment;
128
+ }
129
+ //Errors
130
+ _err(token, code, beforeToken) {
131
+ var _a;
132
+ if (!this.onParseError)
133
+ return;
134
+ const loc = (_a = token.location) !== null && _a !== void 0 ? _a : BASE_LOC;
135
+ const err = {
136
+ code,
137
+ startLine: loc.startLine,
138
+ startCol: loc.startCol,
139
+ startOffset: loc.startOffset,
140
+ endLine: beforeToken ? loc.startLine : loc.endLine,
141
+ endCol: beforeToken ? loc.startCol : loc.endCol,
142
+ endOffset: beforeToken ? loc.startOffset : loc.endOffset,
143
+ };
144
+ this.onParseError(err);
145
+ }
146
+ //Stack events
147
+ onItemPush(node, tid, isTop) {
148
+ var _a, _b;
149
+ (_b = (_a = this.treeAdapter).onItemPush) === null || _b === void 0 ? void 0 : _b.call(_a, node);
150
+ if (isTop && this.openElements.stackTop > 0)
151
+ this._setContextModes(node, tid);
152
+ }
153
+ onItemPop(node, isTop) {
154
+ var _a, _b;
155
+ if (this.options.sourceCodeLocationInfo) {
156
+ this._setEndLocation(node, this.currentToken);
157
+ }
158
+ (_b = (_a = this.treeAdapter).onItemPop) === null || _b === void 0 ? void 0 : _b.call(_a, node, this.openElements.current);
159
+ if (isTop) {
160
+ let current;
161
+ let currentTagId;
162
+ if (this.openElements.stackTop === 0 && this.fragmentContext) {
163
+ current = this.fragmentContext;
164
+ currentTagId = this.fragmentContextID;
165
+ }
166
+ else {
167
+ ({ current, currentTagId } = this.openElements);
168
+ }
169
+ this._setContextModes(current, currentTagId);
170
+ }
171
+ }
172
+ _setContextModes(current, tid) {
173
+ const isHTML = current === this.document || this.treeAdapter.getNamespaceURI(current) === html_js_1.NS.HTML;
174
+ this.currentNotInHTML = !isHTML;
175
+ this.tokenizer.inForeignNode = !isHTML && !this._isIntegrationPoint(tid, current);
176
+ }
177
+ _switchToTextParsing(currentToken, nextTokenizerState) {
178
+ this._insertElement(currentToken, html_js_1.NS.HTML);
179
+ this.tokenizer.state = nextTokenizerState;
180
+ this.originalInsertionMode = this.insertionMode;
181
+ this.insertionMode = InsertionMode.TEXT;
182
+ }
183
+ switchToPlaintextParsing() {
184
+ this.insertionMode = InsertionMode.TEXT;
185
+ this.originalInsertionMode = InsertionMode.IN_BODY;
186
+ this.tokenizer.state = index_js_1.TokenizerMode.PLAINTEXT;
187
+ }
188
+ //Fragment parsing
189
+ _getAdjustedCurrentElement() {
190
+ return this.openElements.stackTop === 0 && this.fragmentContext
191
+ ? this.fragmentContext
192
+ : this.openElements.current;
193
+ }
194
+ _findFormInFragmentContext() {
195
+ let node = this.fragmentContext;
196
+ while (node) {
197
+ if (this.treeAdapter.getTagName(node) === html_js_1.TAG_NAMES.FORM) {
198
+ this.formElement = node;
199
+ break;
200
+ }
201
+ node = this.treeAdapter.getParentNode(node);
202
+ }
203
+ }
204
+ _initTokenizerForFragmentParsing() {
205
+ if (!this.fragmentContext || this.treeAdapter.getNamespaceURI(this.fragmentContext) !== html_js_1.NS.HTML) {
206
+ return;
207
+ }
208
+ switch (this.fragmentContextID) {
209
+ case html_js_1.TAG_ID.TITLE:
210
+ case html_js_1.TAG_ID.TEXTAREA: {
211
+ this.tokenizer.state = index_js_1.TokenizerMode.RCDATA;
212
+ break;
213
+ }
214
+ case html_js_1.TAG_ID.STYLE:
215
+ case html_js_1.TAG_ID.XMP:
216
+ case html_js_1.TAG_ID.IFRAME:
217
+ case html_js_1.TAG_ID.NOEMBED:
218
+ case html_js_1.TAG_ID.NOFRAMES:
219
+ case html_js_1.TAG_ID.NOSCRIPT: {
220
+ this.tokenizer.state = index_js_1.TokenizerMode.RAWTEXT;
221
+ break;
222
+ }
223
+ case html_js_1.TAG_ID.SCRIPT: {
224
+ this.tokenizer.state = index_js_1.TokenizerMode.SCRIPT_DATA;
225
+ break;
226
+ }
227
+ case html_js_1.TAG_ID.PLAINTEXT: {
228
+ this.tokenizer.state = index_js_1.TokenizerMode.PLAINTEXT;
229
+ break;
230
+ }
231
+ default:
232
+ // Do nothing
233
+ }
234
+ }
235
+ //Tree mutation
236
+ _setDocumentType(token) {
237
+ const name = token.name || '';
238
+ const publicId = token.publicId || '';
239
+ const systemId = token.systemId || '';
240
+ this.treeAdapter.setDocumentType(this.document, name, publicId, systemId);
241
+ if (token.location) {
242
+ const documentChildren = this.treeAdapter.getChildNodes(this.document);
243
+ const docTypeNode = documentChildren.find((node) => this.treeAdapter.isDocumentTypeNode(node));
244
+ if (docTypeNode) {
245
+ this.treeAdapter.setNodeSourceCodeLocation(docTypeNode, token.location);
246
+ }
247
+ }
248
+ }
249
+ _attachElementToTree(element, location) {
250
+ if (this.options.sourceCodeLocationInfo) {
251
+ const loc = location && Object.assign(Object.assign({}, location), { startTag: location });
252
+ this.treeAdapter.setNodeSourceCodeLocation(element, loc);
253
+ }
254
+ if (this._shouldFosterParentOnInsertion()) {
255
+ this._fosterParentElement(element);
256
+ }
257
+ else {
258
+ const parent = this.openElements.currentTmplContentOrNode;
259
+ this.treeAdapter.appendChild(parent, element);
260
+ }
261
+ }
262
+ _appendElement(token, namespaceURI) {
263
+ const element = this.treeAdapter.createElement(token.tagName, namespaceURI, token.attrs);
264
+ this._attachElementToTree(element, token.location);
265
+ }
266
+ _insertElement(token, namespaceURI) {
267
+ const element = this.treeAdapter.createElement(token.tagName, namespaceURI, token.attrs);
268
+ this._attachElementToTree(element, token.location);
269
+ this.openElements.push(element, token.tagID);
270
+ }
271
+ _insertFakeElement(tagName, tagID) {
272
+ const element = this.treeAdapter.createElement(tagName, html_js_1.NS.HTML, []);
273
+ this._attachElementToTree(element, null);
274
+ this.openElements.push(element, tagID);
275
+ }
276
+ _insertTemplate(token) {
277
+ const tmpl = this.treeAdapter.createElement(token.tagName, html_js_1.NS.HTML, token.attrs);
278
+ const content = this.treeAdapter.createDocumentFragment();
279
+ this.treeAdapter.setTemplateContent(tmpl, content);
280
+ this._attachElementToTree(tmpl, token.location);
281
+ this.openElements.push(tmpl, token.tagID);
282
+ if (this.options.sourceCodeLocationInfo)
283
+ this.treeAdapter.setNodeSourceCodeLocation(content, null);
284
+ }
285
+ _insertFakeRootElement() {
286
+ const element = this.treeAdapter.createElement(html_js_1.TAG_NAMES.HTML, html_js_1.NS.HTML, []);
287
+ if (this.options.sourceCodeLocationInfo)
288
+ this.treeAdapter.setNodeSourceCodeLocation(element, null);
289
+ this.treeAdapter.appendChild(this.openElements.current, element);
290
+ this.openElements.push(element, html_js_1.TAG_ID.HTML);
291
+ }
292
+ _appendCommentNode(token, parent) {
293
+ const commentNode = this.treeAdapter.createCommentNode(token.data);
294
+ this.treeAdapter.appendChild(parent, commentNode);
295
+ if (this.options.sourceCodeLocationInfo) {
296
+ this.treeAdapter.setNodeSourceCodeLocation(commentNode, token.location);
297
+ }
298
+ }
299
+ _insertCharacters(token) {
300
+ let parent;
301
+ let beforeElement;
302
+ if (this._shouldFosterParentOnInsertion()) {
303
+ ({ parent, beforeElement } = this._findFosterParentingLocation());
304
+ if (beforeElement) {
305
+ this.treeAdapter.insertTextBefore(parent, token.chars, beforeElement);
306
+ }
307
+ else {
308
+ this.treeAdapter.insertText(parent, token.chars);
309
+ }
310
+ }
311
+ else {
312
+ parent = this.openElements.currentTmplContentOrNode;
313
+ this.treeAdapter.insertText(parent, token.chars);
314
+ }
315
+ if (!token.location)
316
+ return;
317
+ const siblings = this.treeAdapter.getChildNodes(parent);
318
+ const textNodeIdx = beforeElement ? siblings.lastIndexOf(beforeElement) : siblings.length;
319
+ const textNode = siblings[textNodeIdx - 1];
320
+ //NOTE: if we have a location assigned by another token, then just update the end position
321
+ const tnLoc = this.treeAdapter.getNodeSourceCodeLocation(textNode);
322
+ if (tnLoc) {
323
+ const { endLine, endCol, endOffset } = token.location;
324
+ this.treeAdapter.updateNodeSourceCodeLocation(textNode, { endLine, endCol, endOffset });
325
+ }
326
+ else if (this.options.sourceCodeLocationInfo) {
327
+ this.treeAdapter.setNodeSourceCodeLocation(textNode, token.location);
328
+ }
329
+ }
330
+ _adoptNodes(donor, recipient) {
331
+ for (let child = this.treeAdapter.getFirstChild(donor); child; child = this.treeAdapter.getFirstChild(donor)) {
332
+ this.treeAdapter.detachNode(child);
333
+ this.treeAdapter.appendChild(recipient, child);
334
+ }
335
+ }
336
+ _setEndLocation(element, closingToken) {
337
+ if (this.treeAdapter.getNodeSourceCodeLocation(element) && closingToken.location) {
338
+ const ctLoc = closingToken.location;
339
+ const tn = this.treeAdapter.getTagName(element);
340
+ const endLoc =
341
+ // NOTE: For cases like <p> <p> </p> - First 'p' closes without a closing
342
+ // tag and for cases like <td> <p> </td> - 'p' closes without a closing tag.
343
+ closingToken.type === token_js_1.TokenType.END_TAG && tn === closingToken.tagName
344
+ ? {
345
+ endTag: Object.assign({}, ctLoc),
346
+ endLine: ctLoc.endLine,
347
+ endCol: ctLoc.endCol,
348
+ endOffset: ctLoc.endOffset,
349
+ }
350
+ : {
351
+ endLine: ctLoc.startLine,
352
+ endCol: ctLoc.startCol,
353
+ endOffset: ctLoc.startOffset,
354
+ };
355
+ this.treeAdapter.updateNodeSourceCodeLocation(element, endLoc);
356
+ }
357
+ }
358
+ //Token processing
359
+ shouldProcessStartTagTokenInForeignContent(token) {
360
+ // Check that neither current === document, or ns === NS.HTML
361
+ if (!this.currentNotInHTML)
362
+ return false;
363
+ let current;
364
+ let currentTagId;
365
+ if (this.openElements.stackTop === 0 && this.fragmentContext) {
366
+ current = this.fragmentContext;
367
+ currentTagId = this.fragmentContextID;
368
+ }
369
+ else {
370
+ ({ current, currentTagId } = this.openElements);
371
+ }
372
+ if (token.tagID === html_js_1.TAG_ID.SVG &&
373
+ this.treeAdapter.getTagName(current) === html_js_1.TAG_NAMES.ANNOTATION_XML &&
374
+ this.treeAdapter.getNamespaceURI(current) === html_js_1.NS.MATHML) {
375
+ return false;
376
+ }
377
+ return (
378
+ // Check that `current` is not an integration point for HTML or MathML elements.
379
+ this.tokenizer.inForeignNode ||
380
+ // If it _is_ an integration point, then we might have to check that it is not an HTML
381
+ // integration point.
382
+ ((token.tagID === html_js_1.TAG_ID.MGLYPH || token.tagID === html_js_1.TAG_ID.MALIGNMARK) &&
383
+ !this._isIntegrationPoint(currentTagId, current, html_js_1.NS.HTML)));
384
+ }
385
+ _processToken(token) {
386
+ switch (token.type) {
387
+ case token_js_1.TokenType.CHARACTER: {
388
+ this.onCharacter(token);
389
+ break;
390
+ }
391
+ case token_js_1.TokenType.NULL_CHARACTER: {
392
+ this.onNullCharacter(token);
393
+ break;
394
+ }
395
+ case token_js_1.TokenType.COMMENT: {
396
+ this.onComment(token);
397
+ break;
398
+ }
399
+ case token_js_1.TokenType.DOCTYPE: {
400
+ this.onDoctype(token);
401
+ break;
402
+ }
403
+ case token_js_1.TokenType.START_TAG: {
404
+ this._processStartTag(token);
405
+ break;
406
+ }
407
+ case token_js_1.TokenType.END_TAG: {
408
+ this.onEndTag(token);
409
+ break;
410
+ }
411
+ case token_js_1.TokenType.EOF: {
412
+ this.onEof(token);
413
+ break;
414
+ }
415
+ case token_js_1.TokenType.WHITESPACE_CHARACTER: {
416
+ this.onWhitespaceCharacter(token);
417
+ break;
418
+ }
419
+ }
420
+ }
421
+ //Integration points
422
+ _isIntegrationPoint(tid, element, foreignNS) {
423
+ const ns = this.treeAdapter.getNamespaceURI(element);
424
+ const attrs = this.treeAdapter.getAttrList(element);
425
+ return foreignContent.isIntegrationPoint(tid, ns, attrs, foreignNS);
426
+ }
427
+ //Active formatting elements reconstruction
428
+ _reconstructActiveFormattingElements() {
429
+ const listLength = this.activeFormattingElements.entries.length;
430
+ if (listLength) {
431
+ const endIndex = this.activeFormattingElements.entries.findIndex((entry) => entry.type === formatting_element_list_js_1.EntryType.Marker || this.openElements.contains(entry.element));
432
+ const unopenIdx = endIndex < 0 ? listLength - 1 : endIndex - 1;
433
+ for (let i = unopenIdx; i >= 0; i--) {
434
+ const entry = this.activeFormattingElements.entries[i];
435
+ this._insertElement(entry.token, this.treeAdapter.getNamespaceURI(entry.element));
436
+ entry.element = this.openElements.current;
437
+ }
438
+ }
439
+ }
440
+ //Close elements
441
+ _closeTableCell() {
442
+ this.openElements.generateImpliedEndTags();
443
+ this.openElements.popUntilTableCellPopped();
444
+ this.activeFormattingElements.clearToLastMarker();
445
+ this.insertionMode = InsertionMode.IN_ROW;
446
+ }
447
+ _closePElement() {
448
+ this.openElements.generateImpliedEndTagsWithExclusion(html_js_1.TAG_ID.P);
449
+ this.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.P);
450
+ }
451
+ //Insertion modes
452
+ _resetInsertionMode() {
453
+ for (let i = this.openElements.stackTop; i >= 0; i--) {
454
+ //Insertion mode reset map
455
+ switch (i === 0 && this.fragmentContext ? this.fragmentContextID : this.openElements.tagIDs[i]) {
456
+ case html_js_1.TAG_ID.TR:
457
+ this.insertionMode = InsertionMode.IN_ROW;
458
+ return;
459
+ case html_js_1.TAG_ID.TBODY:
460
+ case html_js_1.TAG_ID.THEAD:
461
+ case html_js_1.TAG_ID.TFOOT:
462
+ this.insertionMode = InsertionMode.IN_TABLE_BODY;
463
+ return;
464
+ case html_js_1.TAG_ID.CAPTION:
465
+ this.insertionMode = InsertionMode.IN_CAPTION;
466
+ return;
467
+ case html_js_1.TAG_ID.COLGROUP:
468
+ this.insertionMode = InsertionMode.IN_COLUMN_GROUP;
469
+ return;
470
+ case html_js_1.TAG_ID.TABLE:
471
+ this.insertionMode = InsertionMode.IN_TABLE;
472
+ return;
473
+ case html_js_1.TAG_ID.BODY:
474
+ this.insertionMode = InsertionMode.IN_BODY;
475
+ return;
476
+ case html_js_1.TAG_ID.FRAMESET:
477
+ this.insertionMode = InsertionMode.IN_FRAMESET;
478
+ return;
479
+ case html_js_1.TAG_ID.SELECT:
480
+ this._resetInsertionModeForSelect(i);
481
+ return;
482
+ case html_js_1.TAG_ID.TEMPLATE:
483
+ this.insertionMode = this.tmplInsertionModeStack[0];
484
+ return;
485
+ case html_js_1.TAG_ID.HTML:
486
+ this.insertionMode = this.headElement ? InsertionMode.AFTER_HEAD : InsertionMode.BEFORE_HEAD;
487
+ return;
488
+ case html_js_1.TAG_ID.TD:
489
+ case html_js_1.TAG_ID.TH:
490
+ if (i > 0) {
491
+ this.insertionMode = InsertionMode.IN_CELL;
492
+ return;
493
+ }
494
+ break;
495
+ case html_js_1.TAG_ID.HEAD:
496
+ if (i > 0) {
497
+ this.insertionMode = InsertionMode.IN_HEAD;
498
+ return;
499
+ }
500
+ break;
501
+ }
502
+ }
503
+ this.insertionMode = InsertionMode.IN_BODY;
504
+ }
505
+ _resetInsertionModeForSelect(selectIdx) {
506
+ if (selectIdx > 0) {
507
+ for (let i = selectIdx - 1; i > 0; i--) {
508
+ const tn = this.openElements.tagIDs[i];
509
+ if (tn === html_js_1.TAG_ID.TEMPLATE) {
510
+ break;
511
+ }
512
+ else if (tn === html_js_1.TAG_ID.TABLE) {
513
+ this.insertionMode = InsertionMode.IN_SELECT_IN_TABLE;
514
+ return;
515
+ }
516
+ }
517
+ }
518
+ this.insertionMode = InsertionMode.IN_SELECT;
519
+ }
520
+ //Foster parenting
521
+ _isElementCausesFosterParenting(tn) {
522
+ return TABLE_STRUCTURE_TAGS.has(tn);
523
+ }
524
+ _shouldFosterParentOnInsertion() {
525
+ return this.fosterParentingEnabled && this._isElementCausesFosterParenting(this.openElements.currentTagId);
526
+ }
527
+ _findFosterParentingLocation() {
528
+ for (let i = this.openElements.stackTop; i >= 0; i--) {
529
+ const openElement = this.openElements.items[i];
530
+ switch (this.openElements.tagIDs[i]) {
531
+ case html_js_1.TAG_ID.TEMPLATE:
532
+ if (this.treeAdapter.getNamespaceURI(openElement) === html_js_1.NS.HTML) {
533
+ return { parent: this.treeAdapter.getTemplateContent(openElement), beforeElement: null };
534
+ }
535
+ break;
536
+ case html_js_1.TAG_ID.TABLE: {
537
+ const parent = this.treeAdapter.getParentNode(openElement);
538
+ if (parent) {
539
+ return { parent, beforeElement: openElement };
540
+ }
541
+ return { parent: this.openElements.items[i - 1], beforeElement: null };
542
+ }
543
+ default:
544
+ // Do nothing
545
+ }
546
+ }
547
+ return { parent: this.openElements.items[0], beforeElement: null };
548
+ }
549
+ _fosterParentElement(element) {
550
+ const location = this._findFosterParentingLocation();
551
+ if (location.beforeElement) {
552
+ this.treeAdapter.insertBefore(location.parent, element, location.beforeElement);
553
+ }
554
+ else {
555
+ this.treeAdapter.appendChild(location.parent, element);
556
+ }
557
+ }
558
+ //Special elements
559
+ _isSpecialElement(element, id) {
560
+ const ns = this.treeAdapter.getNamespaceURI(element);
561
+ return html_js_1.SPECIAL_ELEMENTS[ns].has(id);
562
+ }
563
+ onCharacter(token) {
564
+ this.skipNextNewLine = false;
565
+ if (this.tokenizer.inForeignNode) {
566
+ characterInForeignContent(this, token);
567
+ return;
568
+ }
569
+ switch (this.insertionMode) {
570
+ case InsertionMode.INITIAL:
571
+ tokenInInitialMode(this, token);
572
+ break;
573
+ case InsertionMode.BEFORE_HTML:
574
+ tokenBeforeHtml(this, token);
575
+ break;
576
+ case InsertionMode.BEFORE_HEAD:
577
+ tokenBeforeHead(this, token);
578
+ break;
579
+ case InsertionMode.IN_HEAD:
580
+ tokenInHead(this, token);
581
+ break;
582
+ case InsertionMode.IN_HEAD_NO_SCRIPT:
583
+ tokenInHeadNoScript(this, token);
584
+ break;
585
+ case InsertionMode.AFTER_HEAD:
586
+ tokenAfterHead(this, token);
587
+ break;
588
+ case InsertionMode.IN_BODY:
589
+ case InsertionMode.IN_CAPTION:
590
+ case InsertionMode.IN_CELL:
591
+ case InsertionMode.IN_TEMPLATE:
592
+ characterInBody(this, token);
593
+ break;
594
+ case InsertionMode.TEXT:
595
+ case InsertionMode.IN_SELECT:
596
+ case InsertionMode.IN_SELECT_IN_TABLE:
597
+ this._insertCharacters(token);
598
+ break;
599
+ case InsertionMode.IN_TABLE:
600
+ case InsertionMode.IN_TABLE_BODY:
601
+ case InsertionMode.IN_ROW:
602
+ characterInTable(this, token);
603
+ break;
604
+ case InsertionMode.IN_TABLE_TEXT:
605
+ characterInTableText(this, token);
606
+ break;
607
+ case InsertionMode.IN_COLUMN_GROUP:
608
+ tokenInColumnGroup(this, token);
609
+ break;
610
+ case InsertionMode.AFTER_BODY:
611
+ tokenAfterBody(this, token);
612
+ break;
613
+ case InsertionMode.AFTER_AFTER_BODY:
614
+ tokenAfterAfterBody(this, token);
615
+ break;
616
+ default:
617
+ // Do nothing
618
+ }
619
+ }
620
+ onNullCharacter(token) {
621
+ this.skipNextNewLine = false;
622
+ if (this.tokenizer.inForeignNode) {
623
+ nullCharacterInForeignContent(this, token);
624
+ return;
625
+ }
626
+ switch (this.insertionMode) {
627
+ case InsertionMode.INITIAL:
628
+ tokenInInitialMode(this, token);
629
+ break;
630
+ case InsertionMode.BEFORE_HTML:
631
+ tokenBeforeHtml(this, token);
632
+ break;
633
+ case InsertionMode.BEFORE_HEAD:
634
+ tokenBeforeHead(this, token);
635
+ break;
636
+ case InsertionMode.IN_HEAD:
637
+ tokenInHead(this, token);
638
+ break;
639
+ case InsertionMode.IN_HEAD_NO_SCRIPT:
640
+ tokenInHeadNoScript(this, token);
641
+ break;
642
+ case InsertionMode.AFTER_HEAD:
643
+ tokenAfterHead(this, token);
644
+ break;
645
+ case InsertionMode.TEXT:
646
+ this._insertCharacters(token);
647
+ break;
648
+ case InsertionMode.IN_TABLE:
649
+ case InsertionMode.IN_TABLE_BODY:
650
+ case InsertionMode.IN_ROW:
651
+ characterInTable(this, token);
652
+ break;
653
+ case InsertionMode.IN_COLUMN_GROUP:
654
+ tokenInColumnGroup(this, token);
655
+ break;
656
+ case InsertionMode.AFTER_BODY:
657
+ tokenAfterBody(this, token);
658
+ break;
659
+ case InsertionMode.AFTER_AFTER_BODY:
660
+ tokenAfterAfterBody(this, token);
661
+ break;
662
+ default:
663
+ // Do nothing
664
+ }
665
+ }
666
+ onComment(token) {
667
+ this.skipNextNewLine = false;
668
+ if (this.currentNotInHTML) {
669
+ appendComment(this, token);
670
+ return;
671
+ }
672
+ switch (this.insertionMode) {
673
+ case InsertionMode.INITIAL:
674
+ case InsertionMode.BEFORE_HTML:
675
+ case InsertionMode.BEFORE_HEAD:
676
+ case InsertionMode.IN_HEAD:
677
+ case InsertionMode.IN_HEAD_NO_SCRIPT:
678
+ case InsertionMode.AFTER_HEAD:
679
+ case InsertionMode.IN_BODY:
680
+ case InsertionMode.IN_TABLE:
681
+ case InsertionMode.IN_CAPTION:
682
+ case InsertionMode.IN_COLUMN_GROUP:
683
+ case InsertionMode.IN_TABLE_BODY:
684
+ case InsertionMode.IN_ROW:
685
+ case InsertionMode.IN_CELL:
686
+ case InsertionMode.IN_SELECT:
687
+ case InsertionMode.IN_SELECT_IN_TABLE:
688
+ case InsertionMode.IN_TEMPLATE:
689
+ case InsertionMode.IN_FRAMESET:
690
+ case InsertionMode.AFTER_FRAMESET:
691
+ appendComment(this, token);
692
+ break;
693
+ case InsertionMode.IN_TABLE_TEXT:
694
+ tokenInTableText(this, token);
695
+ break;
696
+ case InsertionMode.AFTER_BODY:
697
+ appendCommentToRootHtmlElement(this, token);
698
+ break;
699
+ case InsertionMode.AFTER_AFTER_BODY:
700
+ case InsertionMode.AFTER_AFTER_FRAMESET:
701
+ appendCommentToDocument(this, token);
702
+ break;
703
+ default:
704
+ // Do nothing
705
+ }
706
+ }
707
+ onDoctype(token) {
708
+ this.skipNextNewLine = false;
709
+ switch (this.insertionMode) {
710
+ case InsertionMode.INITIAL:
711
+ doctypeInInitialMode(this, token);
712
+ break;
713
+ case InsertionMode.BEFORE_HEAD:
714
+ case InsertionMode.IN_HEAD:
715
+ case InsertionMode.IN_HEAD_NO_SCRIPT:
716
+ case InsertionMode.AFTER_HEAD:
717
+ this._err(token, error_codes_js_1.ERR.misplacedDoctype);
718
+ break;
719
+ case InsertionMode.IN_TABLE_TEXT:
720
+ tokenInTableText(this, token);
721
+ break;
722
+ default:
723
+ // Do nothing
724
+ }
725
+ }
726
+ onStartTag(token) {
727
+ this.skipNextNewLine = false;
728
+ this.currentToken = token;
729
+ this._processStartTag(token);
730
+ if (token.selfClosing && !token.ackSelfClosing) {
731
+ this._err(token, error_codes_js_1.ERR.nonVoidHtmlElementStartTagWithTrailingSolidus);
732
+ }
733
+ }
734
+ /**
735
+ * Processes a given start tag.
736
+ *
737
+ * `onStartTag` checks if a self-closing tag was recognized. When a token
738
+ * is moved inbetween multiple insertion modes, this check for self-closing
739
+ * could lead to false positives. To avoid this, `_processStartTag` is used
740
+ * for nested calls.
741
+ *
742
+ * @param token The token to process.
743
+ */
744
+ _processStartTag(token) {
745
+ if (this.shouldProcessStartTagTokenInForeignContent(token)) {
746
+ startTagInForeignContent(this, token);
747
+ }
748
+ else {
749
+ this._startTagOutsideForeignContent(token);
750
+ }
751
+ }
752
+ _startTagOutsideForeignContent(token) {
753
+ switch (this.insertionMode) {
754
+ case InsertionMode.INITIAL:
755
+ tokenInInitialMode(this, token);
756
+ break;
757
+ case InsertionMode.BEFORE_HTML:
758
+ startTagBeforeHtml(this, token);
759
+ break;
760
+ case InsertionMode.BEFORE_HEAD:
761
+ startTagBeforeHead(this, token);
762
+ break;
763
+ case InsertionMode.IN_HEAD:
764
+ startTagInHead(this, token);
765
+ break;
766
+ case InsertionMode.IN_HEAD_NO_SCRIPT:
767
+ startTagInHeadNoScript(this, token);
768
+ break;
769
+ case InsertionMode.AFTER_HEAD:
770
+ startTagAfterHead(this, token);
771
+ break;
772
+ case InsertionMode.IN_BODY:
773
+ startTagInBody(this, token);
774
+ break;
775
+ case InsertionMode.IN_TABLE:
776
+ startTagInTable(this, token);
777
+ break;
778
+ case InsertionMode.IN_TABLE_TEXT:
779
+ tokenInTableText(this, token);
780
+ break;
781
+ case InsertionMode.IN_CAPTION:
782
+ startTagInCaption(this, token);
783
+ break;
784
+ case InsertionMode.IN_COLUMN_GROUP:
785
+ startTagInColumnGroup(this, token);
786
+ break;
787
+ case InsertionMode.IN_TABLE_BODY:
788
+ startTagInTableBody(this, token);
789
+ break;
790
+ case InsertionMode.IN_ROW:
791
+ startTagInRow(this, token);
792
+ break;
793
+ case InsertionMode.IN_CELL:
794
+ startTagInCell(this, token);
795
+ break;
796
+ case InsertionMode.IN_SELECT:
797
+ startTagInSelect(this, token);
798
+ break;
799
+ case InsertionMode.IN_SELECT_IN_TABLE:
800
+ startTagInSelectInTable(this, token);
801
+ break;
802
+ case InsertionMode.IN_TEMPLATE:
803
+ startTagInTemplate(this, token);
804
+ break;
805
+ case InsertionMode.AFTER_BODY:
806
+ startTagAfterBody(this, token);
807
+ break;
808
+ case InsertionMode.IN_FRAMESET:
809
+ startTagInFrameset(this, token);
810
+ break;
811
+ case InsertionMode.AFTER_FRAMESET:
812
+ startTagAfterFrameset(this, token);
813
+ break;
814
+ case InsertionMode.AFTER_AFTER_BODY:
815
+ startTagAfterAfterBody(this, token);
816
+ break;
817
+ case InsertionMode.AFTER_AFTER_FRAMESET:
818
+ startTagAfterAfterFrameset(this, token);
819
+ break;
820
+ default:
821
+ // Do nothing
822
+ }
823
+ }
824
+ onEndTag(token) {
825
+ this.skipNextNewLine = false;
826
+ this.currentToken = token;
827
+ if (this.currentNotInHTML) {
828
+ endTagInForeignContent(this, token);
829
+ }
830
+ else {
831
+ this._endTagOutsideForeignContent(token);
832
+ }
833
+ }
834
+ _endTagOutsideForeignContent(token) {
835
+ switch (this.insertionMode) {
836
+ case InsertionMode.INITIAL:
837
+ tokenInInitialMode(this, token);
838
+ break;
839
+ case InsertionMode.BEFORE_HTML:
840
+ endTagBeforeHtml(this, token);
841
+ break;
842
+ case InsertionMode.BEFORE_HEAD:
843
+ endTagBeforeHead(this, token);
844
+ break;
845
+ case InsertionMode.IN_HEAD:
846
+ endTagInHead(this, token);
847
+ break;
848
+ case InsertionMode.IN_HEAD_NO_SCRIPT:
849
+ endTagInHeadNoScript(this, token);
850
+ break;
851
+ case InsertionMode.AFTER_HEAD:
852
+ endTagAfterHead(this, token);
853
+ break;
854
+ case InsertionMode.IN_BODY:
855
+ endTagInBody(this, token);
856
+ break;
857
+ case InsertionMode.TEXT:
858
+ endTagInText(this, token);
859
+ break;
860
+ case InsertionMode.IN_TABLE:
861
+ endTagInTable(this, token);
862
+ break;
863
+ case InsertionMode.IN_TABLE_TEXT:
864
+ tokenInTableText(this, token);
865
+ break;
866
+ case InsertionMode.IN_CAPTION:
867
+ endTagInCaption(this, token);
868
+ break;
869
+ case InsertionMode.IN_COLUMN_GROUP:
870
+ endTagInColumnGroup(this, token);
871
+ break;
872
+ case InsertionMode.IN_TABLE_BODY:
873
+ endTagInTableBody(this, token);
874
+ break;
875
+ case InsertionMode.IN_ROW:
876
+ endTagInRow(this, token);
877
+ break;
878
+ case InsertionMode.IN_CELL:
879
+ endTagInCell(this, token);
880
+ break;
881
+ case InsertionMode.IN_SELECT:
882
+ endTagInSelect(this, token);
883
+ break;
884
+ case InsertionMode.IN_SELECT_IN_TABLE:
885
+ endTagInSelectInTable(this, token);
886
+ break;
887
+ case InsertionMode.IN_TEMPLATE:
888
+ endTagInTemplate(this, token);
889
+ break;
890
+ case InsertionMode.AFTER_BODY:
891
+ endTagAfterBody(this, token);
892
+ break;
893
+ case InsertionMode.IN_FRAMESET:
894
+ endTagInFrameset(this, token);
895
+ break;
896
+ case InsertionMode.AFTER_FRAMESET:
897
+ endTagAfterFrameset(this, token);
898
+ break;
899
+ case InsertionMode.AFTER_AFTER_BODY:
900
+ tokenAfterAfterBody(this, token);
901
+ break;
902
+ default:
903
+ // Do nothing
904
+ }
905
+ }
906
+ onEof(token) {
907
+ switch (this.insertionMode) {
908
+ case InsertionMode.INITIAL:
909
+ tokenInInitialMode(this, token);
910
+ break;
911
+ case InsertionMode.BEFORE_HTML:
912
+ tokenBeforeHtml(this, token);
913
+ break;
914
+ case InsertionMode.BEFORE_HEAD:
915
+ tokenBeforeHead(this, token);
916
+ break;
917
+ case InsertionMode.IN_HEAD:
918
+ tokenInHead(this, token);
919
+ break;
920
+ case InsertionMode.IN_HEAD_NO_SCRIPT:
921
+ tokenInHeadNoScript(this, token);
922
+ break;
923
+ case InsertionMode.AFTER_HEAD:
924
+ tokenAfterHead(this, token);
925
+ break;
926
+ case InsertionMode.IN_BODY:
927
+ case InsertionMode.IN_TABLE:
928
+ case InsertionMode.IN_CAPTION:
929
+ case InsertionMode.IN_COLUMN_GROUP:
930
+ case InsertionMode.IN_TABLE_BODY:
931
+ case InsertionMode.IN_ROW:
932
+ case InsertionMode.IN_CELL:
933
+ case InsertionMode.IN_SELECT:
934
+ case InsertionMode.IN_SELECT_IN_TABLE:
935
+ eofInBody(this, token);
936
+ break;
937
+ case InsertionMode.TEXT:
938
+ eofInText(this, token);
939
+ break;
940
+ case InsertionMode.IN_TABLE_TEXT:
941
+ tokenInTableText(this, token);
942
+ break;
943
+ case InsertionMode.IN_TEMPLATE:
944
+ eofInTemplate(this, token);
945
+ break;
946
+ case InsertionMode.AFTER_BODY:
947
+ case InsertionMode.IN_FRAMESET:
948
+ case InsertionMode.AFTER_FRAMESET:
949
+ case InsertionMode.AFTER_AFTER_BODY:
950
+ case InsertionMode.AFTER_AFTER_FRAMESET:
951
+ stopParsing(this, token);
952
+ break;
953
+ default:
954
+ // Do nothing
955
+ }
956
+ }
957
+ onWhitespaceCharacter(token) {
958
+ if (this.skipNextNewLine) {
959
+ this.skipNextNewLine = false;
960
+ if (token.chars.charCodeAt(0) === unicode.CODE_POINTS.LINE_FEED) {
961
+ if (token.chars.length === 1) {
962
+ return;
963
+ }
964
+ token.chars = token.chars.substr(1);
965
+ }
966
+ }
967
+ if (this.tokenizer.inForeignNode) {
968
+ this._insertCharacters(token);
969
+ return;
970
+ }
971
+ switch (this.insertionMode) {
972
+ case InsertionMode.IN_HEAD:
973
+ case InsertionMode.IN_HEAD_NO_SCRIPT:
974
+ case InsertionMode.AFTER_HEAD:
975
+ case InsertionMode.TEXT:
976
+ case InsertionMode.IN_COLUMN_GROUP:
977
+ case InsertionMode.IN_SELECT:
978
+ case InsertionMode.IN_SELECT_IN_TABLE:
979
+ case InsertionMode.IN_FRAMESET:
980
+ case InsertionMode.AFTER_FRAMESET:
981
+ this._insertCharacters(token);
982
+ break;
983
+ case InsertionMode.IN_BODY:
984
+ case InsertionMode.IN_CAPTION:
985
+ case InsertionMode.IN_CELL:
986
+ case InsertionMode.IN_TEMPLATE:
987
+ case InsertionMode.AFTER_BODY:
988
+ case InsertionMode.AFTER_AFTER_BODY:
989
+ case InsertionMode.AFTER_AFTER_FRAMESET:
990
+ whitespaceCharacterInBody(this, token);
991
+ break;
992
+ case InsertionMode.IN_TABLE:
993
+ case InsertionMode.IN_TABLE_BODY:
994
+ case InsertionMode.IN_ROW:
995
+ characterInTable(this, token);
996
+ break;
997
+ case InsertionMode.IN_TABLE_TEXT:
998
+ whitespaceCharacterInTableText(this, token);
999
+ break;
1000
+ default:
1001
+ // Do nothing
1002
+ }
1003
+ }
1004
+ }
1005
+ exports.Parser = Parser;
1006
+ //Adoption agency algorithm
1007
+ //(see: http://www.whatwg.org/specs/web-apps/current-work/multipage/tree-construction.html#adoptionAgency)
1008
+ //------------------------------------------------------------------
1009
+ //Steps 5-8 of the algorithm
1010
+ function aaObtainFormattingElementEntry(p, token) {
1011
+ let formattingElementEntry = p.activeFormattingElements.getElementEntryInScopeWithTagName(token.tagName);
1012
+ if (formattingElementEntry) {
1013
+ if (!p.openElements.contains(formattingElementEntry.element)) {
1014
+ p.activeFormattingElements.removeEntry(formattingElementEntry);
1015
+ formattingElementEntry = null;
1016
+ }
1017
+ else if (!p.openElements.hasInScope(token.tagID)) {
1018
+ formattingElementEntry = null;
1019
+ }
1020
+ }
1021
+ else {
1022
+ genericEndTagInBody(p, token);
1023
+ }
1024
+ return formattingElementEntry;
1025
+ }
1026
+ //Steps 9 and 10 of the algorithm
1027
+ function aaObtainFurthestBlock(p, formattingElementEntry) {
1028
+ let furthestBlock = null;
1029
+ let idx = p.openElements.stackTop;
1030
+ for (; idx >= 0; idx--) {
1031
+ const element = p.openElements.items[idx];
1032
+ if (element === formattingElementEntry.element) {
1033
+ break;
1034
+ }
1035
+ if (p._isSpecialElement(element, p.openElements.tagIDs[idx])) {
1036
+ furthestBlock = element;
1037
+ }
1038
+ }
1039
+ if (!furthestBlock) {
1040
+ p.openElements.shortenToLength(idx < 0 ? 0 : idx);
1041
+ p.activeFormattingElements.removeEntry(formattingElementEntry);
1042
+ }
1043
+ return furthestBlock;
1044
+ }
1045
+ //Step 13 of the algorithm
1046
+ function aaInnerLoop(p, furthestBlock, formattingElement) {
1047
+ let lastElement = furthestBlock;
1048
+ let nextElement = p.openElements.getCommonAncestor(furthestBlock);
1049
+ for (let i = 0, element = nextElement; element !== formattingElement; i++, element = nextElement) {
1050
+ //NOTE: store the next element for the next loop iteration (it may be deleted from the stack by step 9.5)
1051
+ nextElement = p.openElements.getCommonAncestor(element);
1052
+ const elementEntry = p.activeFormattingElements.getElementEntry(element);
1053
+ const counterOverflow = elementEntry && i >= AA_INNER_LOOP_ITER;
1054
+ const shouldRemoveFromOpenElements = !elementEntry || counterOverflow;
1055
+ if (shouldRemoveFromOpenElements) {
1056
+ if (counterOverflow) {
1057
+ p.activeFormattingElements.removeEntry(elementEntry);
1058
+ }
1059
+ p.openElements.remove(element);
1060
+ }
1061
+ else {
1062
+ element = aaRecreateElementFromEntry(p, elementEntry);
1063
+ if (lastElement === furthestBlock) {
1064
+ p.activeFormattingElements.bookmark = elementEntry;
1065
+ }
1066
+ p.treeAdapter.detachNode(lastElement);
1067
+ p.treeAdapter.appendChild(element, lastElement);
1068
+ lastElement = element;
1069
+ }
1070
+ }
1071
+ return lastElement;
1072
+ }
1073
+ //Step 13.7 of the algorithm
1074
+ function aaRecreateElementFromEntry(p, elementEntry) {
1075
+ const ns = p.treeAdapter.getNamespaceURI(elementEntry.element);
1076
+ const newElement = p.treeAdapter.createElement(elementEntry.token.tagName, ns, elementEntry.token.attrs);
1077
+ p.openElements.replace(elementEntry.element, newElement);
1078
+ elementEntry.element = newElement;
1079
+ return newElement;
1080
+ }
1081
+ //Step 14 of the algorithm
1082
+ function aaInsertLastNodeInCommonAncestor(p, commonAncestor, lastElement) {
1083
+ const tn = p.treeAdapter.getTagName(commonAncestor);
1084
+ const tid = (0, html_js_1.getTagID)(tn);
1085
+ if (p._isElementCausesFosterParenting(tid)) {
1086
+ p._fosterParentElement(lastElement);
1087
+ }
1088
+ else {
1089
+ const ns = p.treeAdapter.getNamespaceURI(commonAncestor);
1090
+ if (tid === html_js_1.TAG_ID.TEMPLATE && ns === html_js_1.NS.HTML) {
1091
+ commonAncestor = p.treeAdapter.getTemplateContent(commonAncestor);
1092
+ }
1093
+ p.treeAdapter.appendChild(commonAncestor, lastElement);
1094
+ }
1095
+ }
1096
+ //Steps 15-19 of the algorithm
1097
+ function aaReplaceFormattingElement(p, furthestBlock, formattingElementEntry) {
1098
+ const ns = p.treeAdapter.getNamespaceURI(formattingElementEntry.element);
1099
+ const { token } = formattingElementEntry;
1100
+ const newElement = p.treeAdapter.createElement(token.tagName, ns, token.attrs);
1101
+ p._adoptNodes(furthestBlock, newElement);
1102
+ p.treeAdapter.appendChild(furthestBlock, newElement);
1103
+ p.activeFormattingElements.insertElementAfterBookmark(newElement, token);
1104
+ p.activeFormattingElements.removeEntry(formattingElementEntry);
1105
+ p.openElements.remove(formattingElementEntry.element);
1106
+ p.openElements.insertAfter(furthestBlock, newElement, token.tagID);
1107
+ }
1108
+ //Algorithm entry point
1109
+ function callAdoptionAgency(p, token) {
1110
+ for (let i = 0; i < AA_OUTER_LOOP_ITER; i++) {
1111
+ const formattingElementEntry = aaObtainFormattingElementEntry(p, token);
1112
+ if (!formattingElementEntry) {
1113
+ break;
1114
+ }
1115
+ const furthestBlock = aaObtainFurthestBlock(p, formattingElementEntry);
1116
+ if (!furthestBlock) {
1117
+ break;
1118
+ }
1119
+ p.activeFormattingElements.bookmark = formattingElementEntry;
1120
+ const lastElement = aaInnerLoop(p, furthestBlock, formattingElementEntry.element);
1121
+ const commonAncestor = p.openElements.getCommonAncestor(formattingElementEntry.element);
1122
+ p.treeAdapter.detachNode(lastElement);
1123
+ if (commonAncestor)
1124
+ aaInsertLastNodeInCommonAncestor(p, commonAncestor, lastElement);
1125
+ aaReplaceFormattingElement(p, furthestBlock, formattingElementEntry);
1126
+ }
1127
+ }
1128
+ //Generic token handlers
1129
+ //------------------------------------------------------------------
1130
+ function appendComment(p, token) {
1131
+ p._appendCommentNode(token, p.openElements.currentTmplContentOrNode);
1132
+ }
1133
+ function appendCommentToRootHtmlElement(p, token) {
1134
+ p._appendCommentNode(token, p.openElements.items[0]);
1135
+ }
1136
+ function appendCommentToDocument(p, token) {
1137
+ p._appendCommentNode(token, p.document);
1138
+ }
1139
+ function stopParsing(p, token) {
1140
+ p.stopped = true;
1141
+ // NOTE: Set end locations for elements that remain on the open element stack.
1142
+ if (token.location) {
1143
+ // NOTE: If we are not in a fragment, `html` and `body` will stay on the stack.
1144
+ // This is a problem, as we might overwrite their end position here.
1145
+ const target = p.fragmentContext ? 0 : 2;
1146
+ for (let i = p.openElements.stackTop; i >= target; i--) {
1147
+ p._setEndLocation(p.openElements.items[i], token);
1148
+ }
1149
+ // Handle `html` and `body`
1150
+ if (!p.fragmentContext && p.openElements.stackTop >= 0) {
1151
+ const htmlElement = p.openElements.items[0];
1152
+ const htmlLocation = p.treeAdapter.getNodeSourceCodeLocation(htmlElement);
1153
+ if (htmlLocation && !htmlLocation.endTag) {
1154
+ p._setEndLocation(htmlElement, token);
1155
+ if (p.openElements.stackTop >= 1) {
1156
+ const bodyElement = p.openElements.items[1];
1157
+ const bodyLocation = p.treeAdapter.getNodeSourceCodeLocation(bodyElement);
1158
+ if (bodyLocation && !bodyLocation.endTag) {
1159
+ p._setEndLocation(bodyElement, token);
1160
+ }
1161
+ }
1162
+ }
1163
+ }
1164
+ }
1165
+ }
1166
+ // The "initial" insertion mode
1167
+ //------------------------------------------------------------------
1168
+ function doctypeInInitialMode(p, token) {
1169
+ p._setDocumentType(token);
1170
+ const mode = token.forceQuirks ? html_js_1.DOCUMENT_MODE.QUIRKS : doctype.getDocumentMode(token);
1171
+ if (!doctype.isConforming(token)) {
1172
+ p._err(token, error_codes_js_1.ERR.nonConformingDoctype);
1173
+ }
1174
+ p.treeAdapter.setDocumentMode(p.document, mode);
1175
+ p.insertionMode = InsertionMode.BEFORE_HTML;
1176
+ }
1177
+ function tokenInInitialMode(p, token) {
1178
+ p._err(token, error_codes_js_1.ERR.missingDoctype, true);
1179
+ p.treeAdapter.setDocumentMode(p.document, html_js_1.DOCUMENT_MODE.QUIRKS);
1180
+ p.insertionMode = InsertionMode.BEFORE_HTML;
1181
+ p._processToken(token);
1182
+ }
1183
+ // The "before html" insertion mode
1184
+ //------------------------------------------------------------------
1185
+ function startTagBeforeHtml(p, token) {
1186
+ if (token.tagID === html_js_1.TAG_ID.HTML) {
1187
+ p._insertElement(token, html_js_1.NS.HTML);
1188
+ p.insertionMode = InsertionMode.BEFORE_HEAD;
1189
+ }
1190
+ else {
1191
+ tokenBeforeHtml(p, token);
1192
+ }
1193
+ }
1194
+ function endTagBeforeHtml(p, token) {
1195
+ const tn = token.tagID;
1196
+ if (tn === html_js_1.TAG_ID.HTML || tn === html_js_1.TAG_ID.HEAD || tn === html_js_1.TAG_ID.BODY || tn === html_js_1.TAG_ID.BR) {
1197
+ tokenBeforeHtml(p, token);
1198
+ }
1199
+ }
1200
+ function tokenBeforeHtml(p, token) {
1201
+ p._insertFakeRootElement();
1202
+ p.insertionMode = InsertionMode.BEFORE_HEAD;
1203
+ p._processToken(token);
1204
+ }
1205
+ // The "before head" insertion mode
1206
+ //------------------------------------------------------------------
1207
+ function startTagBeforeHead(p, token) {
1208
+ switch (token.tagID) {
1209
+ case html_js_1.TAG_ID.HTML: {
1210
+ startTagInBody(p, token);
1211
+ break;
1212
+ }
1213
+ case html_js_1.TAG_ID.HEAD: {
1214
+ p._insertElement(token, html_js_1.NS.HTML);
1215
+ p.headElement = p.openElements.current;
1216
+ p.insertionMode = InsertionMode.IN_HEAD;
1217
+ break;
1218
+ }
1219
+ default: {
1220
+ tokenBeforeHead(p, token);
1221
+ }
1222
+ }
1223
+ }
1224
+ function endTagBeforeHead(p, token) {
1225
+ const tn = token.tagID;
1226
+ if (tn === html_js_1.TAG_ID.HEAD || tn === html_js_1.TAG_ID.BODY || tn === html_js_1.TAG_ID.HTML || tn === html_js_1.TAG_ID.BR) {
1227
+ tokenBeforeHead(p, token);
1228
+ }
1229
+ else {
1230
+ p._err(token, error_codes_js_1.ERR.endTagWithoutMatchingOpenElement);
1231
+ }
1232
+ }
1233
+ function tokenBeforeHead(p, token) {
1234
+ p._insertFakeElement(html_js_1.TAG_NAMES.HEAD, html_js_1.TAG_ID.HEAD);
1235
+ p.headElement = p.openElements.current;
1236
+ p.insertionMode = InsertionMode.IN_HEAD;
1237
+ p._processToken(token);
1238
+ }
1239
+ // The "in head" insertion mode
1240
+ //------------------------------------------------------------------
1241
+ function startTagInHead(p, token) {
1242
+ switch (token.tagID) {
1243
+ case html_js_1.TAG_ID.HTML: {
1244
+ startTagInBody(p, token);
1245
+ break;
1246
+ }
1247
+ case html_js_1.TAG_ID.BASE:
1248
+ case html_js_1.TAG_ID.BASEFONT:
1249
+ case html_js_1.TAG_ID.BGSOUND:
1250
+ case html_js_1.TAG_ID.LINK:
1251
+ case html_js_1.TAG_ID.META: {
1252
+ p._appendElement(token, html_js_1.NS.HTML);
1253
+ token.ackSelfClosing = true;
1254
+ break;
1255
+ }
1256
+ case html_js_1.TAG_ID.TITLE: {
1257
+ p._switchToTextParsing(token, index_js_1.TokenizerMode.RCDATA);
1258
+ break;
1259
+ }
1260
+ case html_js_1.TAG_ID.NOSCRIPT: {
1261
+ if (p.options.scriptingEnabled) {
1262
+ p._switchToTextParsing(token, index_js_1.TokenizerMode.RAWTEXT);
1263
+ }
1264
+ else {
1265
+ p._insertElement(token, html_js_1.NS.HTML);
1266
+ p.insertionMode = InsertionMode.IN_HEAD_NO_SCRIPT;
1267
+ }
1268
+ break;
1269
+ }
1270
+ case html_js_1.TAG_ID.NOFRAMES:
1271
+ case html_js_1.TAG_ID.STYLE: {
1272
+ p._switchToTextParsing(token, index_js_1.TokenizerMode.RAWTEXT);
1273
+ break;
1274
+ }
1275
+ case html_js_1.TAG_ID.SCRIPT: {
1276
+ p._switchToTextParsing(token, index_js_1.TokenizerMode.SCRIPT_DATA);
1277
+ break;
1278
+ }
1279
+ case html_js_1.TAG_ID.TEMPLATE: {
1280
+ p._insertTemplate(token);
1281
+ p.activeFormattingElements.insertMarker();
1282
+ p.framesetOk = false;
1283
+ p.insertionMode = InsertionMode.IN_TEMPLATE;
1284
+ p.tmplInsertionModeStack.unshift(InsertionMode.IN_TEMPLATE);
1285
+ break;
1286
+ }
1287
+ case html_js_1.TAG_ID.HEAD: {
1288
+ p._err(token, error_codes_js_1.ERR.misplacedStartTagForHeadElement);
1289
+ break;
1290
+ }
1291
+ default: {
1292
+ tokenInHead(p, token);
1293
+ }
1294
+ }
1295
+ }
1296
+ function endTagInHead(p, token) {
1297
+ switch (token.tagID) {
1298
+ case html_js_1.TAG_ID.HEAD: {
1299
+ p.openElements.pop();
1300
+ p.insertionMode = InsertionMode.AFTER_HEAD;
1301
+ break;
1302
+ }
1303
+ case html_js_1.TAG_ID.BODY:
1304
+ case html_js_1.TAG_ID.BR:
1305
+ case html_js_1.TAG_ID.HTML: {
1306
+ tokenInHead(p, token);
1307
+ break;
1308
+ }
1309
+ case html_js_1.TAG_ID.TEMPLATE: {
1310
+ templateEndTagInHead(p, token);
1311
+ break;
1312
+ }
1313
+ default: {
1314
+ p._err(token, error_codes_js_1.ERR.endTagWithoutMatchingOpenElement);
1315
+ }
1316
+ }
1317
+ }
1318
+ function templateEndTagInHead(p, token) {
1319
+ if (p.openElements.tmplCount > 0) {
1320
+ p.openElements.generateImpliedEndTagsThoroughly();
1321
+ if (p.openElements.currentTagId !== html_js_1.TAG_ID.TEMPLATE) {
1322
+ p._err(token, error_codes_js_1.ERR.closingOfElementWithOpenChildElements);
1323
+ }
1324
+ p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.TEMPLATE);
1325
+ p.activeFormattingElements.clearToLastMarker();
1326
+ p.tmplInsertionModeStack.shift();
1327
+ p._resetInsertionMode();
1328
+ }
1329
+ else {
1330
+ p._err(token, error_codes_js_1.ERR.endTagWithoutMatchingOpenElement);
1331
+ }
1332
+ }
1333
+ function tokenInHead(p, token) {
1334
+ p.openElements.pop();
1335
+ p.insertionMode = InsertionMode.AFTER_HEAD;
1336
+ p._processToken(token);
1337
+ }
1338
+ // The "in head no script" insertion mode
1339
+ //------------------------------------------------------------------
1340
+ function startTagInHeadNoScript(p, token) {
1341
+ switch (token.tagID) {
1342
+ case html_js_1.TAG_ID.HTML: {
1343
+ startTagInBody(p, token);
1344
+ break;
1345
+ }
1346
+ case html_js_1.TAG_ID.BASEFONT:
1347
+ case html_js_1.TAG_ID.BGSOUND:
1348
+ case html_js_1.TAG_ID.HEAD:
1349
+ case html_js_1.TAG_ID.LINK:
1350
+ case html_js_1.TAG_ID.META:
1351
+ case html_js_1.TAG_ID.NOFRAMES:
1352
+ case html_js_1.TAG_ID.STYLE: {
1353
+ startTagInHead(p, token);
1354
+ break;
1355
+ }
1356
+ case html_js_1.TAG_ID.NOSCRIPT: {
1357
+ p._err(token, error_codes_js_1.ERR.nestedNoscriptInHead);
1358
+ break;
1359
+ }
1360
+ default: {
1361
+ tokenInHeadNoScript(p, token);
1362
+ }
1363
+ }
1364
+ }
1365
+ function endTagInHeadNoScript(p, token) {
1366
+ switch (token.tagID) {
1367
+ case html_js_1.TAG_ID.NOSCRIPT: {
1368
+ p.openElements.pop();
1369
+ p.insertionMode = InsertionMode.IN_HEAD;
1370
+ break;
1371
+ }
1372
+ case html_js_1.TAG_ID.BR: {
1373
+ tokenInHeadNoScript(p, token);
1374
+ break;
1375
+ }
1376
+ default: {
1377
+ p._err(token, error_codes_js_1.ERR.endTagWithoutMatchingOpenElement);
1378
+ }
1379
+ }
1380
+ }
1381
+ function tokenInHeadNoScript(p, token) {
1382
+ const errCode = token.type === token_js_1.TokenType.EOF ? error_codes_js_1.ERR.openElementsLeftAfterEof : error_codes_js_1.ERR.disallowedContentInNoscriptInHead;
1383
+ p._err(token, errCode);
1384
+ p.openElements.pop();
1385
+ p.insertionMode = InsertionMode.IN_HEAD;
1386
+ p._processToken(token);
1387
+ }
1388
+ // The "after head" insertion mode
1389
+ //------------------------------------------------------------------
1390
+ function startTagAfterHead(p, token) {
1391
+ switch (token.tagID) {
1392
+ case html_js_1.TAG_ID.HTML: {
1393
+ startTagInBody(p, token);
1394
+ break;
1395
+ }
1396
+ case html_js_1.TAG_ID.BODY: {
1397
+ p._insertElement(token, html_js_1.NS.HTML);
1398
+ p.framesetOk = false;
1399
+ p.insertionMode = InsertionMode.IN_BODY;
1400
+ break;
1401
+ }
1402
+ case html_js_1.TAG_ID.FRAMESET: {
1403
+ p._insertElement(token, html_js_1.NS.HTML);
1404
+ p.insertionMode = InsertionMode.IN_FRAMESET;
1405
+ break;
1406
+ }
1407
+ case html_js_1.TAG_ID.BASE:
1408
+ case html_js_1.TAG_ID.BASEFONT:
1409
+ case html_js_1.TAG_ID.BGSOUND:
1410
+ case html_js_1.TAG_ID.LINK:
1411
+ case html_js_1.TAG_ID.META:
1412
+ case html_js_1.TAG_ID.NOFRAMES:
1413
+ case html_js_1.TAG_ID.SCRIPT:
1414
+ case html_js_1.TAG_ID.STYLE:
1415
+ case html_js_1.TAG_ID.TEMPLATE:
1416
+ case html_js_1.TAG_ID.TITLE: {
1417
+ p._err(token, error_codes_js_1.ERR.abandonedHeadElementChild);
1418
+ p.openElements.push(p.headElement, html_js_1.TAG_ID.HEAD);
1419
+ startTagInHead(p, token);
1420
+ p.openElements.remove(p.headElement);
1421
+ break;
1422
+ }
1423
+ case html_js_1.TAG_ID.HEAD: {
1424
+ p._err(token, error_codes_js_1.ERR.misplacedStartTagForHeadElement);
1425
+ break;
1426
+ }
1427
+ default: {
1428
+ tokenAfterHead(p, token);
1429
+ }
1430
+ }
1431
+ }
1432
+ function endTagAfterHead(p, token) {
1433
+ switch (token.tagID) {
1434
+ case html_js_1.TAG_ID.BODY:
1435
+ case html_js_1.TAG_ID.HTML:
1436
+ case html_js_1.TAG_ID.BR: {
1437
+ tokenAfterHead(p, token);
1438
+ break;
1439
+ }
1440
+ case html_js_1.TAG_ID.TEMPLATE: {
1441
+ templateEndTagInHead(p, token);
1442
+ break;
1443
+ }
1444
+ default: {
1445
+ p._err(token, error_codes_js_1.ERR.endTagWithoutMatchingOpenElement);
1446
+ }
1447
+ }
1448
+ }
1449
+ function tokenAfterHead(p, token) {
1450
+ p._insertFakeElement(html_js_1.TAG_NAMES.BODY, html_js_1.TAG_ID.BODY);
1451
+ p.insertionMode = InsertionMode.IN_BODY;
1452
+ modeInBody(p, token);
1453
+ }
1454
+ // The "in body" insertion mode
1455
+ //------------------------------------------------------------------
1456
+ function modeInBody(p, token) {
1457
+ switch (token.type) {
1458
+ case token_js_1.TokenType.CHARACTER: {
1459
+ characterInBody(p, token);
1460
+ break;
1461
+ }
1462
+ case token_js_1.TokenType.WHITESPACE_CHARACTER: {
1463
+ whitespaceCharacterInBody(p, token);
1464
+ break;
1465
+ }
1466
+ case token_js_1.TokenType.COMMENT: {
1467
+ appendComment(p, token);
1468
+ break;
1469
+ }
1470
+ case token_js_1.TokenType.START_TAG: {
1471
+ startTagInBody(p, token);
1472
+ break;
1473
+ }
1474
+ case token_js_1.TokenType.END_TAG: {
1475
+ endTagInBody(p, token);
1476
+ break;
1477
+ }
1478
+ case token_js_1.TokenType.EOF: {
1479
+ eofInBody(p, token);
1480
+ break;
1481
+ }
1482
+ default:
1483
+ // Do nothing
1484
+ }
1485
+ }
1486
+ function whitespaceCharacterInBody(p, token) {
1487
+ p._reconstructActiveFormattingElements();
1488
+ p._insertCharacters(token);
1489
+ }
1490
+ function characterInBody(p, token) {
1491
+ p._reconstructActiveFormattingElements();
1492
+ p._insertCharacters(token);
1493
+ p.framesetOk = false;
1494
+ }
1495
+ function htmlStartTagInBody(p, token) {
1496
+ if (p.openElements.tmplCount === 0) {
1497
+ p.treeAdapter.adoptAttributes(p.openElements.items[0], token.attrs);
1498
+ }
1499
+ }
1500
+ function bodyStartTagInBody(p, token) {
1501
+ const bodyElement = p.openElements.tryPeekProperlyNestedBodyElement();
1502
+ if (bodyElement && p.openElements.tmplCount === 0) {
1503
+ p.framesetOk = false;
1504
+ p.treeAdapter.adoptAttributes(bodyElement, token.attrs);
1505
+ }
1506
+ }
1507
+ function framesetStartTagInBody(p, token) {
1508
+ const bodyElement = p.openElements.tryPeekProperlyNestedBodyElement();
1509
+ if (p.framesetOk && bodyElement) {
1510
+ p.treeAdapter.detachNode(bodyElement);
1511
+ p.openElements.popAllUpToHtmlElement();
1512
+ p._insertElement(token, html_js_1.NS.HTML);
1513
+ p.insertionMode = InsertionMode.IN_FRAMESET;
1514
+ }
1515
+ }
1516
+ function addressStartTagInBody(p, token) {
1517
+ if (p.openElements.hasInButtonScope(html_js_1.TAG_ID.P)) {
1518
+ p._closePElement();
1519
+ }
1520
+ p._insertElement(token, html_js_1.NS.HTML);
1521
+ }
1522
+ function numberedHeaderStartTagInBody(p, token) {
1523
+ if (p.openElements.hasInButtonScope(html_js_1.TAG_ID.P)) {
1524
+ p._closePElement();
1525
+ }
1526
+ if ((0, html_js_1.isNumberedHeader)(p.openElements.currentTagId)) {
1527
+ p.openElements.pop();
1528
+ }
1529
+ p._insertElement(token, html_js_1.NS.HTML);
1530
+ }
1531
+ function preStartTagInBody(p, token) {
1532
+ if (p.openElements.hasInButtonScope(html_js_1.TAG_ID.P)) {
1533
+ p._closePElement();
1534
+ }
1535
+ p._insertElement(token, html_js_1.NS.HTML);
1536
+ //NOTE: If the next token is a U+000A LINE FEED (LF) character token, then ignore that token and move
1537
+ //on to the next one. (Newlines at the start of pre blocks are ignored as an authoring convenience.)
1538
+ p.skipNextNewLine = true;
1539
+ p.framesetOk = false;
1540
+ }
1541
+ function formStartTagInBody(p, token) {
1542
+ const inTemplate = p.openElements.tmplCount > 0;
1543
+ if (!p.formElement || inTemplate) {
1544
+ if (p.openElements.hasInButtonScope(html_js_1.TAG_ID.P)) {
1545
+ p._closePElement();
1546
+ }
1547
+ p._insertElement(token, html_js_1.NS.HTML);
1548
+ if (!inTemplate) {
1549
+ p.formElement = p.openElements.current;
1550
+ }
1551
+ }
1552
+ }
1553
+ function listItemStartTagInBody(p, token) {
1554
+ p.framesetOk = false;
1555
+ const tn = token.tagID;
1556
+ for (let i = p.openElements.stackTop; i >= 0; i--) {
1557
+ const elementId = p.openElements.tagIDs[i];
1558
+ if ((tn === html_js_1.TAG_ID.LI && elementId === html_js_1.TAG_ID.LI) ||
1559
+ ((tn === html_js_1.TAG_ID.DD || tn === html_js_1.TAG_ID.DT) && (elementId === html_js_1.TAG_ID.DD || elementId === html_js_1.TAG_ID.DT))) {
1560
+ p.openElements.generateImpliedEndTagsWithExclusion(elementId);
1561
+ p.openElements.popUntilTagNamePopped(elementId);
1562
+ break;
1563
+ }
1564
+ if (elementId !== html_js_1.TAG_ID.ADDRESS &&
1565
+ elementId !== html_js_1.TAG_ID.DIV &&
1566
+ elementId !== html_js_1.TAG_ID.P &&
1567
+ p._isSpecialElement(p.openElements.items[i], elementId)) {
1568
+ break;
1569
+ }
1570
+ }
1571
+ if (p.openElements.hasInButtonScope(html_js_1.TAG_ID.P)) {
1572
+ p._closePElement();
1573
+ }
1574
+ p._insertElement(token, html_js_1.NS.HTML);
1575
+ }
1576
+ function plaintextStartTagInBody(p, token) {
1577
+ if (p.openElements.hasInButtonScope(html_js_1.TAG_ID.P)) {
1578
+ p._closePElement();
1579
+ }
1580
+ p._insertElement(token, html_js_1.NS.HTML);
1581
+ p.tokenizer.state = index_js_1.TokenizerMode.PLAINTEXT;
1582
+ }
1583
+ function buttonStartTagInBody(p, token) {
1584
+ if (p.openElements.hasInScope(html_js_1.TAG_ID.BUTTON)) {
1585
+ p.openElements.generateImpliedEndTags();
1586
+ p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.BUTTON);
1587
+ }
1588
+ p._reconstructActiveFormattingElements();
1589
+ p._insertElement(token, html_js_1.NS.HTML);
1590
+ p.framesetOk = false;
1591
+ }
1592
+ function aStartTagInBody(p, token) {
1593
+ const activeElementEntry = p.activeFormattingElements.getElementEntryInScopeWithTagName(html_js_1.TAG_NAMES.A);
1594
+ if (activeElementEntry) {
1595
+ callAdoptionAgency(p, token);
1596
+ p.openElements.remove(activeElementEntry.element);
1597
+ p.activeFormattingElements.removeEntry(activeElementEntry);
1598
+ }
1599
+ p._reconstructActiveFormattingElements();
1600
+ p._insertElement(token, html_js_1.NS.HTML);
1601
+ p.activeFormattingElements.pushElement(p.openElements.current, token);
1602
+ }
1603
+ function bStartTagInBody(p, token) {
1604
+ p._reconstructActiveFormattingElements();
1605
+ p._insertElement(token, html_js_1.NS.HTML);
1606
+ p.activeFormattingElements.pushElement(p.openElements.current, token);
1607
+ }
1608
+ function nobrStartTagInBody(p, token) {
1609
+ p._reconstructActiveFormattingElements();
1610
+ if (p.openElements.hasInScope(html_js_1.TAG_ID.NOBR)) {
1611
+ callAdoptionAgency(p, token);
1612
+ p._reconstructActiveFormattingElements();
1613
+ }
1614
+ p._insertElement(token, html_js_1.NS.HTML);
1615
+ p.activeFormattingElements.pushElement(p.openElements.current, token);
1616
+ }
1617
+ function appletStartTagInBody(p, token) {
1618
+ p._reconstructActiveFormattingElements();
1619
+ p._insertElement(token, html_js_1.NS.HTML);
1620
+ p.activeFormattingElements.insertMarker();
1621
+ p.framesetOk = false;
1622
+ }
1623
+ function tableStartTagInBody(p, token) {
1624
+ if (p.treeAdapter.getDocumentMode(p.document) !== html_js_1.DOCUMENT_MODE.QUIRKS && p.openElements.hasInButtonScope(html_js_1.TAG_ID.P)) {
1625
+ p._closePElement();
1626
+ }
1627
+ p._insertElement(token, html_js_1.NS.HTML);
1628
+ p.framesetOk = false;
1629
+ p.insertionMode = InsertionMode.IN_TABLE;
1630
+ }
1631
+ function areaStartTagInBody(p, token) {
1632
+ p._reconstructActiveFormattingElements();
1633
+ p._appendElement(token, html_js_1.NS.HTML);
1634
+ p.framesetOk = false;
1635
+ token.ackSelfClosing = true;
1636
+ }
1637
+ function isHiddenInput(token) {
1638
+ const inputType = (0, token_js_1.getTokenAttr)(token, html_js_1.ATTRS.TYPE);
1639
+ return inputType != null && inputType.toLowerCase() === HIDDEN_INPUT_TYPE;
1640
+ }
1641
+ function inputStartTagInBody(p, token) {
1642
+ p._reconstructActiveFormattingElements();
1643
+ p._appendElement(token, html_js_1.NS.HTML);
1644
+ if (!isHiddenInput(token)) {
1645
+ p.framesetOk = false;
1646
+ }
1647
+ token.ackSelfClosing = true;
1648
+ }
1649
+ function paramStartTagInBody(p, token) {
1650
+ p._appendElement(token, html_js_1.NS.HTML);
1651
+ token.ackSelfClosing = true;
1652
+ }
1653
+ function hrStartTagInBody(p, token) {
1654
+ if (p.openElements.hasInButtonScope(html_js_1.TAG_ID.P)) {
1655
+ p._closePElement();
1656
+ }
1657
+ p._appendElement(token, html_js_1.NS.HTML);
1658
+ p.framesetOk = false;
1659
+ token.ackSelfClosing = true;
1660
+ }
1661
+ function imageStartTagInBody(p, token) {
1662
+ token.tagName = html_js_1.TAG_NAMES.IMG;
1663
+ token.tagID = html_js_1.TAG_ID.IMG;
1664
+ areaStartTagInBody(p, token);
1665
+ }
1666
+ function textareaStartTagInBody(p, token) {
1667
+ p._insertElement(token, html_js_1.NS.HTML);
1668
+ //NOTE: If the next token is a U+000A LINE FEED (LF) character token, then ignore that token and move
1669
+ //on to the next one. (Newlines at the start of textarea elements are ignored as an authoring convenience.)
1670
+ p.skipNextNewLine = true;
1671
+ p.tokenizer.state = index_js_1.TokenizerMode.RCDATA;
1672
+ p.originalInsertionMode = p.insertionMode;
1673
+ p.framesetOk = false;
1674
+ p.insertionMode = InsertionMode.TEXT;
1675
+ }
1676
+ function xmpStartTagInBody(p, token) {
1677
+ if (p.openElements.hasInButtonScope(html_js_1.TAG_ID.P)) {
1678
+ p._closePElement();
1679
+ }
1680
+ p._reconstructActiveFormattingElements();
1681
+ p.framesetOk = false;
1682
+ p._switchToTextParsing(token, index_js_1.TokenizerMode.RAWTEXT);
1683
+ }
1684
+ function iframeStartTagInBody(p, token) {
1685
+ p.framesetOk = false;
1686
+ p._switchToTextParsing(token, index_js_1.TokenizerMode.RAWTEXT);
1687
+ }
1688
+ //NOTE: here we assume that we always act as an user agent with enabled plugins, so we parse
1689
+ //<noembed> as rawtext.
1690
+ function noembedStartTagInBody(p, token) {
1691
+ p._switchToTextParsing(token, index_js_1.TokenizerMode.RAWTEXT);
1692
+ }
1693
+ function selectStartTagInBody(p, token) {
1694
+ p._reconstructActiveFormattingElements();
1695
+ p._insertElement(token, html_js_1.NS.HTML);
1696
+ p.framesetOk = false;
1697
+ p.insertionMode =
1698
+ p.insertionMode === InsertionMode.IN_TABLE ||
1699
+ p.insertionMode === InsertionMode.IN_CAPTION ||
1700
+ p.insertionMode === InsertionMode.IN_TABLE_BODY ||
1701
+ p.insertionMode === InsertionMode.IN_ROW ||
1702
+ p.insertionMode === InsertionMode.IN_CELL
1703
+ ? InsertionMode.IN_SELECT_IN_TABLE
1704
+ : InsertionMode.IN_SELECT;
1705
+ }
1706
+ function optgroupStartTagInBody(p, token) {
1707
+ if (p.openElements.currentTagId === html_js_1.TAG_ID.OPTION) {
1708
+ p.openElements.pop();
1709
+ }
1710
+ p._reconstructActiveFormattingElements();
1711
+ p._insertElement(token, html_js_1.NS.HTML);
1712
+ }
1713
+ function rbStartTagInBody(p, token) {
1714
+ if (p.openElements.hasInScope(html_js_1.TAG_ID.RUBY)) {
1715
+ p.openElements.generateImpliedEndTags();
1716
+ }
1717
+ p._insertElement(token, html_js_1.NS.HTML);
1718
+ }
1719
+ function rtStartTagInBody(p, token) {
1720
+ if (p.openElements.hasInScope(html_js_1.TAG_ID.RUBY)) {
1721
+ p.openElements.generateImpliedEndTagsWithExclusion(html_js_1.TAG_ID.RTC);
1722
+ }
1723
+ p._insertElement(token, html_js_1.NS.HTML);
1724
+ }
1725
+ function mathStartTagInBody(p, token) {
1726
+ p._reconstructActiveFormattingElements();
1727
+ foreignContent.adjustTokenMathMLAttrs(token);
1728
+ foreignContent.adjustTokenXMLAttrs(token);
1729
+ if (token.selfClosing) {
1730
+ p._appendElement(token, html_js_1.NS.MATHML);
1731
+ }
1732
+ else {
1733
+ p._insertElement(token, html_js_1.NS.MATHML);
1734
+ }
1735
+ token.ackSelfClosing = true;
1736
+ }
1737
+ function svgStartTagInBody(p, token) {
1738
+ p._reconstructActiveFormattingElements();
1739
+ foreignContent.adjustTokenSVGAttrs(token);
1740
+ foreignContent.adjustTokenXMLAttrs(token);
1741
+ if (token.selfClosing) {
1742
+ p._appendElement(token, html_js_1.NS.SVG);
1743
+ }
1744
+ else {
1745
+ p._insertElement(token, html_js_1.NS.SVG);
1746
+ }
1747
+ token.ackSelfClosing = true;
1748
+ }
1749
+ function genericStartTagInBody(p, token) {
1750
+ p._reconstructActiveFormattingElements();
1751
+ p._insertElement(token, html_js_1.NS.HTML);
1752
+ }
1753
+ function startTagInBody(p, token) {
1754
+ switch (token.tagID) {
1755
+ case html_js_1.TAG_ID.I:
1756
+ case html_js_1.TAG_ID.S:
1757
+ case html_js_1.TAG_ID.B:
1758
+ case html_js_1.TAG_ID.U:
1759
+ case html_js_1.TAG_ID.EM:
1760
+ case html_js_1.TAG_ID.TT:
1761
+ case html_js_1.TAG_ID.BIG:
1762
+ case html_js_1.TAG_ID.CODE:
1763
+ case html_js_1.TAG_ID.FONT:
1764
+ case html_js_1.TAG_ID.SMALL:
1765
+ case html_js_1.TAG_ID.STRIKE:
1766
+ case html_js_1.TAG_ID.STRONG: {
1767
+ bStartTagInBody(p, token);
1768
+ break;
1769
+ }
1770
+ case html_js_1.TAG_ID.A: {
1771
+ aStartTagInBody(p, token);
1772
+ break;
1773
+ }
1774
+ case html_js_1.TAG_ID.H1:
1775
+ case html_js_1.TAG_ID.H2:
1776
+ case html_js_1.TAG_ID.H3:
1777
+ case html_js_1.TAG_ID.H4:
1778
+ case html_js_1.TAG_ID.H5:
1779
+ case html_js_1.TAG_ID.H6: {
1780
+ numberedHeaderStartTagInBody(p, token);
1781
+ break;
1782
+ }
1783
+ case html_js_1.TAG_ID.P:
1784
+ case html_js_1.TAG_ID.DL:
1785
+ case html_js_1.TAG_ID.OL:
1786
+ case html_js_1.TAG_ID.UL:
1787
+ case html_js_1.TAG_ID.DIV:
1788
+ case html_js_1.TAG_ID.DIR:
1789
+ case html_js_1.TAG_ID.NAV:
1790
+ case html_js_1.TAG_ID.MAIN:
1791
+ case html_js_1.TAG_ID.MENU:
1792
+ case html_js_1.TAG_ID.ASIDE:
1793
+ case html_js_1.TAG_ID.CENTER:
1794
+ case html_js_1.TAG_ID.FIGURE:
1795
+ case html_js_1.TAG_ID.FOOTER:
1796
+ case html_js_1.TAG_ID.HEADER:
1797
+ case html_js_1.TAG_ID.HGROUP:
1798
+ case html_js_1.TAG_ID.DIALOG:
1799
+ case html_js_1.TAG_ID.DETAILS:
1800
+ case html_js_1.TAG_ID.ADDRESS:
1801
+ case html_js_1.TAG_ID.ARTICLE:
1802
+ case html_js_1.TAG_ID.SECTION:
1803
+ case html_js_1.TAG_ID.SUMMARY:
1804
+ case html_js_1.TAG_ID.FIELDSET:
1805
+ case html_js_1.TAG_ID.BLOCKQUOTE:
1806
+ case html_js_1.TAG_ID.FIGCAPTION: {
1807
+ addressStartTagInBody(p, token);
1808
+ break;
1809
+ }
1810
+ case html_js_1.TAG_ID.LI:
1811
+ case html_js_1.TAG_ID.DD:
1812
+ case html_js_1.TAG_ID.DT: {
1813
+ listItemStartTagInBody(p, token);
1814
+ break;
1815
+ }
1816
+ case html_js_1.TAG_ID.BR:
1817
+ case html_js_1.TAG_ID.IMG:
1818
+ case html_js_1.TAG_ID.WBR:
1819
+ case html_js_1.TAG_ID.AREA:
1820
+ case html_js_1.TAG_ID.EMBED:
1821
+ case html_js_1.TAG_ID.KEYGEN: {
1822
+ areaStartTagInBody(p, token);
1823
+ break;
1824
+ }
1825
+ case html_js_1.TAG_ID.HR: {
1826
+ hrStartTagInBody(p, token);
1827
+ break;
1828
+ }
1829
+ case html_js_1.TAG_ID.RB:
1830
+ case html_js_1.TAG_ID.RTC: {
1831
+ rbStartTagInBody(p, token);
1832
+ break;
1833
+ }
1834
+ case html_js_1.TAG_ID.RT:
1835
+ case html_js_1.TAG_ID.RP: {
1836
+ rtStartTagInBody(p, token);
1837
+ break;
1838
+ }
1839
+ case html_js_1.TAG_ID.PRE:
1840
+ case html_js_1.TAG_ID.LISTING: {
1841
+ preStartTagInBody(p, token);
1842
+ break;
1843
+ }
1844
+ case html_js_1.TAG_ID.XMP: {
1845
+ xmpStartTagInBody(p, token);
1846
+ break;
1847
+ }
1848
+ case html_js_1.TAG_ID.SVG: {
1849
+ svgStartTagInBody(p, token);
1850
+ break;
1851
+ }
1852
+ case html_js_1.TAG_ID.HTML: {
1853
+ htmlStartTagInBody(p, token);
1854
+ break;
1855
+ }
1856
+ case html_js_1.TAG_ID.BASE:
1857
+ case html_js_1.TAG_ID.LINK:
1858
+ case html_js_1.TAG_ID.META:
1859
+ case html_js_1.TAG_ID.STYLE:
1860
+ case html_js_1.TAG_ID.TITLE:
1861
+ case html_js_1.TAG_ID.SCRIPT:
1862
+ case html_js_1.TAG_ID.BGSOUND:
1863
+ case html_js_1.TAG_ID.BASEFONT:
1864
+ case html_js_1.TAG_ID.TEMPLATE: {
1865
+ startTagInHead(p, token);
1866
+ break;
1867
+ }
1868
+ case html_js_1.TAG_ID.BODY: {
1869
+ bodyStartTagInBody(p, token);
1870
+ break;
1871
+ }
1872
+ case html_js_1.TAG_ID.FORM: {
1873
+ formStartTagInBody(p, token);
1874
+ break;
1875
+ }
1876
+ case html_js_1.TAG_ID.NOBR: {
1877
+ nobrStartTagInBody(p, token);
1878
+ break;
1879
+ }
1880
+ case html_js_1.TAG_ID.MATH: {
1881
+ mathStartTagInBody(p, token);
1882
+ break;
1883
+ }
1884
+ case html_js_1.TAG_ID.TABLE: {
1885
+ tableStartTagInBody(p, token);
1886
+ break;
1887
+ }
1888
+ case html_js_1.TAG_ID.INPUT: {
1889
+ inputStartTagInBody(p, token);
1890
+ break;
1891
+ }
1892
+ case html_js_1.TAG_ID.PARAM:
1893
+ case html_js_1.TAG_ID.TRACK:
1894
+ case html_js_1.TAG_ID.SOURCE: {
1895
+ paramStartTagInBody(p, token);
1896
+ break;
1897
+ }
1898
+ case html_js_1.TAG_ID.IMAGE: {
1899
+ imageStartTagInBody(p, token);
1900
+ break;
1901
+ }
1902
+ case html_js_1.TAG_ID.BUTTON: {
1903
+ buttonStartTagInBody(p, token);
1904
+ break;
1905
+ }
1906
+ case html_js_1.TAG_ID.APPLET:
1907
+ case html_js_1.TAG_ID.OBJECT:
1908
+ case html_js_1.TAG_ID.MARQUEE: {
1909
+ appletStartTagInBody(p, token);
1910
+ break;
1911
+ }
1912
+ case html_js_1.TAG_ID.IFRAME: {
1913
+ iframeStartTagInBody(p, token);
1914
+ break;
1915
+ }
1916
+ case html_js_1.TAG_ID.SELECT: {
1917
+ selectStartTagInBody(p, token);
1918
+ break;
1919
+ }
1920
+ case html_js_1.TAG_ID.OPTION:
1921
+ case html_js_1.TAG_ID.OPTGROUP: {
1922
+ optgroupStartTagInBody(p, token);
1923
+ break;
1924
+ }
1925
+ case html_js_1.TAG_ID.NOEMBED: {
1926
+ noembedStartTagInBody(p, token);
1927
+ break;
1928
+ }
1929
+ case html_js_1.TAG_ID.FRAMESET: {
1930
+ framesetStartTagInBody(p, token);
1931
+ break;
1932
+ }
1933
+ case html_js_1.TAG_ID.TEXTAREA: {
1934
+ textareaStartTagInBody(p, token);
1935
+ break;
1936
+ }
1937
+ case html_js_1.TAG_ID.NOSCRIPT: {
1938
+ if (p.options.scriptingEnabled) {
1939
+ noembedStartTagInBody(p, token);
1940
+ }
1941
+ else {
1942
+ genericStartTagInBody(p, token);
1943
+ }
1944
+ break;
1945
+ }
1946
+ case html_js_1.TAG_ID.PLAINTEXT: {
1947
+ plaintextStartTagInBody(p, token);
1948
+ break;
1949
+ }
1950
+ case html_js_1.TAG_ID.COL:
1951
+ case html_js_1.TAG_ID.TH:
1952
+ case html_js_1.TAG_ID.TD:
1953
+ case html_js_1.TAG_ID.TR:
1954
+ case html_js_1.TAG_ID.HEAD:
1955
+ case html_js_1.TAG_ID.FRAME:
1956
+ case html_js_1.TAG_ID.TBODY:
1957
+ case html_js_1.TAG_ID.TFOOT:
1958
+ case html_js_1.TAG_ID.THEAD:
1959
+ case html_js_1.TAG_ID.CAPTION:
1960
+ case html_js_1.TAG_ID.COLGROUP: {
1961
+ // Ignore token
1962
+ break;
1963
+ }
1964
+ default: {
1965
+ genericStartTagInBody(p, token);
1966
+ }
1967
+ }
1968
+ }
1969
+ function bodyEndTagInBody(p, token) {
1970
+ if (p.openElements.hasInScope(html_js_1.TAG_ID.BODY)) {
1971
+ p.insertionMode = InsertionMode.AFTER_BODY;
1972
+ //NOTE: <body> is never popped from the stack, so we need to updated
1973
+ //the end location explicitly.
1974
+ if (p.options.sourceCodeLocationInfo) {
1975
+ const bodyElement = p.openElements.tryPeekProperlyNestedBodyElement();
1976
+ if (bodyElement) {
1977
+ p._setEndLocation(bodyElement, token);
1978
+ }
1979
+ }
1980
+ }
1981
+ }
1982
+ function htmlEndTagInBody(p, token) {
1983
+ if (p.openElements.hasInScope(html_js_1.TAG_ID.BODY)) {
1984
+ p.insertionMode = InsertionMode.AFTER_BODY;
1985
+ endTagAfterBody(p, token);
1986
+ }
1987
+ }
1988
+ function addressEndTagInBody(p, token) {
1989
+ const tn = token.tagID;
1990
+ if (p.openElements.hasInScope(tn)) {
1991
+ p.openElements.generateImpliedEndTags();
1992
+ p.openElements.popUntilTagNamePopped(tn);
1993
+ }
1994
+ }
1995
+ function formEndTagInBody(p) {
1996
+ const inTemplate = p.openElements.tmplCount > 0;
1997
+ const { formElement } = p;
1998
+ if (!inTemplate) {
1999
+ p.formElement = null;
2000
+ }
2001
+ if ((formElement || inTemplate) && p.openElements.hasInScope(html_js_1.TAG_ID.FORM)) {
2002
+ p.openElements.generateImpliedEndTags();
2003
+ if (inTemplate) {
2004
+ p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.FORM);
2005
+ }
2006
+ else if (formElement) {
2007
+ p.openElements.remove(formElement);
2008
+ }
2009
+ }
2010
+ }
2011
+ function pEndTagInBody(p) {
2012
+ if (!p.openElements.hasInButtonScope(html_js_1.TAG_ID.P)) {
2013
+ p._insertFakeElement(html_js_1.TAG_NAMES.P, html_js_1.TAG_ID.P);
2014
+ }
2015
+ p._closePElement();
2016
+ }
2017
+ function liEndTagInBody(p) {
2018
+ if (p.openElements.hasInListItemScope(html_js_1.TAG_ID.LI)) {
2019
+ p.openElements.generateImpliedEndTagsWithExclusion(html_js_1.TAG_ID.LI);
2020
+ p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.LI);
2021
+ }
2022
+ }
2023
+ function ddEndTagInBody(p, token) {
2024
+ const tn = token.tagID;
2025
+ if (p.openElements.hasInScope(tn)) {
2026
+ p.openElements.generateImpliedEndTagsWithExclusion(tn);
2027
+ p.openElements.popUntilTagNamePopped(tn);
2028
+ }
2029
+ }
2030
+ function numberedHeaderEndTagInBody(p) {
2031
+ if (p.openElements.hasNumberedHeaderInScope()) {
2032
+ p.openElements.generateImpliedEndTags();
2033
+ p.openElements.popUntilNumberedHeaderPopped();
2034
+ }
2035
+ }
2036
+ function appletEndTagInBody(p, token) {
2037
+ const tn = token.tagID;
2038
+ if (p.openElements.hasInScope(tn)) {
2039
+ p.openElements.generateImpliedEndTags();
2040
+ p.openElements.popUntilTagNamePopped(tn);
2041
+ p.activeFormattingElements.clearToLastMarker();
2042
+ }
2043
+ }
2044
+ function brEndTagInBody(p) {
2045
+ p._reconstructActiveFormattingElements();
2046
+ p._insertFakeElement(html_js_1.TAG_NAMES.BR, html_js_1.TAG_ID.BR);
2047
+ p.openElements.pop();
2048
+ p.framesetOk = false;
2049
+ }
2050
+ function genericEndTagInBody(p, token) {
2051
+ const tn = token.tagName;
2052
+ const tid = token.tagID;
2053
+ for (let i = p.openElements.stackTop; i > 0; i--) {
2054
+ const element = p.openElements.items[i];
2055
+ const elementId = p.openElements.tagIDs[i];
2056
+ // Compare the tag name here, as the tag might not be a known tag with an ID.
2057
+ if (tid === elementId && (tid !== html_js_1.TAG_ID.UNKNOWN || p.treeAdapter.getTagName(element) === tn)) {
2058
+ p.openElements.generateImpliedEndTagsWithExclusion(tid);
2059
+ if (p.openElements.stackTop >= i)
2060
+ p.openElements.shortenToLength(i);
2061
+ break;
2062
+ }
2063
+ if (p._isSpecialElement(element, elementId)) {
2064
+ break;
2065
+ }
2066
+ }
2067
+ }
2068
+ function endTagInBody(p, token) {
2069
+ switch (token.tagID) {
2070
+ case html_js_1.TAG_ID.A:
2071
+ case html_js_1.TAG_ID.B:
2072
+ case html_js_1.TAG_ID.I:
2073
+ case html_js_1.TAG_ID.S:
2074
+ case html_js_1.TAG_ID.U:
2075
+ case html_js_1.TAG_ID.EM:
2076
+ case html_js_1.TAG_ID.TT:
2077
+ case html_js_1.TAG_ID.BIG:
2078
+ case html_js_1.TAG_ID.CODE:
2079
+ case html_js_1.TAG_ID.FONT:
2080
+ case html_js_1.TAG_ID.NOBR:
2081
+ case html_js_1.TAG_ID.SMALL:
2082
+ case html_js_1.TAG_ID.STRIKE:
2083
+ case html_js_1.TAG_ID.STRONG: {
2084
+ callAdoptionAgency(p, token);
2085
+ break;
2086
+ }
2087
+ case html_js_1.TAG_ID.P: {
2088
+ pEndTagInBody(p);
2089
+ break;
2090
+ }
2091
+ case html_js_1.TAG_ID.DL:
2092
+ case html_js_1.TAG_ID.UL:
2093
+ case html_js_1.TAG_ID.OL:
2094
+ case html_js_1.TAG_ID.DIR:
2095
+ case html_js_1.TAG_ID.DIV:
2096
+ case html_js_1.TAG_ID.NAV:
2097
+ case html_js_1.TAG_ID.PRE:
2098
+ case html_js_1.TAG_ID.MAIN:
2099
+ case html_js_1.TAG_ID.MENU:
2100
+ case html_js_1.TAG_ID.ASIDE:
2101
+ case html_js_1.TAG_ID.BUTTON:
2102
+ case html_js_1.TAG_ID.CENTER:
2103
+ case html_js_1.TAG_ID.FIGURE:
2104
+ case html_js_1.TAG_ID.FOOTER:
2105
+ case html_js_1.TAG_ID.HEADER:
2106
+ case html_js_1.TAG_ID.HGROUP:
2107
+ case html_js_1.TAG_ID.DIALOG:
2108
+ case html_js_1.TAG_ID.ADDRESS:
2109
+ case html_js_1.TAG_ID.ARTICLE:
2110
+ case html_js_1.TAG_ID.DETAILS:
2111
+ case html_js_1.TAG_ID.SECTION:
2112
+ case html_js_1.TAG_ID.SUMMARY:
2113
+ case html_js_1.TAG_ID.LISTING:
2114
+ case html_js_1.TAG_ID.FIELDSET:
2115
+ case html_js_1.TAG_ID.BLOCKQUOTE:
2116
+ case html_js_1.TAG_ID.FIGCAPTION: {
2117
+ addressEndTagInBody(p, token);
2118
+ break;
2119
+ }
2120
+ case html_js_1.TAG_ID.LI: {
2121
+ liEndTagInBody(p);
2122
+ break;
2123
+ }
2124
+ case html_js_1.TAG_ID.DD:
2125
+ case html_js_1.TAG_ID.DT: {
2126
+ ddEndTagInBody(p, token);
2127
+ break;
2128
+ }
2129
+ case html_js_1.TAG_ID.H1:
2130
+ case html_js_1.TAG_ID.H2:
2131
+ case html_js_1.TAG_ID.H3:
2132
+ case html_js_1.TAG_ID.H4:
2133
+ case html_js_1.TAG_ID.H5:
2134
+ case html_js_1.TAG_ID.H6: {
2135
+ numberedHeaderEndTagInBody(p);
2136
+ break;
2137
+ }
2138
+ case html_js_1.TAG_ID.BR: {
2139
+ brEndTagInBody(p);
2140
+ break;
2141
+ }
2142
+ case html_js_1.TAG_ID.BODY: {
2143
+ bodyEndTagInBody(p, token);
2144
+ break;
2145
+ }
2146
+ case html_js_1.TAG_ID.HTML: {
2147
+ htmlEndTagInBody(p, token);
2148
+ break;
2149
+ }
2150
+ case html_js_1.TAG_ID.FORM: {
2151
+ formEndTagInBody(p);
2152
+ break;
2153
+ }
2154
+ case html_js_1.TAG_ID.APPLET:
2155
+ case html_js_1.TAG_ID.OBJECT:
2156
+ case html_js_1.TAG_ID.MARQUEE: {
2157
+ appletEndTagInBody(p, token);
2158
+ break;
2159
+ }
2160
+ case html_js_1.TAG_ID.TEMPLATE: {
2161
+ templateEndTagInHead(p, token);
2162
+ break;
2163
+ }
2164
+ default: {
2165
+ genericEndTagInBody(p, token);
2166
+ }
2167
+ }
2168
+ }
2169
+ function eofInBody(p, token) {
2170
+ if (p.tmplInsertionModeStack.length > 0) {
2171
+ eofInTemplate(p, token);
2172
+ }
2173
+ else {
2174
+ stopParsing(p, token);
2175
+ }
2176
+ }
2177
+ // The "text" insertion mode
2178
+ //------------------------------------------------------------------
2179
+ function endTagInText(p, token) {
2180
+ var _a;
2181
+ if (token.tagID === html_js_1.TAG_ID.SCRIPT) {
2182
+ (_a = p.scriptHandler) === null || _a === void 0 ? void 0 : _a.call(p, p.openElements.current);
2183
+ }
2184
+ p.openElements.pop();
2185
+ p.insertionMode = p.originalInsertionMode;
2186
+ }
2187
+ function eofInText(p, token) {
2188
+ p._err(token, error_codes_js_1.ERR.eofInElementThatCanContainOnlyText);
2189
+ p.openElements.pop();
2190
+ p.insertionMode = p.originalInsertionMode;
2191
+ p.onEof(token);
2192
+ }
2193
+ // The "in table" insertion mode
2194
+ //------------------------------------------------------------------
2195
+ function characterInTable(p, token) {
2196
+ if (TABLE_STRUCTURE_TAGS.has(p.openElements.currentTagId)) {
2197
+ p.pendingCharacterTokens.length = 0;
2198
+ p.hasNonWhitespacePendingCharacterToken = false;
2199
+ p.originalInsertionMode = p.insertionMode;
2200
+ p.insertionMode = InsertionMode.IN_TABLE_TEXT;
2201
+ switch (token.type) {
2202
+ case token_js_1.TokenType.CHARACTER: {
2203
+ characterInTableText(p, token);
2204
+ break;
2205
+ }
2206
+ case token_js_1.TokenType.WHITESPACE_CHARACTER: {
2207
+ whitespaceCharacterInTableText(p, token);
2208
+ break;
2209
+ }
2210
+ // Ignore null
2211
+ }
2212
+ }
2213
+ else {
2214
+ tokenInTable(p, token);
2215
+ }
2216
+ }
2217
+ function captionStartTagInTable(p, token) {
2218
+ p.openElements.clearBackToTableContext();
2219
+ p.activeFormattingElements.insertMarker();
2220
+ p._insertElement(token, html_js_1.NS.HTML);
2221
+ p.insertionMode = InsertionMode.IN_CAPTION;
2222
+ }
2223
+ function colgroupStartTagInTable(p, token) {
2224
+ p.openElements.clearBackToTableContext();
2225
+ p._insertElement(token, html_js_1.NS.HTML);
2226
+ p.insertionMode = InsertionMode.IN_COLUMN_GROUP;
2227
+ }
2228
+ function colStartTagInTable(p, token) {
2229
+ p.openElements.clearBackToTableContext();
2230
+ p._insertFakeElement(html_js_1.TAG_NAMES.COLGROUP, html_js_1.TAG_ID.COLGROUP);
2231
+ p.insertionMode = InsertionMode.IN_COLUMN_GROUP;
2232
+ startTagInColumnGroup(p, token);
2233
+ }
2234
+ function tbodyStartTagInTable(p, token) {
2235
+ p.openElements.clearBackToTableContext();
2236
+ p._insertElement(token, html_js_1.NS.HTML);
2237
+ p.insertionMode = InsertionMode.IN_TABLE_BODY;
2238
+ }
2239
+ function tdStartTagInTable(p, token) {
2240
+ p.openElements.clearBackToTableContext();
2241
+ p._insertFakeElement(html_js_1.TAG_NAMES.TBODY, html_js_1.TAG_ID.TBODY);
2242
+ p.insertionMode = InsertionMode.IN_TABLE_BODY;
2243
+ startTagInTableBody(p, token);
2244
+ }
2245
+ function tableStartTagInTable(p, token) {
2246
+ if (p.openElements.hasInTableScope(html_js_1.TAG_ID.TABLE)) {
2247
+ p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.TABLE);
2248
+ p._resetInsertionMode();
2249
+ p._processStartTag(token);
2250
+ }
2251
+ }
2252
+ function inputStartTagInTable(p, token) {
2253
+ if (isHiddenInput(token)) {
2254
+ p._appendElement(token, html_js_1.NS.HTML);
2255
+ }
2256
+ else {
2257
+ tokenInTable(p, token);
2258
+ }
2259
+ token.ackSelfClosing = true;
2260
+ }
2261
+ function formStartTagInTable(p, token) {
2262
+ if (!p.formElement && p.openElements.tmplCount === 0) {
2263
+ p._insertElement(token, html_js_1.NS.HTML);
2264
+ p.formElement = p.openElements.current;
2265
+ p.openElements.pop();
2266
+ }
2267
+ }
2268
+ function startTagInTable(p, token) {
2269
+ switch (token.tagID) {
2270
+ case html_js_1.TAG_ID.TD:
2271
+ case html_js_1.TAG_ID.TH:
2272
+ case html_js_1.TAG_ID.TR: {
2273
+ tdStartTagInTable(p, token);
2274
+ break;
2275
+ }
2276
+ case html_js_1.TAG_ID.STYLE:
2277
+ case html_js_1.TAG_ID.SCRIPT:
2278
+ case html_js_1.TAG_ID.TEMPLATE: {
2279
+ startTagInHead(p, token);
2280
+ break;
2281
+ }
2282
+ case html_js_1.TAG_ID.COL: {
2283
+ colStartTagInTable(p, token);
2284
+ break;
2285
+ }
2286
+ case html_js_1.TAG_ID.FORM: {
2287
+ formStartTagInTable(p, token);
2288
+ break;
2289
+ }
2290
+ case html_js_1.TAG_ID.TABLE: {
2291
+ tableStartTagInTable(p, token);
2292
+ break;
2293
+ }
2294
+ case html_js_1.TAG_ID.TBODY:
2295
+ case html_js_1.TAG_ID.TFOOT:
2296
+ case html_js_1.TAG_ID.THEAD: {
2297
+ tbodyStartTagInTable(p, token);
2298
+ break;
2299
+ }
2300
+ case html_js_1.TAG_ID.INPUT: {
2301
+ inputStartTagInTable(p, token);
2302
+ break;
2303
+ }
2304
+ case html_js_1.TAG_ID.CAPTION: {
2305
+ captionStartTagInTable(p, token);
2306
+ break;
2307
+ }
2308
+ case html_js_1.TAG_ID.COLGROUP: {
2309
+ colgroupStartTagInTable(p, token);
2310
+ break;
2311
+ }
2312
+ default: {
2313
+ tokenInTable(p, token);
2314
+ }
2315
+ }
2316
+ }
2317
+ function endTagInTable(p, token) {
2318
+ switch (token.tagID) {
2319
+ case html_js_1.TAG_ID.TABLE: {
2320
+ if (p.openElements.hasInTableScope(html_js_1.TAG_ID.TABLE)) {
2321
+ p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.TABLE);
2322
+ p._resetInsertionMode();
2323
+ }
2324
+ break;
2325
+ }
2326
+ case html_js_1.TAG_ID.TEMPLATE: {
2327
+ templateEndTagInHead(p, token);
2328
+ break;
2329
+ }
2330
+ case html_js_1.TAG_ID.BODY:
2331
+ case html_js_1.TAG_ID.CAPTION:
2332
+ case html_js_1.TAG_ID.COL:
2333
+ case html_js_1.TAG_ID.COLGROUP:
2334
+ case html_js_1.TAG_ID.HTML:
2335
+ case html_js_1.TAG_ID.TBODY:
2336
+ case html_js_1.TAG_ID.TD:
2337
+ case html_js_1.TAG_ID.TFOOT:
2338
+ case html_js_1.TAG_ID.TH:
2339
+ case html_js_1.TAG_ID.THEAD:
2340
+ case html_js_1.TAG_ID.TR: {
2341
+ // Ignore token
2342
+ break;
2343
+ }
2344
+ default: {
2345
+ tokenInTable(p, token);
2346
+ }
2347
+ }
2348
+ }
2349
+ function tokenInTable(p, token) {
2350
+ const savedFosterParentingState = p.fosterParentingEnabled;
2351
+ p.fosterParentingEnabled = true;
2352
+ // Process token in `In Body` mode
2353
+ modeInBody(p, token);
2354
+ p.fosterParentingEnabled = savedFosterParentingState;
2355
+ }
2356
+ // The "in table text" insertion mode
2357
+ //------------------------------------------------------------------
2358
+ function whitespaceCharacterInTableText(p, token) {
2359
+ p.pendingCharacterTokens.push(token);
2360
+ }
2361
+ function characterInTableText(p, token) {
2362
+ p.pendingCharacterTokens.push(token);
2363
+ p.hasNonWhitespacePendingCharacterToken = true;
2364
+ }
2365
+ function tokenInTableText(p, token) {
2366
+ let i = 0;
2367
+ if (p.hasNonWhitespacePendingCharacterToken) {
2368
+ for (; i < p.pendingCharacterTokens.length; i++) {
2369
+ tokenInTable(p, p.pendingCharacterTokens[i]);
2370
+ }
2371
+ }
2372
+ else {
2373
+ for (; i < p.pendingCharacterTokens.length; i++) {
2374
+ p._insertCharacters(p.pendingCharacterTokens[i]);
2375
+ }
2376
+ }
2377
+ p.insertionMode = p.originalInsertionMode;
2378
+ p._processToken(token);
2379
+ }
2380
+ // The "in caption" insertion mode
2381
+ //------------------------------------------------------------------
2382
+ const TABLE_VOID_ELEMENTS = new Set([html_js_1.TAG_ID.CAPTION, html_js_1.TAG_ID.COL, html_js_1.TAG_ID.COLGROUP, html_js_1.TAG_ID.TBODY, html_js_1.TAG_ID.TD, html_js_1.TAG_ID.TFOOT, html_js_1.TAG_ID.TH, html_js_1.TAG_ID.THEAD, html_js_1.TAG_ID.TR]);
2383
+ function startTagInCaption(p, token) {
2384
+ const tn = token.tagID;
2385
+ if (TABLE_VOID_ELEMENTS.has(tn)) {
2386
+ if (p.openElements.hasInTableScope(html_js_1.TAG_ID.CAPTION)) {
2387
+ p.openElements.generateImpliedEndTags();
2388
+ p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.CAPTION);
2389
+ p.activeFormattingElements.clearToLastMarker();
2390
+ p.insertionMode = InsertionMode.IN_TABLE;
2391
+ startTagInTable(p, token);
2392
+ }
2393
+ }
2394
+ else {
2395
+ startTagInBody(p, token);
2396
+ }
2397
+ }
2398
+ function endTagInCaption(p, token) {
2399
+ const tn = token.tagID;
2400
+ switch (tn) {
2401
+ case html_js_1.TAG_ID.CAPTION:
2402
+ case html_js_1.TAG_ID.TABLE: {
2403
+ if (p.openElements.hasInTableScope(html_js_1.TAG_ID.CAPTION)) {
2404
+ p.openElements.generateImpliedEndTags();
2405
+ p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.CAPTION);
2406
+ p.activeFormattingElements.clearToLastMarker();
2407
+ p.insertionMode = InsertionMode.IN_TABLE;
2408
+ if (tn === html_js_1.TAG_ID.TABLE) {
2409
+ endTagInTable(p, token);
2410
+ }
2411
+ }
2412
+ break;
2413
+ }
2414
+ case html_js_1.TAG_ID.BODY:
2415
+ case html_js_1.TAG_ID.COL:
2416
+ case html_js_1.TAG_ID.COLGROUP:
2417
+ case html_js_1.TAG_ID.HTML:
2418
+ case html_js_1.TAG_ID.TBODY:
2419
+ case html_js_1.TAG_ID.TD:
2420
+ case html_js_1.TAG_ID.TFOOT:
2421
+ case html_js_1.TAG_ID.TH:
2422
+ case html_js_1.TAG_ID.THEAD:
2423
+ case html_js_1.TAG_ID.TR: {
2424
+ // Ignore token
2425
+ break;
2426
+ }
2427
+ default: {
2428
+ endTagInBody(p, token);
2429
+ }
2430
+ }
2431
+ }
2432
+ // The "in column group" insertion mode
2433
+ //------------------------------------------------------------------
2434
+ function startTagInColumnGroup(p, token) {
2435
+ switch (token.tagID) {
2436
+ case html_js_1.TAG_ID.HTML: {
2437
+ startTagInBody(p, token);
2438
+ break;
2439
+ }
2440
+ case html_js_1.TAG_ID.COL: {
2441
+ p._appendElement(token, html_js_1.NS.HTML);
2442
+ token.ackSelfClosing = true;
2443
+ break;
2444
+ }
2445
+ case html_js_1.TAG_ID.TEMPLATE: {
2446
+ startTagInHead(p, token);
2447
+ break;
2448
+ }
2449
+ default: {
2450
+ tokenInColumnGroup(p, token);
2451
+ }
2452
+ }
2453
+ }
2454
+ function endTagInColumnGroup(p, token) {
2455
+ switch (token.tagID) {
2456
+ case html_js_1.TAG_ID.COLGROUP: {
2457
+ if (p.openElements.currentTagId === html_js_1.TAG_ID.COLGROUP) {
2458
+ p.openElements.pop();
2459
+ p.insertionMode = InsertionMode.IN_TABLE;
2460
+ }
2461
+ break;
2462
+ }
2463
+ case html_js_1.TAG_ID.TEMPLATE: {
2464
+ templateEndTagInHead(p, token);
2465
+ break;
2466
+ }
2467
+ case html_js_1.TAG_ID.COL: {
2468
+ // Ignore token
2469
+ break;
2470
+ }
2471
+ default: {
2472
+ tokenInColumnGroup(p, token);
2473
+ }
2474
+ }
2475
+ }
2476
+ function tokenInColumnGroup(p, token) {
2477
+ if (p.openElements.currentTagId === html_js_1.TAG_ID.COLGROUP) {
2478
+ p.openElements.pop();
2479
+ p.insertionMode = InsertionMode.IN_TABLE;
2480
+ p._processToken(token);
2481
+ }
2482
+ }
2483
+ // The "in table body" insertion mode
2484
+ //------------------------------------------------------------------
2485
+ function startTagInTableBody(p, token) {
2486
+ switch (token.tagID) {
2487
+ case html_js_1.TAG_ID.TR: {
2488
+ p.openElements.clearBackToTableBodyContext();
2489
+ p._insertElement(token, html_js_1.NS.HTML);
2490
+ p.insertionMode = InsertionMode.IN_ROW;
2491
+ break;
2492
+ }
2493
+ case html_js_1.TAG_ID.TH:
2494
+ case html_js_1.TAG_ID.TD: {
2495
+ p.openElements.clearBackToTableBodyContext();
2496
+ p._insertFakeElement(html_js_1.TAG_NAMES.TR, html_js_1.TAG_ID.TR);
2497
+ p.insertionMode = InsertionMode.IN_ROW;
2498
+ startTagInRow(p, token);
2499
+ break;
2500
+ }
2501
+ case html_js_1.TAG_ID.CAPTION:
2502
+ case html_js_1.TAG_ID.COL:
2503
+ case html_js_1.TAG_ID.COLGROUP:
2504
+ case html_js_1.TAG_ID.TBODY:
2505
+ case html_js_1.TAG_ID.TFOOT:
2506
+ case html_js_1.TAG_ID.THEAD: {
2507
+ if (p.openElements.hasTableBodyContextInTableScope()) {
2508
+ p.openElements.clearBackToTableBodyContext();
2509
+ p.openElements.pop();
2510
+ p.insertionMode = InsertionMode.IN_TABLE;
2511
+ startTagInTable(p, token);
2512
+ }
2513
+ break;
2514
+ }
2515
+ default: {
2516
+ startTagInTable(p, token);
2517
+ }
2518
+ }
2519
+ }
2520
+ function endTagInTableBody(p, token) {
2521
+ const tn = token.tagID;
2522
+ switch (token.tagID) {
2523
+ case html_js_1.TAG_ID.TBODY:
2524
+ case html_js_1.TAG_ID.TFOOT:
2525
+ case html_js_1.TAG_ID.THEAD: {
2526
+ if (p.openElements.hasInTableScope(tn)) {
2527
+ p.openElements.clearBackToTableBodyContext();
2528
+ p.openElements.pop();
2529
+ p.insertionMode = InsertionMode.IN_TABLE;
2530
+ }
2531
+ break;
2532
+ }
2533
+ case html_js_1.TAG_ID.TABLE: {
2534
+ if (p.openElements.hasTableBodyContextInTableScope()) {
2535
+ p.openElements.clearBackToTableBodyContext();
2536
+ p.openElements.pop();
2537
+ p.insertionMode = InsertionMode.IN_TABLE;
2538
+ endTagInTable(p, token);
2539
+ }
2540
+ break;
2541
+ }
2542
+ case html_js_1.TAG_ID.BODY:
2543
+ case html_js_1.TAG_ID.CAPTION:
2544
+ case html_js_1.TAG_ID.COL:
2545
+ case html_js_1.TAG_ID.COLGROUP:
2546
+ case html_js_1.TAG_ID.HTML:
2547
+ case html_js_1.TAG_ID.TD:
2548
+ case html_js_1.TAG_ID.TH:
2549
+ case html_js_1.TAG_ID.TR: {
2550
+ // Ignore token
2551
+ break;
2552
+ }
2553
+ default: {
2554
+ endTagInTable(p, token);
2555
+ }
2556
+ }
2557
+ }
2558
+ // The "in row" insertion mode
2559
+ //------------------------------------------------------------------
2560
+ function startTagInRow(p, token) {
2561
+ switch (token.tagID) {
2562
+ case html_js_1.TAG_ID.TH:
2563
+ case html_js_1.TAG_ID.TD: {
2564
+ p.openElements.clearBackToTableRowContext();
2565
+ p._insertElement(token, html_js_1.NS.HTML);
2566
+ p.insertionMode = InsertionMode.IN_CELL;
2567
+ p.activeFormattingElements.insertMarker();
2568
+ break;
2569
+ }
2570
+ case html_js_1.TAG_ID.CAPTION:
2571
+ case html_js_1.TAG_ID.COL:
2572
+ case html_js_1.TAG_ID.COLGROUP:
2573
+ case html_js_1.TAG_ID.TBODY:
2574
+ case html_js_1.TAG_ID.TFOOT:
2575
+ case html_js_1.TAG_ID.THEAD:
2576
+ case html_js_1.TAG_ID.TR: {
2577
+ if (p.openElements.hasInTableScope(html_js_1.TAG_ID.TR)) {
2578
+ p.openElements.clearBackToTableRowContext();
2579
+ p.openElements.pop();
2580
+ p.insertionMode = InsertionMode.IN_TABLE_BODY;
2581
+ startTagInTableBody(p, token);
2582
+ }
2583
+ break;
2584
+ }
2585
+ default: {
2586
+ startTagInTable(p, token);
2587
+ }
2588
+ }
2589
+ }
2590
+ function endTagInRow(p, token) {
2591
+ switch (token.tagID) {
2592
+ case html_js_1.TAG_ID.TR: {
2593
+ if (p.openElements.hasInTableScope(html_js_1.TAG_ID.TR)) {
2594
+ p.openElements.clearBackToTableRowContext();
2595
+ p.openElements.pop();
2596
+ p.insertionMode = InsertionMode.IN_TABLE_BODY;
2597
+ }
2598
+ break;
2599
+ }
2600
+ case html_js_1.TAG_ID.TABLE: {
2601
+ if (p.openElements.hasInTableScope(html_js_1.TAG_ID.TR)) {
2602
+ p.openElements.clearBackToTableRowContext();
2603
+ p.openElements.pop();
2604
+ p.insertionMode = InsertionMode.IN_TABLE_BODY;
2605
+ endTagInTableBody(p, token);
2606
+ }
2607
+ break;
2608
+ }
2609
+ case html_js_1.TAG_ID.TBODY:
2610
+ case html_js_1.TAG_ID.TFOOT:
2611
+ case html_js_1.TAG_ID.THEAD: {
2612
+ if (p.openElements.hasInTableScope(token.tagID) || p.openElements.hasInTableScope(html_js_1.TAG_ID.TR)) {
2613
+ p.openElements.clearBackToTableRowContext();
2614
+ p.openElements.pop();
2615
+ p.insertionMode = InsertionMode.IN_TABLE_BODY;
2616
+ endTagInTableBody(p, token);
2617
+ }
2618
+ break;
2619
+ }
2620
+ case html_js_1.TAG_ID.BODY:
2621
+ case html_js_1.TAG_ID.CAPTION:
2622
+ case html_js_1.TAG_ID.COL:
2623
+ case html_js_1.TAG_ID.COLGROUP:
2624
+ case html_js_1.TAG_ID.HTML:
2625
+ case html_js_1.TAG_ID.TD:
2626
+ case html_js_1.TAG_ID.TH: {
2627
+ // Ignore end tag
2628
+ break;
2629
+ }
2630
+ default:
2631
+ endTagInTable(p, token);
2632
+ }
2633
+ }
2634
+ // The "in cell" insertion mode
2635
+ //------------------------------------------------------------------
2636
+ function startTagInCell(p, token) {
2637
+ const tn = token.tagID;
2638
+ if (TABLE_VOID_ELEMENTS.has(tn)) {
2639
+ if (p.openElements.hasInTableScope(html_js_1.TAG_ID.TD) || p.openElements.hasInTableScope(html_js_1.TAG_ID.TH)) {
2640
+ p._closeTableCell();
2641
+ startTagInRow(p, token);
2642
+ }
2643
+ }
2644
+ else {
2645
+ startTagInBody(p, token);
2646
+ }
2647
+ }
2648
+ function endTagInCell(p, token) {
2649
+ const tn = token.tagID;
2650
+ switch (tn) {
2651
+ case html_js_1.TAG_ID.TD:
2652
+ case html_js_1.TAG_ID.TH: {
2653
+ if (p.openElements.hasInTableScope(tn)) {
2654
+ p.openElements.generateImpliedEndTags();
2655
+ p.openElements.popUntilTagNamePopped(tn);
2656
+ p.activeFormattingElements.clearToLastMarker();
2657
+ p.insertionMode = InsertionMode.IN_ROW;
2658
+ }
2659
+ break;
2660
+ }
2661
+ case html_js_1.TAG_ID.TABLE:
2662
+ case html_js_1.TAG_ID.TBODY:
2663
+ case html_js_1.TAG_ID.TFOOT:
2664
+ case html_js_1.TAG_ID.THEAD:
2665
+ case html_js_1.TAG_ID.TR: {
2666
+ if (p.openElements.hasInTableScope(tn)) {
2667
+ p._closeTableCell();
2668
+ endTagInRow(p, token);
2669
+ }
2670
+ break;
2671
+ }
2672
+ case html_js_1.TAG_ID.BODY:
2673
+ case html_js_1.TAG_ID.CAPTION:
2674
+ case html_js_1.TAG_ID.COL:
2675
+ case html_js_1.TAG_ID.COLGROUP:
2676
+ case html_js_1.TAG_ID.HTML: {
2677
+ // Ignore token
2678
+ break;
2679
+ }
2680
+ default: {
2681
+ endTagInBody(p, token);
2682
+ }
2683
+ }
2684
+ }
2685
+ // The "in select" insertion mode
2686
+ //------------------------------------------------------------------
2687
+ function startTagInSelect(p, token) {
2688
+ switch (token.tagID) {
2689
+ case html_js_1.TAG_ID.HTML: {
2690
+ startTagInBody(p, token);
2691
+ break;
2692
+ }
2693
+ case html_js_1.TAG_ID.OPTION: {
2694
+ if (p.openElements.currentTagId === html_js_1.TAG_ID.OPTION) {
2695
+ p.openElements.pop();
2696
+ }
2697
+ p._insertElement(token, html_js_1.NS.HTML);
2698
+ break;
2699
+ }
2700
+ case html_js_1.TAG_ID.OPTGROUP: {
2701
+ if (p.openElements.currentTagId === html_js_1.TAG_ID.OPTION) {
2702
+ p.openElements.pop();
2703
+ }
2704
+ if (p.openElements.currentTagId === html_js_1.TAG_ID.OPTGROUP) {
2705
+ p.openElements.pop();
2706
+ }
2707
+ p._insertElement(token, html_js_1.NS.HTML);
2708
+ break;
2709
+ }
2710
+ case html_js_1.TAG_ID.INPUT:
2711
+ case html_js_1.TAG_ID.KEYGEN:
2712
+ case html_js_1.TAG_ID.TEXTAREA:
2713
+ case html_js_1.TAG_ID.SELECT: {
2714
+ if (p.openElements.hasInSelectScope(html_js_1.TAG_ID.SELECT)) {
2715
+ p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.SELECT);
2716
+ p._resetInsertionMode();
2717
+ if (token.tagID !== html_js_1.TAG_ID.SELECT) {
2718
+ p._processStartTag(token);
2719
+ }
2720
+ }
2721
+ break;
2722
+ }
2723
+ case html_js_1.TAG_ID.SCRIPT:
2724
+ case html_js_1.TAG_ID.TEMPLATE: {
2725
+ startTagInHead(p, token);
2726
+ break;
2727
+ }
2728
+ default:
2729
+ // Do nothing
2730
+ }
2731
+ }
2732
+ function endTagInSelect(p, token) {
2733
+ switch (token.tagID) {
2734
+ case html_js_1.TAG_ID.OPTGROUP: {
2735
+ if (p.openElements.stackTop > 0 &&
2736
+ p.openElements.currentTagId === html_js_1.TAG_ID.OPTION &&
2737
+ p.openElements.tagIDs[p.openElements.stackTop - 1] === html_js_1.TAG_ID.OPTGROUP) {
2738
+ p.openElements.pop();
2739
+ }
2740
+ if (p.openElements.currentTagId === html_js_1.TAG_ID.OPTGROUP) {
2741
+ p.openElements.pop();
2742
+ }
2743
+ break;
2744
+ }
2745
+ case html_js_1.TAG_ID.OPTION: {
2746
+ if (p.openElements.currentTagId === html_js_1.TAG_ID.OPTION) {
2747
+ p.openElements.pop();
2748
+ }
2749
+ break;
2750
+ }
2751
+ case html_js_1.TAG_ID.SELECT: {
2752
+ if (p.openElements.hasInSelectScope(html_js_1.TAG_ID.SELECT)) {
2753
+ p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.SELECT);
2754
+ p._resetInsertionMode();
2755
+ }
2756
+ break;
2757
+ }
2758
+ case html_js_1.TAG_ID.TEMPLATE: {
2759
+ templateEndTagInHead(p, token);
2760
+ break;
2761
+ }
2762
+ default:
2763
+ // Do nothing
2764
+ }
2765
+ }
2766
+ // The "in select in table" insertion mode
2767
+ //------------------------------------------------------------------
2768
+ function startTagInSelectInTable(p, token) {
2769
+ const tn = token.tagID;
2770
+ if (tn === html_js_1.TAG_ID.CAPTION ||
2771
+ tn === html_js_1.TAG_ID.TABLE ||
2772
+ tn === html_js_1.TAG_ID.TBODY ||
2773
+ tn === html_js_1.TAG_ID.TFOOT ||
2774
+ tn === html_js_1.TAG_ID.THEAD ||
2775
+ tn === html_js_1.TAG_ID.TR ||
2776
+ tn === html_js_1.TAG_ID.TD ||
2777
+ tn === html_js_1.TAG_ID.TH) {
2778
+ p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.SELECT);
2779
+ p._resetInsertionMode();
2780
+ p._processStartTag(token);
2781
+ }
2782
+ else {
2783
+ startTagInSelect(p, token);
2784
+ }
2785
+ }
2786
+ function endTagInSelectInTable(p, token) {
2787
+ const tn = token.tagID;
2788
+ if (tn === html_js_1.TAG_ID.CAPTION ||
2789
+ tn === html_js_1.TAG_ID.TABLE ||
2790
+ tn === html_js_1.TAG_ID.TBODY ||
2791
+ tn === html_js_1.TAG_ID.TFOOT ||
2792
+ tn === html_js_1.TAG_ID.THEAD ||
2793
+ tn === html_js_1.TAG_ID.TR ||
2794
+ tn === html_js_1.TAG_ID.TD ||
2795
+ tn === html_js_1.TAG_ID.TH) {
2796
+ if (p.openElements.hasInTableScope(tn)) {
2797
+ p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.SELECT);
2798
+ p._resetInsertionMode();
2799
+ p.onEndTag(token);
2800
+ }
2801
+ }
2802
+ else {
2803
+ endTagInSelect(p, token);
2804
+ }
2805
+ }
2806
+ // The "in template" insertion mode
2807
+ //------------------------------------------------------------------
2808
+ function startTagInTemplate(p, token) {
2809
+ switch (token.tagID) {
2810
+ // First, handle tags that can start without a mode change
2811
+ case html_js_1.TAG_ID.BASE:
2812
+ case html_js_1.TAG_ID.BASEFONT:
2813
+ case html_js_1.TAG_ID.BGSOUND:
2814
+ case html_js_1.TAG_ID.LINK:
2815
+ case html_js_1.TAG_ID.META:
2816
+ case html_js_1.TAG_ID.NOFRAMES:
2817
+ case html_js_1.TAG_ID.SCRIPT:
2818
+ case html_js_1.TAG_ID.STYLE:
2819
+ case html_js_1.TAG_ID.TEMPLATE:
2820
+ case html_js_1.TAG_ID.TITLE:
2821
+ startTagInHead(p, token);
2822
+ break;
2823
+ // Re-process the token in the appropriate mode
2824
+ case html_js_1.TAG_ID.CAPTION:
2825
+ case html_js_1.TAG_ID.COLGROUP:
2826
+ case html_js_1.TAG_ID.TBODY:
2827
+ case html_js_1.TAG_ID.TFOOT:
2828
+ case html_js_1.TAG_ID.THEAD:
2829
+ p.tmplInsertionModeStack[0] = InsertionMode.IN_TABLE;
2830
+ p.insertionMode = InsertionMode.IN_TABLE;
2831
+ startTagInTable(p, token);
2832
+ break;
2833
+ case html_js_1.TAG_ID.COL:
2834
+ p.tmplInsertionModeStack[0] = InsertionMode.IN_COLUMN_GROUP;
2835
+ p.insertionMode = InsertionMode.IN_COLUMN_GROUP;
2836
+ startTagInColumnGroup(p, token);
2837
+ break;
2838
+ case html_js_1.TAG_ID.TR:
2839
+ p.tmplInsertionModeStack[0] = InsertionMode.IN_TABLE_BODY;
2840
+ p.insertionMode = InsertionMode.IN_TABLE_BODY;
2841
+ startTagInTableBody(p, token);
2842
+ break;
2843
+ case html_js_1.TAG_ID.TD:
2844
+ case html_js_1.TAG_ID.TH:
2845
+ p.tmplInsertionModeStack[0] = InsertionMode.IN_ROW;
2846
+ p.insertionMode = InsertionMode.IN_ROW;
2847
+ startTagInRow(p, token);
2848
+ break;
2849
+ default:
2850
+ p.tmplInsertionModeStack[0] = InsertionMode.IN_BODY;
2851
+ p.insertionMode = InsertionMode.IN_BODY;
2852
+ startTagInBody(p, token);
2853
+ }
2854
+ }
2855
+ function endTagInTemplate(p, token) {
2856
+ if (token.tagID === html_js_1.TAG_ID.TEMPLATE) {
2857
+ templateEndTagInHead(p, token);
2858
+ }
2859
+ }
2860
+ function eofInTemplate(p, token) {
2861
+ if (p.openElements.tmplCount > 0) {
2862
+ p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.TEMPLATE);
2863
+ p.activeFormattingElements.clearToLastMarker();
2864
+ p.tmplInsertionModeStack.shift();
2865
+ p._resetInsertionMode();
2866
+ p.onEof(token);
2867
+ }
2868
+ else {
2869
+ stopParsing(p, token);
2870
+ }
2871
+ }
2872
+ // The "after body" insertion mode
2873
+ //------------------------------------------------------------------
2874
+ function startTagAfterBody(p, token) {
2875
+ if (token.tagID === html_js_1.TAG_ID.HTML) {
2876
+ startTagInBody(p, token);
2877
+ }
2878
+ else {
2879
+ tokenAfterBody(p, token);
2880
+ }
2881
+ }
2882
+ function endTagAfterBody(p, token) {
2883
+ var _a;
2884
+ if (token.tagID === html_js_1.TAG_ID.HTML) {
2885
+ if (!p.fragmentContext) {
2886
+ p.insertionMode = InsertionMode.AFTER_AFTER_BODY;
2887
+ }
2888
+ //NOTE: <html> is never popped from the stack, so we need to updated
2889
+ //the end location explicitly.
2890
+ if (p.options.sourceCodeLocationInfo && p.openElements.tagIDs[0] === html_js_1.TAG_ID.HTML) {
2891
+ p._setEndLocation(p.openElements.items[0], token);
2892
+ // Update the body element, if it doesn't have an end tag
2893
+ const bodyElement = p.openElements.items[1];
2894
+ if (bodyElement && !((_a = p.treeAdapter.getNodeSourceCodeLocation(bodyElement)) === null || _a === void 0 ? void 0 : _a.endTag)) {
2895
+ p._setEndLocation(bodyElement, token);
2896
+ }
2897
+ }
2898
+ }
2899
+ else {
2900
+ tokenAfterBody(p, token);
2901
+ }
2902
+ }
2903
+ function tokenAfterBody(p, token) {
2904
+ p.insertionMode = InsertionMode.IN_BODY;
2905
+ modeInBody(p, token);
2906
+ }
2907
+ // The "in frameset" insertion mode
2908
+ //------------------------------------------------------------------
2909
+ function startTagInFrameset(p, token) {
2910
+ switch (token.tagID) {
2911
+ case html_js_1.TAG_ID.HTML: {
2912
+ startTagInBody(p, token);
2913
+ break;
2914
+ }
2915
+ case html_js_1.TAG_ID.FRAMESET: {
2916
+ p._insertElement(token, html_js_1.NS.HTML);
2917
+ break;
2918
+ }
2919
+ case html_js_1.TAG_ID.FRAME: {
2920
+ p._appendElement(token, html_js_1.NS.HTML);
2921
+ token.ackSelfClosing = true;
2922
+ break;
2923
+ }
2924
+ case html_js_1.TAG_ID.NOFRAMES: {
2925
+ startTagInHead(p, token);
2926
+ break;
2927
+ }
2928
+ default:
2929
+ // Do nothing
2930
+ }
2931
+ }
2932
+ function endTagInFrameset(p, token) {
2933
+ if (token.tagID === html_js_1.TAG_ID.FRAMESET && !p.openElements.isRootHtmlElementCurrent()) {
2934
+ p.openElements.pop();
2935
+ if (!p.fragmentContext && p.openElements.currentTagId !== html_js_1.TAG_ID.FRAMESET) {
2936
+ p.insertionMode = InsertionMode.AFTER_FRAMESET;
2937
+ }
2938
+ }
2939
+ }
2940
+ // The "after frameset" insertion mode
2941
+ //------------------------------------------------------------------
2942
+ function startTagAfterFrameset(p, token) {
2943
+ switch (token.tagID) {
2944
+ case html_js_1.TAG_ID.HTML: {
2945
+ startTagInBody(p, token);
2946
+ break;
2947
+ }
2948
+ case html_js_1.TAG_ID.NOFRAMES: {
2949
+ startTagInHead(p, token);
2950
+ break;
2951
+ }
2952
+ default:
2953
+ // Do nothing
2954
+ }
2955
+ }
2956
+ function endTagAfterFrameset(p, token) {
2957
+ if (token.tagID === html_js_1.TAG_ID.HTML) {
2958
+ p.insertionMode = InsertionMode.AFTER_AFTER_FRAMESET;
2959
+ }
2960
+ }
2961
+ // The "after after body" insertion mode
2962
+ //------------------------------------------------------------------
2963
+ function startTagAfterAfterBody(p, token) {
2964
+ if (token.tagID === html_js_1.TAG_ID.HTML) {
2965
+ startTagInBody(p, token);
2966
+ }
2967
+ else {
2968
+ tokenAfterAfterBody(p, token);
2969
+ }
2970
+ }
2971
+ function tokenAfterAfterBody(p, token) {
2972
+ p.insertionMode = InsertionMode.IN_BODY;
2973
+ modeInBody(p, token);
2974
+ }
2975
+ // The "after after frameset" insertion mode
2976
+ //------------------------------------------------------------------
2977
+ function startTagAfterAfterFrameset(p, token) {
2978
+ switch (token.tagID) {
2979
+ case html_js_1.TAG_ID.HTML: {
2980
+ startTagInBody(p, token);
2981
+ break;
2982
+ }
2983
+ case html_js_1.TAG_ID.NOFRAMES: {
2984
+ startTagInHead(p, token);
2985
+ break;
2986
+ }
2987
+ default:
2988
+ // Do nothing
2989
+ }
2990
+ }
2991
+ // The rules for parsing tokens in foreign content
2992
+ //------------------------------------------------------------------
2993
+ function nullCharacterInForeignContent(p, token) {
2994
+ token.chars = unicode.REPLACEMENT_CHARACTER;
2995
+ p._insertCharacters(token);
2996
+ }
2997
+ function characterInForeignContent(p, token) {
2998
+ p._insertCharacters(token);
2999
+ p.framesetOk = false;
3000
+ }
3001
+ function popUntilHtmlOrIntegrationPoint(p) {
3002
+ while (p.treeAdapter.getNamespaceURI(p.openElements.current) !== html_js_1.NS.HTML &&
3003
+ !p._isIntegrationPoint(p.openElements.currentTagId, p.openElements.current)) {
3004
+ p.openElements.pop();
3005
+ }
3006
+ }
3007
+ function startTagInForeignContent(p, token) {
3008
+ if (foreignContent.causesExit(token)) {
3009
+ popUntilHtmlOrIntegrationPoint(p);
3010
+ p._startTagOutsideForeignContent(token);
3011
+ }
3012
+ else {
3013
+ const current = p._getAdjustedCurrentElement();
3014
+ const currentNs = p.treeAdapter.getNamespaceURI(current);
3015
+ if (currentNs === html_js_1.NS.MATHML) {
3016
+ foreignContent.adjustTokenMathMLAttrs(token);
3017
+ }
3018
+ else if (currentNs === html_js_1.NS.SVG) {
3019
+ foreignContent.adjustTokenSVGTagName(token);
3020
+ foreignContent.adjustTokenSVGAttrs(token);
3021
+ }
3022
+ foreignContent.adjustTokenXMLAttrs(token);
3023
+ if (token.selfClosing) {
3024
+ p._appendElement(token, currentNs);
3025
+ }
3026
+ else {
3027
+ p._insertElement(token, currentNs);
3028
+ }
3029
+ token.ackSelfClosing = true;
3030
+ }
3031
+ }
3032
+ function endTagInForeignContent(p, token) {
3033
+ if (token.tagID === html_js_1.TAG_ID.P || token.tagID === html_js_1.TAG_ID.BR) {
3034
+ popUntilHtmlOrIntegrationPoint(p);
3035
+ p._endTagOutsideForeignContent(token);
3036
+ return;
3037
+ }
3038
+ for (let i = p.openElements.stackTop; i > 0; i--) {
3039
+ const element = p.openElements.items[i];
3040
+ if (p.treeAdapter.getNamespaceURI(element) === html_js_1.NS.HTML) {
3041
+ p._endTagOutsideForeignContent(token);
3042
+ break;
3043
+ }
3044
+ const tagName = p.treeAdapter.getTagName(element);
3045
+ if (tagName.toLowerCase() === token.tagName) {
3046
+ //NOTE: update the token tag name for `_setEndLocation`.
3047
+ token.tagName = tagName;
3048
+ p.openElements.shortenToLength(i);
3049
+ break;
3050
+ }
3051
+ }
3052
+ }
3053
+ //# sourceMappingURL=index.js.map