-
-
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: allow for arrays in member access in directives #11470
base: main
Are you sure you want to change the base?
fix: allow for arrays in member access in directives #11470
Conversation
🦋 Changeset detectedLatest commit: df749d4 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 |
This fails with e.g. |
Wait really? I remember specifically testing for those cases. Can you approve the deploy on vercel so I can take a look? I'm on my phone |
Btw I agree that this kind of stuff is pretty un-useful |
With this <script>
let arr = $state([[()=>{}]])
</script>
<button use:arr[0][0]>
clicks
</button> the generated code is import * as $ from "svelte/internal/client";
var root = $.template(`<button>clicks</button>`);
export default function App($$anchor) {
let arr = $.proxy([[() => {}]]);
var button = root();
$.action(button, ($$node) => arr[0][0]($$node));
$.append($$anchor, button);
} which is correct and doesn't errors out. With this <script>
let x = $state({"y-z": ()=>{}})
</script>
<button use:x.y-z>
clicks
</button> the generated code is import * as $ from "svelte/internal/client";
var root = $.template(`<button>clicks</button>`);
export default function App($$anchor) {
let x = $.proxy({ "y-z": () => {} });
var button = root();
$.action(button, ($$node) => x["y-z"]($$node));
$.append($$anchor, button);
} which is also correct and doesn't errors out. Were you referring to a different code? You can't do this <script>
let x = $state({"y-z": ()=>{}})
</script>
<button use:x["y-z"]>
clicks
</button> but that's actually a parsing error in svelte. We could fix it but i'ts not worth imho |
Huh, weird — I could have sworn it was failing for me locally with |
Classic old version of the compiler still in cache or yet to finish build? Sometimes it even happen between refreshes if roll-up is a tad slower. I tested all it came to mind but if there's some case not covered I'm happy to add that |
Svelte 5 rewrite
Closes #11467 ...this uses a slightly more advanced regex to determine if a part of a member access should use a literal or an identifier to access it.
I've also added the code to handle this absurd situation
i don't know if actually want to remove this and just ignore this case 😄
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