Skip to content

feat: allow comments in tags#17671

Open
Rich-Harris wants to merge 13 commits intomainfrom
comments-in-tags
Open

feat: allow comments in tags#17671
Rich-Harris wants to merge 13 commits intomainfrom
comments-in-tags

Conversation

@Rich-Harris
Copy link
Member

Alternative to #17188. I prefer this syntax, it's lighter and feels much more natural to me. For me it's less about commenting things out than about just, well... commenting — I frequently want to do this sort of thing:

<button
  // when the user clicks the button, the thing should happen
  onclick={doTheThing}
>click me</button>

One difference between this and #17188 is that this doesn't add a node to the AST, just like comments in CSS/JS. Haven't decided if that's desirable or not. I think it's more correct (it's an AST, not a CST; HTML comments are different insofar as they can represent 'real' nodes) but it might be less convenient when (for example) pretty-printing.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

@changeset-bot
Copy link

changeset-bot bot commented Feb 10, 2026

🦋 Changeset detected

Latest commit: b47ba90

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Rich-Harris Rich-Harris temporarily deployed to Publish pkg.pr.new (maintainers) February 10, 2026 20:29 — with GitHub Actions Inactive
@github-actions
Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@17671

@Rich-Harris
Copy link
Member Author

(note that this doesn't change anything in regard to syntax highlighting or language-tools etc; that would have to happen as a follow-up)

@Rich-Harris Rich-Harris temporarily deployed to Publish pkg.pr.new (maintainers) February 10, 2026 20:34 — with GitHub Actions Inactive
@dummdidumm
Copy link
Member

Nice idea! I have to see how much this would complicate/fuck up our TextMate syntax highlighting grammar. Also, for pretty printing this information absolutely must live somewhere, else it will just be deleted on format.

@Rich-Harris
Copy link
Member Author

JS/TS comments live on root.comments (demo):

image

What if we did the same for these?

@Rich-Harris Rich-Harris temporarily deployed to Publish pkg.pr.new (maintainers) February 10, 2026 21:14 — with GitHub Actions Inactive
@Rich-Harris Rich-Harris temporarily deployed to Publish pkg.pr.new (maintainers) February 10, 2026 21:19 — with GitHub Actions Inactive
@Rich-Harris Rich-Harris had a problem deploying to Publish pkg.pr.new (maintainers) February 10, 2026 22:09 — with GitHub Actions Failure
@Rich-Harris Rich-Harris temporarily deployed to Publish pkg.pr.new (maintainers) February 10, 2026 22:11 — with GitHub Actions Inactive
@Rich-Harris
Copy link
Member Author

alright, comments are now printing correctly if you use the included print(...) function. Doesn't help Prettier et al (which will just bail on this, at least for now) but is a necessary first step

@Rich-Harris Rich-Harris temporarily deployed to Publish pkg.pr.new (maintainers) February 10, 2026 22:21 — with GitHub Actions Inactive
@dummdidumm dummdidumm temporarily deployed to Publish pkg.pr.new (maintainers) February 11, 2026 16:15 — with GitHub Actions Inactive
@dummdidumm dummdidumm temporarily deployed to Publish pkg.pr.new (maintainers) February 11, 2026 17:15 — with GitHub Actions Inactive
@Rich-Harris Rich-Harris temporarily deployed to Publish pkg.pr.new (maintainers) February 11, 2026 18:03 — with GitHub Actions Inactive
@dummdidumm
Copy link
Member

adding prettier support was straightforward sveltejs/prettier-plugin-svelte#510, now still needs language tools support (or rather I need to check if it breaks stuff; and we need syntax highlighting)

@svelte-docs-bot
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments