Skip to content

Commit cc856a0

Browse files
authored
fix: don't duplicate comments of nested script/style tags (#425)
fixes #400
1 parent 1884f22 commit cc856a0

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 3.2.0 (Unreleased)
44

55
- (feat) format JSON script tags
6+
- (fix) don't duplicate comments of nested script/style tags
67

78
## 3.1.2
89

src/embed.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ async function embedTag(
366366
// the new position.
367367
return [...comments, result, hardline];
368368
} else {
369-
return comments.length ? [...comments, result] : result;
369+
// Only comments at the top level get the special "move comment" treatment.
370+
return isTopLevel && comments.length ? [...comments, result] : result;
370371
}
371372
}
372373

src/print/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import {
4646
import {
4747
ASTNode,
4848
AttributeNode,
49-
CommentInfo,
5049
CommentNode,
5150
IfBlockNode,
5251
Node,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<div>
2+
<!-- hello -->
3+
<style></style>
4+
</div>
5+
<svelte:head>
6+
<!-- world -->
7+
<script>
8+
let x;
9+
</script>
10+
</svelte:head>

0 commit comments

Comments
 (0)