-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
fix: throw on invalid attribute expressions #11736
fix: throw on invalid attribute expressions #11736
Conversation
🦋 Changeset detectedLatest commit: f320272 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 |
TBH I'm not totally sure if we should even error here. As you point, out |
This will not error on |
I think we should error on It's also just inconsistent that Is that a breaking change too far? |
You're right that it's inconsistent, and I would be ok with requiring quotes in this situation. I fear that breaking change though - can we parse it like before but move the error to the validation phase for runes mode only? i.e. only in runes mode it's an error |
I think it's doable...let me try. P.s. this means that <button
onclick={() => console.log('hello')}}
another={'hello'}}
>
click
</button> will have the same error as today in rune mode right? |
A couple of things:
|
You can know if something is quoted like so: function is_quoted(attribute) {
if (attribute.value === true) return false;
return attribute.value.at(-1).end !== attribute.end;
} |
Ok so it's fine to do it like this (which is simpler but similar to what i come up with 😄 thanks) |
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.
Thank you!
Svelte 5 rewrite
Closes #11734
Initially i went with: if there's not a quote mark and the value returned is more than a single expression there's a problem. But there's some weird and probably old svelte that you can write that was failing
that will result in
so i had to check for if we are in a mustache with
parser.match('{')
.Tests are all passing and it does seem to work so i guess my assumption that mustache tags can only return one expression is correct. If it is a string then the closing tag either is a quote or is the monstrosity up above and we can't really do much about this error imho.
Please note that the Svelte codebase is currently being rewritten for Svelte 5. Changes should target Svelte 5, which lives on the default branch (
main
).If your PR concerns Svelte 4 (including updates to svelte.dev.docs), please ensure the base branch is
svelte-4
and notmain
.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