-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: tweak script/style tag parsing/preprocessing logic
Related to sveltejs/language-tools#2204 / sveltejs/language-tools#2039 The Svelte 5 version of #9486 and #9498
- Loading branch information
1 parent
37f2493
commit 1807e88
Showing
8 changed files
with
217 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'svelte': patch | ||
--- | ||
|
||
fix: tweak script/style tag parsing/preprocessing logic |
This file contains 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
This file contains 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
5 changes: 5 additions & 0 deletions
5
packages/svelte/tests/parser-legacy/samples/script-attribute-with-curly-braces/input.svelte
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<script generics="T extends { yes: boolean }"> | ||
let name = 'world'; | ||
</script> | ||
|
||
<h1>Hello {name}!</h1> |
150 changes: 150 additions & 0 deletions
150
packages/svelte/tests/parser-legacy/samples/script-attribute-with-curly-braces/output.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
{ | ||
"html": { | ||
"start": 79, | ||
"end": 101, | ||
"type": "Fragment", | ||
"children": [ | ||
{ | ||
"start": 77, | ||
"end": 79, | ||
"type": "Text", | ||
"raw": "\n\n", | ||
"data": "\n\n" | ||
}, | ||
{ | ||
"start": 79, | ||
"end": 101, | ||
"type": "Element", | ||
"name": "h1", | ||
"attributes": [], | ||
"children": [ | ||
{ | ||
"start": 83, | ||
"end": 89, | ||
"type": "Text", | ||
"raw": "Hello ", | ||
"data": "Hello " | ||
}, | ||
{ | ||
"start": 89, | ||
"end": 95, | ||
"type": "MustacheTag", | ||
"expression": { | ||
"type": "Identifier", | ||
"start": 90, | ||
"end": 94, | ||
"loc": { | ||
"start": { | ||
"line": 5, | ||
"column": 11 | ||
}, | ||
"end": { | ||
"line": 5, | ||
"column": 15 | ||
} | ||
}, | ||
"name": "name" | ||
} | ||
}, | ||
{ | ||
"start": 95, | ||
"end": 96, | ||
"type": "Text", | ||
"raw": "!", | ||
"data": "!" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"instance": { | ||
"type": "Script", | ||
"start": 0, | ||
"end": 77, | ||
"context": "default", | ||
"content": { | ||
"type": "Program", | ||
"start": 46, | ||
"end": 68, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 0 | ||
} | ||
}, | ||
"body": [ | ||
{ | ||
"type": "VariableDeclaration", | ||
"start": 48, | ||
"end": 67, | ||
"loc": { | ||
"start": { | ||
"line": 2, | ||
"column": 1 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 20 | ||
} | ||
}, | ||
"declarations": [ | ||
{ | ||
"type": "VariableDeclarator", | ||
"start": 52, | ||
"end": 66, | ||
"loc": { | ||
"start": { | ||
"line": 2, | ||
"column": 5 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 19 | ||
} | ||
}, | ||
"id": { | ||
"type": "Identifier", | ||
"start": 52, | ||
"end": 56, | ||
"loc": { | ||
"start": { | ||
"line": 2, | ||
"column": 5 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 9 | ||
} | ||
}, | ||
"name": "name" | ||
}, | ||
"init": { | ||
"type": "Literal", | ||
"start": 59, | ||
"end": 66, | ||
"loc": { | ||
"start": { | ||
"line": 2, | ||
"column": 12 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 19 | ||
} | ||
}, | ||
"value": "world", | ||
"raw": "'world'" | ||
} | ||
} | ||
], | ||
"kind": "let" | ||
} | ||
], | ||
"sourceType": "module" | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/svelte/tests/preprocess/samples/attributes-with-closing-tag/_config.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
preprocess: { | ||
script: ({ attributes }) => | ||
typeof attributes.generics === 'string' && attributes.generics.includes('>') | ||
? { code: '' } | ||
: undefined | ||
} | ||
}); |
3 changes: 3 additions & 0 deletions
3
packages/svelte/tests/preprocess/samples/attributes-with-closing-tag/input.svelte
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<script generics="T extends Record<string, string>"> | ||
foo {} | ||
</script> |
1 change: 1 addition & 0 deletions
1
packages/svelte/tests/preprocess/samples/attributes-with-closing-tag/output.svelte
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<script generics="T extends Record<string, string>"></script> |