mirror of https://github.com/sveltejs/svelte
fix: don't mistake `type` identifier expressions for TS `type` declarations in tags (#18330)
Detect TypeScript `type` declarations by actually parsing instead of by
character-class blacklists, so that expressions like `{type === 'all' ?
a : b}` or `{type instanceof Foo}` aren't misclassified as malformed
declarations.
Closes #18328
---------
Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
pull/18351/head
parent
b76b937e00
commit
c74f44fff9
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: more robust parsing of declaration tags with regards to `type`
|
||||
@ -1,4 +1,5 @@
|
||||
{#if true}
|
||||
{let }
|
||||
{const x = }
|
||||
{let x = a / }
|
||||
{/if}
|
||||
|
||||
@ -0,0 +1 @@
|
||||
{type instanceof /* probe */ Object}
|
||||
@ -0,0 +1,92 @@
|
||||
{
|
||||
"css": null,
|
||||
"js": [],
|
||||
"start": 0,
|
||||
"end": 36,
|
||||
"type": "Root",
|
||||
"fragment": {
|
||||
"type": "Fragment",
|
||||
"nodes": [
|
||||
{
|
||||
"type": "ExpressionTag",
|
||||
"start": 0,
|
||||
"end": 36,
|
||||
"expression": {
|
||||
"type": "BinaryExpression",
|
||||
"start": 1,
|
||||
"end": 35,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 35
|
||||
}
|
||||
},
|
||||
"left": {
|
||||
"type": "Identifier",
|
||||
"start": 1,
|
||||
"end": 5,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 5
|
||||
}
|
||||
},
|
||||
"name": "type"
|
||||
},
|
||||
"operator": "instanceof",
|
||||
"right": {
|
||||
"type": "Identifier",
|
||||
"start": 29,
|
||||
"end": 35,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 29
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 35
|
||||
}
|
||||
},
|
||||
"name": "Object",
|
||||
"leadingComments": [
|
||||
{
|
||||
"type": "Block",
|
||||
"value": " probe ",
|
||||
"start": 17,
|
||||
"end": 28
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"options": null,
|
||||
"comments": [
|
||||
{
|
||||
"type": "Block",
|
||||
"value": " probe ",
|
||||
"start": 17,
|
||||
"end": 28,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 17
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 28
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
Reference in new issue