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

fix(css_parser): accept more valid CSS identifiers #3771

Merged
merged 1 commit into from
Sep 3, 2024

Conversation

Conaclos
Copy link
Member

@Conaclos Conaclos commented Sep 3, 2024

Summary

Fix #3627

CSS allows a wider rang e of characters for identifiers than JS:

ident-start code point
    A letter, a non-ASCII ident code point, or U+005F LOW LINE (_). 
ident code point
    An ident-start code point, a digit, or U+002D HYPHEN-MINUS (-).
non-ASCII ident code point
    A [code point](https://infra.spec.whatwg.org/#code-point) whose value is any of:
        U+00B7
        between U+00C0 and U+00D6
        between U+00D8 and U+00F6
        between U+00F8 and U+037D
        between U+037F and U+1FFF
        U+200C
        U+200D
        U+203F
        U+2040
        between U+2070 and U+218F
        between U+2C00 and U+2FEF
        between U+3001 and U+D7FF
        between U+F900 and U+FDCF
        between U+FDF0 and U+FFFD
        greater than or equal to U+10000

Why these character, specifically?

This matches the list of non-ASCII codepoints allowed to be used in HTML valid custom element names. It excludes a number of characters that appear as whitespace, or that can cause rendering or parsing issues in some tools, such as the direction override codepoints.

Note that this is a weaker set of restrictions than UAX 31 recommends for identifiers (used by languages such as JavaScript to restrict their identifier syntax), allowing things such as starting an identifier with a combining character. Consistency with HTML custom element names (and thus, the ability to write selectors for all custom elements without having to use escapes) was considered valuable, and the set of characters restricted by HTML covers the "high value" restrictions well.

Test Plan

I added a test.

@github-actions github-actions bot added A-Parser Area: parser L-CSS Language: CSS A-Changelog Area: changelog labels Sep 3, 2024
@github-actions github-actions bot added the A-Formatter Area: formatter label Sep 3, 2024
@Conaclos Conaclos merged commit 73656ec into main Sep 3, 2024
14 checks passed
@Conaclos Conaclos deleted the conaclos/css-ident-parsing branch September 3, 2024 14:38
Copy link

codspeed-hq bot commented Sep 3, 2024

CodSpeed Performance Report

Merging #3771 will degrade performances by 17.31%

Comparing conaclos/css-ident-parsing (1b9e8dd) with main (0b83351)

Summary

⚡ 15 improvements
❌ 1 regressions
✅ 83 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main conaclos/css-ident-parsing Change
css_formatter[semantic_2402227530816031580.css] 299.2 ms 361.9 ms -17.31%
bootstrap_18416142857265205439.css[cached] 47.6 ms 42 ms +13.16%
bootstrap_18416142857265205439.css[uncached] 51.2 ms 45.7 ms +11.87%
bulma_15117074458139280020.css[cached] 45.2 ms 40.3 ms +12.24%
bulma_15117074458139280020.css[uncached] 49.3 ms 44.3 ms +11.5%
foundation_7285025277362245733.css[cached] 30.1 ms 27.2 ms +10.52%
foundation_7285025277362245733.css[uncached] 32.7 ms 29.5 ms +10.54%
full_5814491140539129161.css[cached] 503.7 ms 463.6 ms +8.66%
full_5814491140539129161.css[uncached] 530 ms 485.7 ms +9.12%
materialize_13055388268705992476.css[cached] 33.6 ms 30.1 ms +11.54%
materialize_13055388268705992476.css[uncached] 36.5 ms 33.1 ms +10.36%
pure_9395922602181450299.css[cached] 3.9 ms 3.5 ms +12.35%
pure_9395922602181450299.css[uncached] 4.5 ms 4.1 ms +9.3%
semantic_2402227530816031580.css[cached] 143.6 ms 128.3 ms +11.91%
semantic_2402227530816031580.css[uncached] 153.3 ms 136.6 ms +12.29%
tachyons_9066552643484828443.css[cached] 21.5 ms 20 ms +7.57%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Changelog Area: changelog A-Formatter Area: formatter A-Parser Area: parser L-CSS Language: CSS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 emoji not supported in CSS parser
2 participants