feat: Add ability to comment out attributes#17188
feat: Add ability to comment out attributes#17188Teiem wants to merge 3 commits intosveltejs:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 85242fc The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
|
One workaround I use is to add an underscore ( <Button _color="blue">This works except for svelte-check getting cranky. also if I'm trying a few options I will add additional underscores: <Button _color="blue" __color="red" color="green">Having a way to comment out attributes similar to React would be great though! |
|
Thank you. I'm not personally sold on the syntax, it feels quite heavy to me, and it's something people have to learn. I'd rather be able to just use the same comments I already use in JS/TS. Opened #17671 as an alternative. |
|
Going to go ahead and close this in favour of #17671, since it now also works with |
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: ```svelte <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 - [x] 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 - [x] Prefix your PR title with `feat:`, `fix:`, `chore:`, or `docs:`. - [x] This message body should clearly illustrate what problems it solves. - [x] Ideally, include a test that fails without this PR but passes with it. - [x] If this PR changes code within `packages/svelte/src`, add a changeset (`npx changeset`). ### Tests and linting - [x] Run the tests with `pnpm test` and lint the project with `pnpm lint` --------- Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
Relevant RFC, specifically this comment which has the most upvotes.
In short, this PR would allow comments in the form of
{/* some comment*/}where an html attribute is expected, e.g.This would be useful to quickly comment out single attributes of an HTML element.
What does not work is using this to comment out the entire tag, for that we already have normal html comments (
<!-- -->).Implementation wise this is an empty attribute which will then be ignored by the parser.
Before submitting the PR, please make sure you do the following
feat:,fix:,chore:, ordocs:.packages/svelte/src, add a changeset (npx changeset).Tests and linting
pnpm testand lint the project withpnpm lint