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

Better error message on invalid ref names, or allow ref names with dashes. #1613

Closed
mhkeller opened this issue Jul 25, 2018 · 3 comments
Closed

Comments

@mhkeller
Copy link

I like using ref names in my CSS so I'm often tempted to use dash-style names such as ref:chart-container. If I use a dash, though, I get a cryptic error Assigning to rvalue. This took me a little while to figure out what I was doing wrong but it's because I believe the compiler creates code like this.refs.chart-container, which obviously isn't proper JavaScript. Here's the error in the REPL

screen shot 2018-07-24 at 10 48 26 pm

It would be a nice to have but I don't really care if I can't (or shouldn't) use dashed names for whatever reason. If the error message can be improved, though, that would be great!

@GarrettGeorge
Copy link

Did some initial digging. The rvalue error is actually from the acorn parser located here.
Obviously that doesn't mean an issue needs to be made for Acorn but rather the Svelte code needs to be checking for that.

This is my first attempt at contributing to Svelte so let me know if this evaluation is incorrect, but we need to either

  1. (the simpler case?) Throw a more specific error indicating foo-bar is invalid.

or

  1. Allow foo-bar references by having the compiler output this.refs['chart-container'] instead of the invalid this.refs.chart-container.

@mhkeller
Copy link
Author

mhkeller commented Aug 6, 2018

Thanks @GarrettGeorge!

@Rich-Harris
Copy link
Member

Released @GarrettGeorge's fix in 2.9.11 — thanks

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

3 participants