Skip to content

Commit

Permalink
(fix) embed check (#208)
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 #207
  • Loading branch information
dummdidumm authored Feb 17, 2021
1 parent f714816 commit 4b9b0c6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# prettier-plugin-svelte changelog

## 2.1.6 (Unreleased)

* Fix wrong removal of comment ([#207](https://github.com/sveltejs/prettier-plugin-svelte/issues/207))

## 2.1.5

* Fix retrieval of comment belonging to `<script>`/`<style>` block ([#205](https://github.com/sveltejs/prettier-plugin-svelte/issues/205))
Expand Down
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 4b9b0c6

Please sign in to comment.