From c01034ac19cbea3df7fd81ed660da94a09d5cc3c Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Wed, 17 Feb 2021 09:40:10 +0100 Subject: [PATCH] (fix) embed check 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 #207 --- src/print/node-helpers.ts | 6 ++++++ test/printer/samples/comment-at-end.html | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 test/printer/samples/comment-at-end.html diff --git a/src/print/node-helpers.ts b/src/print/node-helpers.ts index f040456f..8c8aa7eb 100644 --- a/src/print/node-helpers.ts +++ b/src/print/node-helpers.ts @@ -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]; diff --git a/test/printer/samples/comment-at-end.html b/test/printer/samples/comment-at-end.html new file mode 100644 index 00000000..cceefa9a --- /dev/null +++ b/test/printer/samples/comment-at-end.html @@ -0,0 +1,6 @@ +
+
+ +
+ +