-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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: allow for literal property definition with state on classes #11326
feat: allow for literal property definition with state on classes #11326
Conversation
🦋 Changeset detectedLatest commit: 99d3a06 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 |
packages/svelte/src/compiler/phases/3-transform/client/visitors/javascript-runes.js
Outdated
Show resolved
Hide resolved
} | ||
create_state_field(definition, is_private, name); | ||
} else if (definition.type === 'PropertyDefinition' && definition.key.type === 'Literal') { | ||
const name = definition.key.value?.toString().replace('-', '_'); |
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.
Don't think this is enough - there could be all sorts of whacky characters in there, better to use a "non-valid ID identifier" regex (I believe there exists one already)
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.
Oh great, yesterday I started to think of other invalid characters but nothing come to mind...I'll update soon
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.
Also just realized I need replaceAll
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.
@dummdidumm fixed it in the new commit...should i add more tests for all the same thing that were tested with normal identifiers?
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
Kinda closes #11316: although the code in their repro will still not work because you can't spread classes into arguments this allow to create properties with literals like
that get's compiled to
i've added a single test for this but i'm wondering if i should add a test for each class test that was already there (in theory it should already be covered because they share the same code but you know)
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