-
Notifications
You must be signed in to change notification settings - Fork 660
Normalize numeric literals #2442
Comments
This normalization is actually number-to-string from the spec. I think we can use https://crates.io/crates/ryu-js, it's from https://github.com/boa-dev/boa
|
This library accepts a float and converts it to a string. The formatter on the other hand operates on a string input. The library also looks rather complicated, I was hoping we would get away with something less sophisticated. For example, all that prettier does is to run some Regular Expressions:
|
Do you think we could achieve that with only string manipulation? We can't use regex unfortunately (it's better not to) |
hmm ... number parsing hasn't been used anywhere yet, maybe this is the time? I'm afraid that any adhoc algorithm will eventually end up similar to the number-to-string algorithm. tools/crates/rome_js_syntax/src/expr_ext.rs Lines 366 to 370 in a4702ba
|
Sure. A RegEx is just a state machine. The only question is how much code it requires. But I haven't looked into the implementation yet. I'm only concerned with finding all discrepancies. @Boshen I'm not sure if this is implementing the
Returns |
Duplicate of #3294 |
Prettier normalizes numeric literals, e.g. by removing unnecessarily trailing zeros but Rome doesn't. Playground
Input
Prettier
Rome
Expected
Rome to normalize octal, hex, and byte escapes as well as exponential formats the same as Prettier does.
The text was updated successfully, but these errors were encountered: