-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: include script
and svelte:options
attributes in ast
#11241
Conversation
🦋 Changeset detectedLatest commit: 4299721 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems very sensible to me — @dummdidumm any thoughts on this from a language-tools perspective?
We can't allow expression attributes on the script tag because |
But we could do that, no? The parser would treat that as a text attribute regardless of the |
I've added a test for that, and it seems it's trated literally: {
"type": "Attribute",
"start": 132,
"end": 168,
"name": "generics",
"value": [
{
"start": 142,
"end": 167,
"type": "Text",
"raw": "T extends { foo: number }",
"data": "T extends { foo: number }"
}
]
}
I'll check how it works in sveltejs/prettier-plugin-svelte#436. |
It worked, I was able to delete |
Push it anyway 😁 it's fine if the PR fails in CI for a few days, we just don't merge until this goes in. |
@dummdidumm Here you go: sveltejs/prettier-plugin-svelte@ |
thank you! |
In Svelte 4 AST,
script
tags (root.instance
androot.module
) do not have attributes, andprettier-plugin-svelte
has to extract them using regex (https://github.com/sveltejs/prettier-plugin-svelte/blob/b120c4de5faa6ca6fa0c6867d6048e1dd1b958ca/src/lib/extractAttributes.ts).With Svelte 5 (modern AST), the same now applies to
svelte:options
tag. However, unlikescript
, it can also have expression attributes:Currently,
extractAttributes
can only handle string attributes. If we included attributes for these elements in AST, we could remove this function altogether, instead of improving it to also parse expression attributes.Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint