-
Notifications
You must be signed in to change notification settings - Fork 324
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
chore: Add new style-value-parser package #743
base: main
Are you sure you want to change the base?
Conversation
workflow: benchmarks/sizeComparison of minified (terser) and compressed (brotli) size results, measured in bytes. Smaller is better.
|
0a83c00
to
4b70761
Compare
6c30646
to
21b5475
Compare
21b5475
to
36fc22d
Compare
I have rebased and squashed this branch to two commits. The first commit is everything that was in this PR so far. The second commit and future commits will be used as an experiment to try to use a tokenizer to speed up the parser. So far, the build performance has been the blocker to shipping this parser. |
I feel fairly confident that the new parser implementation is fast enough: > @stylexjs/[email protected] benchmark
> babel-node src/__benchmarks__/alpha-value.bench.js
Original Parser x 692 ops/sec ±4.18% (43 runs sampled)
Token Parser x 18,246 ops/sec ±0.44% (86 runs sampled)
Fastest is Token Parser |
Why Parser
How
|
cd0dbb5
to
609fd30
Compare
Some interesting data from adding more benchmarks:
|
56c7fe9
to
2187f31
Compare
Background
We're currently using
postcss-value-parser
for a few purposes but it is quite rudimentary.lightningcss
was considered but its API only parses entire CSS files and not individual values. It would also be a very heavy tool for what we need as it's an entire CSS post-processor. It would also allow all valid CSS and it would be more difficult to manually add our own constraints to it.New CSS Value Parser
This PR introduces a new parser which have been tailored for StyleX:
box-shadow
..toString()
methods will output normalised strings for various valuescm
andinch
topx
.How it will be used
This parser will be used to :
@media
queries in order to add additional guarantees for them.How complete is it?
There should already be parser for every CSS type.
There are a few style property specific parsers that composing together the "type" parsers. These are there as examples to get us started. These need to be updated to allow CSS variables being used in various positions.
There are many unit tests, but test coverage could be improved. Specially for the
toString
methods.