Skip to content
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

Cannot bind to MemberExpression #14341

Closed
HanielU opened this issue Nov 18, 2024 · 1 comment
Closed

Cannot bind to MemberExpression #14341

HanielU opened this issue Nov 18, 2024 · 1 comment

Comments

@HanielU
Copy link

HanielU commented Nov 18, 2024

Describe the bug

When trying to bind: to a MemberExpression (e.g bind:checked={checked(true).current}) Svelte throws the error:

Can only bind to an Identifier or MemberExpression

Here's a simple snippet highlighting the issue:

<script>
  const state = $state({
    checked: true,
  });

  const store = Object.fromEntries(
    Object.keys(state).map(key => [
      key,
      (current = false) => {
        return current
          ? {
              get current() {
                return state[key];
              },
              set current(value) {
                state[key] = value;
              },
            }
          : state[key];
      },
    ])
  );
</script>

<!-- This causes the error ❌ -->
<input type="checkbox" bind:checked={store.checked(true).current} />

Reproduction

Here's a REPL

Logs

No response

System Info

Playground version 5.2.2

Severity

annoyance

@trueadm
Copy link
Contributor

trueadm commented Nov 18, 2024

You cannot bind to a call expression, which store.checked(true).current contains. This has always been a constraint of bind and if #14307 lands then you'll be able to work around this constraint :)

@trueadm trueadm closed this as not planned Won't fix, can't repro, duplicate, stale Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants