Repository: sveltejs/prettier-plugin-svelte (ts)

Issue:
HTML comments inside svelte markup cause formatting to fail
**Describe the bug**
HTML comments inside svelte markup prevents remaining markup from being formatted.

**To Reproduce**
For example (with `"svelteStrictMode": true`) this:

```svelte
<Component   foo={bar} 
      />
<!-- comment -->
<Component   foo={bar} 
      />
```
becomes
```svelte
<Component foo="{bar}" />
<!-- comment -->
<Component   foo={bar} 
      />
```

<hr/>

Using js comments works, however, they are not syntax highlighted.

```svelte
<Component foo="{bar}" />
// comment
<Component foo="{bar}" />
```

**Expected behavior**
Should get this:
```svelte
<Component foo="{bar}" />
<!-- comment -->
<Component foo="{bar}" />
```

**System:**
 - OS: Windows
 - IDE: VSCode
 - Plugin/Package: "Svelte for VSCode"

Pull request:
Next line after comment would not be formatted
Fixes #151. There were two bugs here:
 * every comment was treated as a `prettier-ignore-next` attribute
 * the detection of whether the next node was an embedded node that had been removed from the AST did not work when the comment was the last child node

Patch:
diff --git a/src/print/index.ts b/src/print/index.ts
index 5b121a5..8bcaba0 100644
--- a/src/print/index.ts
+++ b/src/print/index.ts
@@ -16,8 +16,8 @@ import {
     isNodeSupportedLanguage,
     isLoneMustacheTag,
     isOrCanBeConvertedToShorthand,
-    getNextNode,
-    getNodeEnd,
+    isIgnoreDirective,
+    doesEmbedStartAt,
     getUnencodedText
 } from './node-helpers';
 import {
@@ -459,9 +459,9 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D
              * If so, the comment does not refer to the next line we will see.
              * The `embed` function handles printing the comment in the right place.
              */
-            if (node.end < getNodeEnd(path.getParentNode(), path) && !getNextNode(path)) {
+            if (doesEmbedStartAt(node.end, path)) {
                 return '';
-            } else {
+            } else if (isIgnoreDirective(node)) {
                 ignoreNext = true;
             }
 
diff --git a/src/print/node-helpers.ts b/src/print/node-helpers.ts
index 28dd095..5e930a8 100644
--- a/src/print/node-helpers.ts
+++ b/src/print/node-helpers.ts
@@ -91,34 +91,14 @@ export function getPreviousNode(path: FastPath): Node | undefined {
 }
 
 /**
- * Returns the next sibling node.
+ * Did there use to be any embedded object (that has been snipped out of the AST to be moved)
+ * at the specified position?
  */
-export function getNextNode(path: FastPath): Node | undefined {
-    const node: Node = path.getNode();
-    let parent: Node = path.getParentNode();
-
-    if (isASTNode(parent)) {
-        parent = parent.html;
-    }
-
-    return getChildren(parent).find((child) => child.start === node.end);
-}
-
-/**
- * Returns the position that used to be the end of the node before the embed elements were cut out.
- */
-export function getNodeEnd(node: Node, path: FastPath) {
+export function doesEmbedStartAt(position: number, path: FastPath) {
     const root = path.stack[0];
+    const embeds = [root.css, root.html, root.instance, root.js, root.module] as Node[];
 
-    if (root.html === node) {
-        return Math.max(
-            ...([root.css, root.html, root.instance, root.js, root.module] as Node[])
-                .filter((n) => !!n)
-                .map((n) => n.end),
-        );
-    } else {
-        return node.end;
-    }
+    return embeds.find((n) => n && n.start === position) != null;
 }
 
 export function isEmptyNode(node: Node): boolean {


Test patch:
diff --git a/test/formatting/samples/prettier-ignore/input.html b/test/formatting/samples/prettier-ignore/input.html
index dec7f44..8d3ab56 100644
--- a/test/formatting/samples/prettier-ignore/input.html
+++ b/test/formatting/samples/prettier-ignore/input.html
@@ -1,3 +1,4 @@
 <!-- prettier-ignore -->
 <div id="x" class="y" title="A really long title" hidden on:click={do_something} draggable="false" data-my-prop />
+<!-- do not ignore -->
 <div id="x" class="y" title="A really long title" hidden on:click={do_something} draggable="false" data-my-prop />
diff --git a/test/formatting/samples/prettier-ignore/output.html b/test/formatting/samples/prettier-ignore/output.html
index 63c7067..524649a 100644
--- a/test/formatting/samples/prettier-ignore/output.html
+++ b/test/formatting/samples/prettier-ignore/output.html
@@ -1,5 +1,6 @@
 <!-- prettier-ignore -->
 <div id="x" class="y" title="A really long title" hidden on:click={do_something} draggable="false" data-my-prop />
+<!-- do not ignore -->
 <div
     id="x"
     class="y"
diff --git a/test/printer/samples/element-with-class-and-comment-inside.html b/test/printer/samples/element-with-class-and-comment-inside.html
index 7529bb9..2847ddd 100644
--- a/test/printer/samples/element-with-class-and-comment-inside.html
+++ b/test/printer/samples/element-with-class-and-comment-inside.html
@@ -1,5 +1,3 @@
 <div class="test">
     <!-- c -->
 </div>
-
-<div class="test"><!-- c --></div>