Repository navigation
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes sveltejs/language-tools#3151
Comments inside an opening tag were silently deleted in two cases:
Causes
attachAttributeCommentsonly looks at elements whoseattributesarray is non-empty, so a comment in<p /* c */>was never attached to anything and never printed.>inside a comment: the end of the opening tag was found withoriginal_text.indexOf('>', last_attr.end), which stops at the>inside the comment. A comment containing>after the last attribute fell outside that range and was dropped.Fix
findOpeningTagEndscans for the closing>while skipping over the known comment ranges, so a>inside a comment is never taken as the end of the tag.this={...}expression of<svelte:element>/<svelte:component>) and>are attached as dangling comments on the element. The element printer prints them where attributes would go (printDanglingTagComments). Line comments force the tag to break, and withbracketSameLinethe>moves to its own line so it isn't commented out.Tests
Added
test/printer/samples/attribute-comment-without-attributes.html, which covers block and line comments,>inside comments, self-closing and void elements, components,<svelte:element this>, and comments after an attribute. It fails onmasterand passes with this change. I also checked the output by hand with--bracket-same-lineand re-formatted it to make sure it's idempotent.pnpm test: 310 passedpnpm lint: passespnpm check: shows the same two errors as onmaster(estreetypes, implicitanyinprint/index.ts). This PR adds no new ones.Changeset included.