Skip to content

Commit 8168db1

Browse files
committed
Fix: crash if <tbody> was omitted
1 parent 6fbd273 commit 8168db1

File tree

5 files changed

+1162
-0
lines changed

5 files changed

+1162
-0
lines changed

lib/transform-html.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,26 @@ class HTMLTransformer {
629629
* @returns {ASTNode|ASTNode[]} The transformed node.
630630
*/
631631
visitElementNode(parent, node) {
632+
// if __location does not exists, this is auto-inserted element for some reason.
633+
// E.g. if a <tr> exists as a direct child of <table>, <tbody> element is inserted implicitly.
634+
if (node.__location == null) {
635+
const results = []
636+
for (const childNode of node.childNodes) {
637+
const child = this.visit(parent, childNode)
638+
639+
// Flatten.
640+
if (Array.isArray(child)) {
641+
for (const child1 of child) {
642+
results.push(child1)
643+
}
644+
}
645+
else if (child != null) {
646+
results.push(child)
647+
}
648+
}
649+
return results
650+
}
651+
632652
const start = node.__location.startOffset
633653
const end = node.__location.endOffset
634654
const childNodes = (node.tagName === "template")

0 commit comments

Comments
 (0)