mirror of https://github.com/sveltejs/svelte
feat: allow comments in tags (#17671)
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>pull/17747/head
parent
2661513cd3
commit
92e2fc1209
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
feat: allow comments in tags
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
<div
|
||||||
|
data-one="1"
|
||||||
|
// this is a line comment
|
||||||
|
data-two="2"
|
||||||
|
/* this is a
|
||||||
|
m
|
||||||
|
u
|
||||||
|
l
|
||||||
|
t
|
||||||
|
i
|
||||||
|
l
|
||||||
|
i
|
||||||
|
n
|
||||||
|
e
|
||||||
|
comment
|
||||||
|
*/
|
||||||
|
// oh look another line comment
|
||||||
|
// (two, in fact)
|
||||||
|
data-three="3"
|
||||||
|
></div>
|
||||||
|
|
||||||
|
<span /* inline */ /* another inline */ data-one="1"></span>
|
||||||
@ -0,0 +1,286 @@
|
|||||||
|
{
|
||||||
|
"css": null,
|
||||||
|
"js": [],
|
||||||
|
"start": 0,
|
||||||
|
"end": 261,
|
||||||
|
"type": "Root",
|
||||||
|
"fragment": {
|
||||||
|
"type": "Fragment",
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"type": "RegularElement",
|
||||||
|
"start": 0,
|
||||||
|
"end": 199,
|
||||||
|
"name": "div",
|
||||||
|
"name_loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 1,
|
||||||
|
"character": 1
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 4,
|
||||||
|
"character": 4
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"attributes": [
|
||||||
|
{
|
||||||
|
"type": "Attribute",
|
||||||
|
"start": 6,
|
||||||
|
"end": 18,
|
||||||
|
"name": "data-one",
|
||||||
|
"name_loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 2,
|
||||||
|
"column": 1,
|
||||||
|
"character": 6
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 2,
|
||||||
|
"column": 9,
|
||||||
|
"character": 14
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"start": 16,
|
||||||
|
"end": 17,
|
||||||
|
"type": "Text",
|
||||||
|
"raw": "1",
|
||||||
|
"data": "1"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Attribute",
|
||||||
|
"start": 47,
|
||||||
|
"end": 59,
|
||||||
|
"name": "data-two",
|
||||||
|
"name_loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 4,
|
||||||
|
"column": 1,
|
||||||
|
"character": 47
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 4,
|
||||||
|
"column": 9,
|
||||||
|
"character": 55
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"start": 57,
|
||||||
|
"end": 58,
|
||||||
|
"type": "Text",
|
||||||
|
"raw": "2",
|
||||||
|
"data": "2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Attribute",
|
||||||
|
"start": 177,
|
||||||
|
"end": 191,
|
||||||
|
"name": "data-three",
|
||||||
|
"name_loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 19,
|
||||||
|
"column": 1,
|
||||||
|
"character": 177
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 19,
|
||||||
|
"column": 11,
|
||||||
|
"character": 187
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"start": 189,
|
||||||
|
"end": 190,
|
||||||
|
"type": "Text",
|
||||||
|
"raw": "3",
|
||||||
|
"data": "3"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"fragment": {
|
||||||
|
"type": "Fragment",
|
||||||
|
"nodes": []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Text",
|
||||||
|
"start": 199,
|
||||||
|
"end": 201,
|
||||||
|
"raw": "\n\n",
|
||||||
|
"data": "\n\n"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "RegularElement",
|
||||||
|
"start": 201,
|
||||||
|
"end": 261,
|
||||||
|
"name": "span",
|
||||||
|
"name_loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 22,
|
||||||
|
"column": 1,
|
||||||
|
"character": 202
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 22,
|
||||||
|
"column": 5,
|
||||||
|
"character": 206
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"attributes": [
|
||||||
|
{
|
||||||
|
"type": "Attribute",
|
||||||
|
"start": 241,
|
||||||
|
"end": 253,
|
||||||
|
"name": "data-one",
|
||||||
|
"name_loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 22,
|
||||||
|
"column": 40,
|
||||||
|
"character": 241
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 22,
|
||||||
|
"column": 48,
|
||||||
|
"character": 249
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"start": 251,
|
||||||
|
"end": 252,
|
||||||
|
"type": "Text",
|
||||||
|
"raw": "1",
|
||||||
|
"data": "1"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"fragment": {
|
||||||
|
"type": "Fragment",
|
||||||
|
"nodes": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"options": null,
|
||||||
|
"comments": [
|
||||||
|
{
|
||||||
|
"type": "Line",
|
||||||
|
"start": 20,
|
||||||
|
"end": 45,
|
||||||
|
"value": " this is a line comment",
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 3,
|
||||||
|
"column": 1,
|
||||||
|
"character": 20
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 3,
|
||||||
|
"column": 26,
|
||||||
|
"character": 45
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Block",
|
||||||
|
"start": 61,
|
||||||
|
"end": 123,
|
||||||
|
"value": " this is a\n\t\tm\n\t\tu\n\t\tl\n\t\tt\n\t\ti\n\t\tl\n\t\ti\n\t\tn\n\t\te\n\t\tcomment\n\t",
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 5,
|
||||||
|
"column": 1,
|
||||||
|
"character": 61
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 16,
|
||||||
|
"column": 3,
|
||||||
|
"character": 123
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Line",
|
||||||
|
"start": 125,
|
||||||
|
"end": 156,
|
||||||
|
"value": " oh look another line comment",
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 17,
|
||||||
|
"column": 1,
|
||||||
|
"character": 125
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 17,
|
||||||
|
"column": 32,
|
||||||
|
"character": 156
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Line",
|
||||||
|
"start": 158,
|
||||||
|
"end": 175,
|
||||||
|
"value": " (two, in fact)",
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 18,
|
||||||
|
"column": 1,
|
||||||
|
"character": 158
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 18,
|
||||||
|
"column": 18,
|
||||||
|
"character": 175
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Block",
|
||||||
|
"start": 207,
|
||||||
|
"end": 219,
|
||||||
|
"value": " inline ",
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 22,
|
||||||
|
"column": 6,
|
||||||
|
"character": 207
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 22,
|
||||||
|
"column": 18,
|
||||||
|
"character": 219
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Block",
|
||||||
|
"start": 220,
|
||||||
|
"end": 240,
|
||||||
|
"value": " another inline ",
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 22,
|
||||||
|
"column": 19,
|
||||||
|
"character": 220
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 22,
|
||||||
|
"column": 39,
|
||||||
|
"character": 240
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Loading…
Reference in new issue