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

Improve error message for invalid attribute values #208

Closed
lambda-fairy opened this issue Sep 6, 2020 · 5 comments · Fixed by #265
Closed

Improve error message for invalid attribute values #208

lambda-fairy opened this issue Sep 6, 2020 · 5 comments · Fixed by #265

Comments

@lambda-fairy
Copy link
Owner

lambda-fairy commented Sep 6, 2020

Currently, when the user types in:

input type="number" min=0 max=100;

or

script src="pinkie.js" defer=true;

or

.col-sm-2 {}

they get the error "expected string". This is technically correct but I think we can do better.

  • For number literals (integer or float), suggest wrapping the number in quotes.
  • For boolean literals, suggest removing the =true bit altogether.
@CreepySkeleton
Copy link
Contributor

CreepySkeleton commented Sep 7, 2020

For example, 0x2a and 0.99999999999999999999999 will be parsed as 42 and 1.0 respectively.

Actually, while Literal::* methods do lose precision, impl FromStr for TokenStream and Display seem to be able to round-trip number literals loselessly. There rest is pretty easy.

@lambda-fairy
Copy link
Owner Author

Ah, that's interesting. I'm still against allowing that, though, as it means that factoring out a variable can change the result:

html! { 0x2a }  // "0x2a"

let ponk = 0x2a;
html! { (ponk) }  // "42"

@CreepySkeleton
Copy link
Contributor

CreepySkeleton commented Sep 8, 2020

But ponk is not a literal, it's an identifier. It shouldn't be a subject for suggestions in the first place.

@lambda-fairy
Copy link
Owner Author

To clarify, I mean that so far it's been true that adding parentheses () to a literal doesn't change it:

html! { "ponk" }  // "ponk"
html! { ("ponk") }  // "ponk"

But allowing bare number literals will break this property:

html! { 0x2a }  // "0x2a"
html! { (0x2a) }  // "42"

@lambda-fairy
Copy link
Owner Author

lambda-fairy commented Mar 13, 2021

#265 improves the error message for non-string literals in element bodies and attribute values.

But it doesn't handle the class/ID shorthand case (.col-sm-2). I'll file a follow-up issue to address that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants