Skip to content

Commit b954bee

Browse files
committed
Fix: recognize self-closing elements
1 parent ba0239a commit b954bee

5 files changed

+987
-2
lines changed

lib/transform-html.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ class HTMLTransformer {
626626
* Transform the given parse5's element node.
627627
* @param {ASTNode} parent The parent node.
628628
* @param {module:parse5.AST.Element} node The element node to transform.
629-
* @returns {ASTNode} The transformed node.
629+
* @returns {ASTNode|ASTNode[]} The transformed node.
630630
*/
631631
visitElementNode(parent, node) {
632632
const start = node.__location.startOffset
@@ -662,8 +662,25 @@ class HTMLTransformer {
662662
}
663663
}
664664

665-
result.endTag = this.createVEndTag(result, node)
665+
if (result.startTag.selfClosing) {
666+
// Vue.js recognizes self-closing elements as different to HTML.
667+
// Move children to the same level of this node.
668+
const results = [result]
669+
const startTag = result.startTag
670+
result.range[1] = startTag.range[1]
671+
result.loc.end.column = startTag.loc.end.column
672+
result.loc.end.line = startTag.loc.end.line
673+
674+
for (const child of result.children) {
675+
child.parent = parent
676+
results.push(child)
677+
}
678+
result.children = []
666679

680+
return results
681+
}
682+
683+
result.endTag = this.createVEndTag(result, node)
667684
return result
668685
}
669686

0 commit comments

Comments
 (0)