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

Attributes with values like "20vw" get converted incorrectly #234

Closed
PaulBGD opened this issue Dec 31, 2016 · 4 comments · Fixed by #235
Closed

Attributes with values like "20vw" get converted incorrectly #234

PaulBGD opened this issue Dec 31, 2016 · 4 comments · Fixed by #235

Comments

@PaulBGD
Copy link
Member

PaulBGD commented Dec 31, 2016

Sample repo: https://github.com/PaulBGD/svelte-pass-number

Basically comes down to this line of code:

const result = isNaN( parseFloat( value.data ) ) ? JSON.stringify( value.data ) : value.data;

Attributes that start with a number like <Comp value="10px" gets parsed into the number 10 by parseFloat so it outputs it as

initialData = {
  value: 10vw // throws parse error here
}

I suggest replacing the isNaN check with

String(parseFloat(value.data)) !== value.data

or something that better checks if it's a number or not.

@Ryuno-Ki
Copy link

Ryuno-Ki commented Jan 4, 2017

Hope, that you never encounter an input with leading zero … that is, better pass 10 as second parameter to parseFloat to denote the base (leading zero leads to interpretation as octal number).

@mrkishi
Copy link
Member

mrkishi commented Jan 4, 2017

@Ryuno-Ki That's not a thing for parseFloat: there's no radix argument. For parseInt, I believe it's not a problem for IE9+ support.

@Ryuno-Ki
Copy link

Ryuno-Ki commented Jan 4, 2017

Looking it up on MDN and you're right.

@Rich-Harris
Copy link
Member

Either way, we're using isNaN now

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

Successfully merging a pull request may close this issue.

4 participants