feat(parse/tailwind): differentiate between number and non-number values#10332
Conversation
|
Parser conformance results onjs/262
jsx/babel
markdown/commonmark
symbols/microsoft
ts/babel
ts/microsoft
|
Merging this PR will not alter performance
Comparing Footnotes
|
cb522cf to
c6004a8
Compare
WalkthroughThis change extends the Tailwind parser to recognise and correctly parse numeric and percentage values. The lexer gains a Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/biome_tailwind_parser/tests/tailwind_specs/ok/simple/ratio-value.txt (1)
1-1: 💤 Low valueConsider renaming this fixture.
The filename suggests a ratio value type, but
w-3/4is actually parsed as a number value (3) followed by a modifier (/4). Perhapsnumber-with-modifier.txtorfractional-modifier.txtwould be clearer? Not a blocker, just a thought.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/biome_tailwind_parser/tests/tailwind_specs/ok/simple/ratio-value.txt` at line 1, The fixture filename ratio-value.txt is misleading because the content "w-3/4" parses as a numeric value with a fractional modifier; rename the test file to something clearer (e.g., number-with-modifier.txt or fractional-modifier.txt) and update any references to the fixture in tests or test harness to use the new name so the filename matches the parsed token structure.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@crates/biome_tailwind_parser/tests/tailwind_specs/ok/simple/ratio-value.txt`:
- Line 1: The fixture filename ratio-value.txt is misleading because the content
"w-3/4" parses as a numeric value with a fractional modifier; rename the test
file to something clearer (e.g., number-with-modifier.txt or
fractional-modifier.txt) and update any references to the fixture in tests or
test harness to use the new name so the filename matches the parsed token
structure.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: b28bb3ca-8d34-4aba-94b7-f621d2a74b01
⛔ Files ignored due to path filters (23)
crates/biome_tailwind_factory/src/generated/node_factory.rsis excluded by!**/generated/**,!**/generated/**and included by**crates/biome_tailwind_factory/src/generated/syntax_factory.rsis excluded by!**/generated/**,!**/generated/**and included by**crates/biome_tailwind_parser/tests/tailwind_specs/error/arbitrary-candidate/missing-property.txt.snapis excluded by!**/*.snapand included by**crates/biome_tailwind_parser/tests/tailwind_specs/error/arbitrary-candidate/missing-value-in-arbitrary.txt.snapis excluded by!**/*.snapand included by**crates/biome_tailwind_parser/tests/tailwind_specs/ok/brackets/css-values.txt.snapis excluded by!**/*.snapand included by**crates/biome_tailwind_parser/tests/tailwind_specs/ok/brackets/gradient.txt.snapis excluded by!**/*.snapand included by**crates/biome_tailwind_parser/tests/tailwind_specs/ok/candidates/arbitrary-candidate-0.txt.snapis excluded by!**/*.snapand included by**crates/biome_tailwind_parser/tests/tailwind_specs/ok/candidates/arbitrary-candidate-1.txt.snapis excluded by!**/*.snapand included by**crates/biome_tailwind_parser/tests/tailwind_specs/ok/candidates/arbitrary-candidate-2.txt.snapis excluded by!**/*.snapand included by**crates/biome_tailwind_parser/tests/tailwind_specs/ok/gradients/precise-control.txt.snapis excluded by!**/*.snapand included by**crates/biome_tailwind_parser/tests/tailwind_specs/ok/simple/2-classes.txt.snapis excluded by!**/*.snapand included by**crates/biome_tailwind_parser/tests/tailwind_specs/ok/simple/modifier.txt.snapis excluded by!**/*.snapand included by**crates/biome_tailwind_parser/tests/tailwind_specs/ok/simple/negative.txt.snapis excluded by!**/*.snapand included by**crates/biome_tailwind_parser/tests/tailwind_specs/ok/simple/number-value.txt.snapis excluded by!**/*.snapand included by**crates/biome_tailwind_parser/tests/tailwind_specs/ok/simple/percentage-value.txt.snapis excluded by!**/*.snapand included by**crates/biome_tailwind_parser/tests/tailwind_specs/ok/simple/ratio-value.txt.snapis excluded by!**/*.snapand included by**crates/biome_tailwind_parser/tests/tailwind_specs/ok/stress/stress-1.txt.snapis excluded by!**/*.snapand included by**crates/biome_tailwind_parser/tests/tailwind_specs/ok/stress/stress-2.txt.snapis excluded by!**/*.snapand included by**crates/biome_tailwind_parser/tests/tailwind_specs/ok/variants/consecutive-arbitrary-variants.txt.snapis excluded by!**/*.snapand included by**crates/biome_tailwind_syntax/src/generated/kind.rsis excluded by!**/generated/**,!**/generated/**and included by**crates/biome_tailwind_syntax/src/generated/macros.rsis excluded by!**/generated/**,!**/generated/**and included by**crates/biome_tailwind_syntax/src/generated/nodes.rsis excluded by!**/generated/**,!**/generated/**and included by**crates/biome_tailwind_syntax/src/generated/nodes_mut.rsis excluded by!**/generated/**,!**/generated/**and included by**
📒 Files selected for processing (8)
crates/biome_tailwind_parser/src/lexer/mod.rscrates/biome_tailwind_parser/src/lexer/tests.rscrates/biome_tailwind_parser/src/syntax/value.rscrates/biome_tailwind_parser/tests/tailwind_specs/ok/simple/number-value.txtcrates/biome_tailwind_parser/tests/tailwind_specs/ok/simple/percentage-value.txtcrates/biome_tailwind_parser/tests/tailwind_specs/ok/simple/ratio-value.txtxtask/codegen/src/tailwind_kinds_src.rsxtask/codegen/tailwind.ungram
Routes sort_v4 through the new TwNumberValue / TwPercentageValue nodes from biomejs#10332 instead of scanning value text in predicates.rs. Ratio is synthesized from value + numeric modifier when the entry has a Ratio branch (mirrors Tailwind's supportsFractions). All hot-path matching stays allocation-free.
Routes sort_v4 through the new TwNumberValue / TwPercentageValue nodes from biomejs#10332 instead of scanning value text in predicates.rs. Ratio is synthesized from value + numeric modifier when the entry has a Ratio branch (mirrors Tailwind's supportsFractions). All hot-path matching stays allocation-free.
Summary
This makes the tailwind parser parse values more precisely. Specifically, it lexes numbers as its own token and percentage values as their own syntax node. ratios were considered, but not included because there are still some edge cases that are too complicated for this PR.
Test Plan
snapshots
Docs