-
Notifications
You must be signed in to change notification settings - Fork 658
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
[css-syntax] numeric separators #9293
Comments
Right, they're currently parsed as dimension tokens. I think there is some use of So the JS rules are that _ isn't allowed at the beginning or end of the number, and you can't have two in a row - So yeah, this is likely safe? So, specifically, we'd change steps 3, 4.2, and 5.3 of https://drafts.csswg.org/css-syntax/#consume-a-number to skip past single underscores followed by a digit, as long as we'd already seen at least one digit. |
Yes, although step 3, not 2? Haven't tested this through but this seems fairly straight forward : https://github.com/csstools/postcss-plugins/pull/1099/files It does make things a bit messier and there will be more lookahead:
-> advance 3 code points. whereas the current algorithm doesn't do any lookahead as long as the current codepoint is a digit. |
Yeah, a little more lookahead, but still within our current budget of 3 characters.
Yup, fixed. (And clarified step 4.2.) |
If long runs of decimal digits were an issue in CSS, I’d expect this to be fixed by introducing a new, better suited unit, which is a concept JS does not have (yet). The entire use case seems to be ”JS syntax compatibility for copy-pasting bare numbers“, when bare numbers are hardly used in CSS and a lot of JS’s number formats are not supported in CSS. Just to be clear, digit grouping is a good thing per se, I’m just not convinced that making breaking changes to the core grammar is sufficiently justified by ”JS has this“, especially since other, non-breaking changes with the same underlying intention (i.e. more units, e.g. #309) have regularly been rejected. |
This was quoted directly from the MDN docs page for the JS numeric separators. This proposal is only for
My current assumption is that this is non-breaking in practice. |
I'm not convinced this would be useful in CSS. The only case where I have seen big numbers is |
Probably more useful after the decimal point when using fractions that have lots of significant digits |
But browsers use layout units of 1/60 or 1/64 pixels, and CSSOM has a limit of 6 decimals. So I haven't seen authors using lots of decimal digits. |
Delays in JavaScript are in milliseconds and they can be fairly large numbers. Durations/delays were the main example I had in mind when submitting this. Dimensions with a Some samples from real CSS I have access to :
|
The CSS Working Group just discussed
The full IRC log of that discussion<dael> TabAtkins: Raised the topic that JS allows _ for numeric separators for numeric literals. If you have a large number with many digits it's hard to read. Suggestion is add them to CSS syntax as wel<Rossen_> q? <iank_> we can also change those units <dael> TabAtkins: I think this is safe to do. 1_000 is a dimension with value 1. We have a few places with _ prefix but it's not followed by digits. It's internal stuff. <dael> TabAtkins: Arguments against is not very valuable. Large and small numbers show up a lot in JS and precision is important. Much less the case in CSS. large numbers the important thing is they're big. Being able to tell a 6 vs 7 digit number apart for your page isn't common in practice. <dael> TabAtkins: Same with decimals. Pixels are limited to 1/64th or 1/60th. Much less than JS precision. <iank_> +1 to no change - doesn't seem super valuable. <astearns> +1 to no change <dael> TabAtkins: Basic argument against is we just don't need it. I'm inclined to go no change due to low need. But I think it's safe if someone wants to have it and I'm happy to make the change <smfr_> +1 to no change <iank_> (unless strong desire from community) <fantasai> +1 TO tAB'S ANALYSIS <dael> Rossen_: Proposal is raise awareness but don't add to CSS right now due to lack of use cases/user voices to add it <emeyer> +1 to no change (the only time I’ve ever seen long numbers is in z-index and precision wasn’t needed) <dael> Rossen_: Obj to resolving no change? <dael> RESOLVED: Don't add to CSS right now due to lack of use cases/user voices to add it <fantasai> s/TO tAB'S ANALYSIS/to Tab's analysis/ |
Per WG resolution, closing this as no change; the use-cases for large and small numbers in JS don't generally apply to CSS, which largely only needs values in a fairly small number of digits. People certainly write numbers with longer values (probably copied from a calculation done in JS or other language using doubles), but the exact value past the first few digits is rarely important. We're open to changing this if we get compelling, realistic use-cases where numbers with large numbers of digits (more than 6 on either side of the decimal point) are important to be able to distinguish fairly precisely. |
Agreed, thank you for considering this. |
In JavaScript you can use underscores as numeric separators.
This is purely syntax sugar.
From : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#numeric_separators
https://tc39.es/ecma262/multipage/ecmascript-language-lexical-grammar.html#prod-NumericLiteralSeparator
CSS number tokens and JS number tokens are mostly the same.
This makes it easy to copy/paste values between the two languages.
It would be nice if CSS also has support for numeric separators, for the same reasons as why they were added to JavaScript and to make it easier to copy/paste from JavaScript to CSS.
As far as I can tell these sequences do not form useful tokens in todays syntax.
1_000_000_000_000
is a dimension token with a value of1
and a unit of_000_000_000_000
.The text was updated successfully, but these errors were encountered: