Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) embed check #208

Merged
merged 2 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>