Skip to content

Commit

Permalink
fix: don't duplicate comments of nested script/style tags (#425)
Browse files Browse the repository at this point in the history
fixes #400
  • Loading branch information
dummdidumm committed Jan 29, 2024
1 parent 1884f22 commit cc856a0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 3.2.0 (Unreleased)

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

## 3.1.2

Expand Down
3 changes: 2 additions & 1 deletion src/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ async function embedTag(
// the new position.
return [...comments, result, hardline];
} else {
return comments.length ? [...comments, result] : result;
// Only comments at the top level get the special "move comment" treatment.
return isTopLevel && comments.length ? [...comments, result] : result;
}
}

Expand Down
1 change: 0 additions & 1 deletion src/print/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import {
import {
ASTNode,
AttributeNode,
CommentInfo,
CommentNode,
IfBlockNode,
Node,
Expand Down
10 changes: 10 additions & 0 deletions test/printer/samples/script-style-inside-element-comment.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div>
<!-- hello -->
<style></style>
</div>
<svelte:head>
<!-- world -->
<script>
let x;
</script>
</svelte:head>

0 comments on commit cc856a0

Please sign in to comment.