-
-
Notifications
You must be signed in to change notification settings - Fork 964
feat(parse/html/svelte): new svelte syntax for comments inside tags #9173
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
Merged
+1,458
−57
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| --- | ||
| "@biomejs/biome": patch | ||
| --- | ||
|
|
||
| Added parsing support for Svelte's new [comments-in-tags](https://github.com/sveltejs/svelte/pull/17671) feature. | ||
|
|
||
| The HTML parser will now accept JS style comments in tags in Svelte files. | ||
| ```svelte | ||
| <button | ||
| // single-line comment | ||
| onclick={doTheThing} | ||
| >click me</button> | ||
|
|
||
| <div | ||
| /* block comment */ | ||
| class="foo" | ||
| >text</div> | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
crates/biome_html_formatter/tests/specs/html/svelte/comments-in-component-tags.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <Component | ||
| /* block comment */ | ||
| prop="value" | ||
| /> | ||
| <Component | ||
| // line comment | ||
| prop="value" | ||
| /> | ||
| <Component /* inline block comment */ prop="value" /> | ||
| <Component // inline line comment | ||
| prop="value" /> | ||
| <Component.Member | ||
| /* block comment */ | ||
| prop="value" | ||
| /> |
66 changes: 66 additions & 0 deletions
66
crates/biome_html_formatter/tests/specs/html/svelte/comments-in-component-tags.svelte.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| --- | ||
| source: crates/biome_formatter_test/src/snapshot_builder.rs | ||
| info: svelte/comments-in-component-tags.svelte | ||
| --- | ||
|
|
||
| # Input | ||
|
|
||
| ```svelte | ||
| <Component | ||
| /* block comment */ | ||
| prop="value" | ||
| /> | ||
| <Component | ||
| // line comment | ||
| prop="value" | ||
| /> | ||
| <Component /* inline block comment */ prop="value" /> | ||
| <Component // inline line comment | ||
| prop="value" /> | ||
| <Component.Member | ||
| /* block comment */ | ||
| prop="value" | ||
| /> | ||
|
|
||
| ``` | ||
|
|
||
|
|
||
| ============================= | ||
|
|
||
| # Outputs | ||
|
|
||
| ## Output 1 | ||
|
|
||
| ----- | ||
| Indent style: Tab | ||
| Indent width: 2 | ||
| Line ending: LF | ||
| Line width: 80 | ||
| Attribute Position: Auto | ||
| Bracket same line: false | ||
| Whitespace sensitivity: css | ||
| Indent script and style: false | ||
| Self close void elements: never | ||
| Trailing newline: true | ||
| ----- | ||
|
|
||
| ```svelte | ||
| <Component | ||
| /* block comment */ | ||
| prop="value" | ||
| /> | ||
| <Component | ||
| // line comment | ||
| prop="value" | ||
| /> | ||
| <Component /* inline block comment */ prop="value" /> | ||
| <Component | ||
| // inline line comment | ||
| prop="value" | ||
| /> | ||
| <Component.Member | ||
| /* block comment */ | ||
| prop="value" | ||
| /> | ||
|
|
||
| ``` | ||
58 changes: 58 additions & 0 deletions
58
crates/biome_html_formatter/tests/specs/html/svelte/comments-in-tags.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| <!-- Block comments between attributes (already working) --> | ||
| <div /* block comment */ class="foo" /* block comment */ >text</div> | ||
| <div /* block comment */ class="foo" data-foo="info" /* block comment */ data-bar="info" >text</div> | ||
|
|
||
| <!-- Single-line comment between attributes — was producing invalid syntax before this fix --> | ||
| <div // comment | ||
| class="foo" | ||
| >text</div> | ||
|
|
||
| <!-- // comment as the first attribute (no preceding node) --> | ||
| <div | ||
| // first comment | ||
| class="foo" | ||
| >text</div> | ||
|
|
||
| <!-- // comment as the last attribute before > --> | ||
| <div | ||
| class="foo" | ||
| // last comment | ||
| >text</div> | ||
|
|
||
| <!-- Multiple consecutive // comments --> | ||
| <div | ||
| // first line comment | ||
| // second line comment | ||
| class="foo" | ||
| >text</div> | ||
|
|
||
| <!-- // comment before a Svelte directive attribute --> | ||
| <div | ||
| // comment before directive | ||
| on:click={handler} | ||
| >text</div> | ||
|
|
||
| <!-- biome-ignore suppression comment on an attribute --> | ||
| <div | ||
| // biome-ignore format: reason | ||
| class = "foo" | ||
| data-bar = "baz" | ||
| >text</div> | ||
|
|
||
| <!-- // comment on a self-closing Svelte component --> | ||
| <Component | ||
| // comment | ||
| prop="value" | ||
| /> | ||
|
|
||
| <!-- /* block comment */ on a self-closing Svelte component --> | ||
| <Component | ||
| /* block comment */ | ||
| prop="value" | ||
| /> | ||
|
|
||
| <!-- // biome-ignore suppression comment on a component attribute --> | ||
| <Component | ||
| // biome-ignore format: reason | ||
| prop="value" data-bar="baz" | ||
| /> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.