Skip to content

Commit

Permalink
(fix) embed check
Browse files Browse the repository at this point in the history
When checking if an embed starts after a node, return early if that node is not at the top level of html, because embeds cannot start after it.
Fixes sveltejs#207
  • Loading branch information
Simon Holthausen committed Feb 17, 2021
1 parent f714816 commit c01034a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/print/node-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ export function getLeadingComment(path: FastPath): CommentNode | undefined {
export function doesEmbedStartAfterNode(node: Node, path: FastPath, siblings = getSiblings(path)) {
const position = node.end;
const root = path.stack[0];
// If node is not at the top level of html, an embed cannot start after it,
// because embeds are only at the top level
if (!root.html || !root.html.children || !root.html.children.includes(node)) {
return false;
}

const embeds = [root.css, root.html, root.instance, root.js, root.module] as Node[];

const nextNode = siblings[siblings.indexOf(node) + 1];
Expand Down
6 changes: 6 additions & 0 deletions test/printer/samples/comment-at-end.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div>
<div />
<!-- testing 123 -->
</div>

<style></style>

0 comments on commit c01034a

Please sign in to comment.