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

Throw a warning if we are declaring a variable with const and also using bind directive to mutate its value. #4479

Closed
kanishk30 opened this issue Feb 27, 2020 · 5 comments · Fixed by #4506
Labels
feature request good first issue A small, encapsulated issue, ideal for a new contributor to Svelte to tackle.

Comments

@kanishk30
Copy link

Is your feature request related to a problem? Please describe.
While defining a variable in #Svelte, make sure to use let/var and not const, otherwise those bindings won't work, as it can't be updated by its compiler.
image

Describe the solution you'd like
Throw a warning or error.

Describe alternatives you've considered
Using let always.

How important is this feature to you?
It brings a delight to users.

@Conduitry
Copy link
Member

This sounds reasonable. I think I'd favor an outright compilation error in this case. We need to be careful though because binding to foo.bar when foo is a const should continue to be valid.

@kanishk30
Copy link
Author

Yes absolutely. Making sure that primitives cannot be mutated once assigned with const. Sounds reasonable?

@antony antony added the good first issue A small, encapsulated issue, ideal for a new contributor to Svelte to tackle. label Feb 27, 2020
@tanhauhau
Copy link
Member

tanhauhau commented Feb 29, 2020

Some pointers for getting started on the good first issue:

  1. Read our Contribution Guide
  2. We checked whether the bind: variable is defined or not here in src/compiler/compile/nodes/Binding.ts
    • You can add another check to see whether the variable can be mutated.
    • Exhaustive list of the properties of the variables can be found in the vars section of the doc
  3. tests for compile time validation goes into the test/validator/ folder (you can refer to this test sample)

@vlasy
Copy link
Contributor

vlasy commented Mar 4, 2020

I am working on this. I already have a working implementation, but need to fix some tests.

@kanishk30
Copy link
Author

sure @vlasy . Was planning to pick it up this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request good first issue A small, encapsulated issue, ideal for a new contributor to Svelte to tackle.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants