Skip to content

feat(parse/tailwind): differentiate between number and non-number values#10332

Merged
dyc3 merged 6 commits into
mainfrom
dyc3/tw-parse-number-values
May 11, 2026
Merged

feat(parse/tailwind): differentiate between number and non-number values#10332
dyc3 merged 6 commits into
mainfrom
dyc3/tw-parse-number-values

Conversation

@dyc3
Copy link
Copy Markdown
Contributor

@dyc3 dyc3 commented May 10, 2026

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

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 10, 2026

⚠️ No Changeset found

Latest commit: 2467d2b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions Bot added A-Parser Area: parser A-Tooling Area: internal tools L-Tailwind Language: Tailwind CSS labels May 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Parser conformance results on

js/262

Test result main count This PR count Difference
Total 53208 53208 0
Passed 51990 51990 0
Failed 1176 1176 0
Panics 42 42 0
Coverage 97.71% 97.71% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 38 38 0
Passed 37 37 0
Failed 1 1 0
Panics 0 0 0
Coverage 97.37% 97.37% 0.00%

markdown/commonmark

Test result main count This PR count Difference
Total 652 652 0
Passed 652 652 0
Failed 0 0 0
Panics 0 0 0
Coverage 100.00% 100.00% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 5467 5467 0
Passed 1915 1915 0
Failed 3552 3552 0
Panics 0 0 0
Coverage 35.03% 35.03% 0.00%

ts/babel

Test result main count This PR count Difference
Total 658 658 0
Passed 574 574 0
Failed 84 84 0
Panics 0 0 0
Coverage 87.23% 87.23% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 18876 18876 0
Passed 13010 13010 0
Failed 5865 5865 0
Panics 1 1 0
Coverage 68.92% 68.92% 0.00%

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 10, 2026

Merging this PR will not alter performance

✅ 10 untouched benchmarks
⏩ 246 skipped benchmarks1


Comparing dyc3/tw-parse-number-values (2467d2b) with main (ed26542)

Open in CodSpeed

Footnotes

  1. 246 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@dyc3 dyc3 marked this pull request as ready for review May 10, 2026 23:14
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 10, 2026

Review Change Stack

Walkthrough

This change extends the Tailwind parser to recognise and correctly parse numeric and percentage values. The lexer gains a TW_NUMBER token kind and now detects when consumed value or modifier spans contain only numeric characters, emitting TW_NUMBER instead of TW_VALUE and treating % as an explicit delimiter. The parser routes these numeric tokens to a new parse_numeric_value function that optionally consumes a trailing % to produce TW_NUMBER_VALUE or TW_PERCENTAGE_VALUE AST nodes. Grammar rules and type definitions are updated accordingly, with tests verifying both lexer tokenisation and end-to-end parsing of numeric and percentage Tailwind values.

Possibly related PRs

  • biomejs/biome#10299: Directly overlapping changes to lexer and parser code for numeric and percentage Tailwind value recognition.

Suggested reviewers

  • ematipico
  • denbezrukov
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main feature: differentiating between number and non-number values in the Tailwind parser.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description clearly explains the motivation (parse values more precisely by lexing numbers as distinct tokens and percentage values as syntax nodes) and directly relates to the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dyc3/tw-parse-number-values

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
crates/biome_tailwind_parser/tests/tailwind_specs/ok/simple/ratio-value.txt (1)

1-1: 💤 Low value

Consider renaming this fixture.

The filename suggests a ratio value type, but w-3/4 is actually parsed as a number value (3) followed by a modifier (/4). Perhaps number-with-modifier.txt or fractional-modifier.txt would 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9b1577f and 2467d2b.

⛔ Files ignored due to path filters (23)
  • crates/biome_tailwind_factory/src/generated/node_factory.rs is excluded by !**/generated/**, !**/generated/** and included by **
  • crates/biome_tailwind_factory/src/generated/syntax_factory.rs is excluded by !**/generated/**, !**/generated/** and included by **
  • crates/biome_tailwind_parser/tests/tailwind_specs/error/arbitrary-candidate/missing-property.txt.snap is excluded by !**/*.snap and included by **
  • crates/biome_tailwind_parser/tests/tailwind_specs/error/arbitrary-candidate/missing-value-in-arbitrary.txt.snap is excluded by !**/*.snap and included by **
  • crates/biome_tailwind_parser/tests/tailwind_specs/ok/brackets/css-values.txt.snap is excluded by !**/*.snap and included by **
  • crates/biome_tailwind_parser/tests/tailwind_specs/ok/brackets/gradient.txt.snap is excluded by !**/*.snap and included by **
  • crates/biome_tailwind_parser/tests/tailwind_specs/ok/candidates/arbitrary-candidate-0.txt.snap is excluded by !**/*.snap and included by **
  • crates/biome_tailwind_parser/tests/tailwind_specs/ok/candidates/arbitrary-candidate-1.txt.snap is excluded by !**/*.snap and included by **
  • crates/biome_tailwind_parser/tests/tailwind_specs/ok/candidates/arbitrary-candidate-2.txt.snap is excluded by !**/*.snap and included by **
  • crates/biome_tailwind_parser/tests/tailwind_specs/ok/gradients/precise-control.txt.snap is excluded by !**/*.snap and included by **
  • crates/biome_tailwind_parser/tests/tailwind_specs/ok/simple/2-classes.txt.snap is excluded by !**/*.snap and included by **
  • crates/biome_tailwind_parser/tests/tailwind_specs/ok/simple/modifier.txt.snap is excluded by !**/*.snap and included by **
  • crates/biome_tailwind_parser/tests/tailwind_specs/ok/simple/negative.txt.snap is excluded by !**/*.snap and included by **
  • crates/biome_tailwind_parser/tests/tailwind_specs/ok/simple/number-value.txt.snap is excluded by !**/*.snap and included by **
  • crates/biome_tailwind_parser/tests/tailwind_specs/ok/simple/percentage-value.txt.snap is excluded by !**/*.snap and included by **
  • crates/biome_tailwind_parser/tests/tailwind_specs/ok/simple/ratio-value.txt.snap is excluded by !**/*.snap and included by **
  • crates/biome_tailwind_parser/tests/tailwind_specs/ok/stress/stress-1.txt.snap is excluded by !**/*.snap and included by **
  • crates/biome_tailwind_parser/tests/tailwind_specs/ok/stress/stress-2.txt.snap is excluded by !**/*.snap and included by **
  • crates/biome_tailwind_parser/tests/tailwind_specs/ok/variants/consecutive-arbitrary-variants.txt.snap is excluded by !**/*.snap and included by **
  • crates/biome_tailwind_syntax/src/generated/kind.rs is excluded by !**/generated/**, !**/generated/** and included by **
  • crates/biome_tailwind_syntax/src/generated/macros.rs is excluded by !**/generated/**, !**/generated/** and included by **
  • crates/biome_tailwind_syntax/src/generated/nodes.rs is excluded by !**/generated/**, !**/generated/** and included by **
  • crates/biome_tailwind_syntax/src/generated/nodes_mut.rs is excluded by !**/generated/**, !**/generated/** and included by **
📒 Files selected for processing (8)
  • crates/biome_tailwind_parser/src/lexer/mod.rs
  • crates/biome_tailwind_parser/src/lexer/tests.rs
  • crates/biome_tailwind_parser/src/syntax/value.rs
  • crates/biome_tailwind_parser/tests/tailwind_specs/ok/simple/number-value.txt
  • crates/biome_tailwind_parser/tests/tailwind_specs/ok/simple/percentage-value.txt
  • crates/biome_tailwind_parser/tests/tailwind_specs/ok/simple/ratio-value.txt
  • xtask/codegen/src/tailwind_kinds_src.rs
  • xtask/codegen/tailwind.ungram

@dyc3 dyc3 requested review from a team May 11, 2026 02:18
@dyc3 dyc3 merged commit 3f02f4a into main May 11, 2026
29 checks passed
@dyc3 dyc3 deleted the dyc3/tw-parse-number-values branch May 11, 2026 12:51
jiwon79 pushed a commit to jiwon79/biome that referenced this pull request May 11, 2026
jiwon79 added a commit to jiwon79/biome that referenced this pull request May 11, 2026
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.
jiwon79 added a commit to jiwon79/biome that referenced this pull request May 11, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Parser Area: parser A-Tooling Area: internal tools L-Tailwind Language: Tailwind CSS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant