Skip to content

Fix parsing bug in SelectorParser#20090

Merged
RobinMalfait merged 2 commits into
mainfrom
fix/pseudo-element-in-selector-parser
May 20, 2026
Merged

Fix parsing bug in SelectorParser#20090
RobinMalfait merged 2 commits into
mainfrom
fix/pseudo-element-in-selector-parser

Conversation

@RobinMalfait
Copy link
Copy Markdown
Member

While working on another feature, I noticed that a selector such as .foo::before was parsed as:

[
  {
    kind: 'compound',
    nodes: [
      { kind: 'selector', value: '.foo' },
      { kind: 'selector', value: ':' },
      { kind: 'selector', value: '::before' },
    ],
  },
]

Instead of:

[
  {
    kind: 'compound',
    nodes: [
      { kind: 'selector', value: '.foo' },
      { kind: 'selector', value: '::before' },
    ],
  },
]

So far this hasn't been a real issue in practice, but it is in a follow-up PR that I'm working on. To keep things separated, I wanted to fix this behavior in a dedicated PR instead.

Test plan

  1. Added a test case for this situation
  2. Other tests still pass

@RobinMalfait RobinMalfait requested a review from a team as a code owner May 20, 2026 13:35
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 20, 2026

Confidence Score: 5/5

Safe to merge — the change is a one-condition guard in a well-tested parser that corrects a silent mis-parse of double-colon pseudo-elements.

The fix is minimal and surgical: a single if inside one switch case, guarded by a precise equality check (buffer === ':') that can only match the exact scenario being corrected. The logic traces cleanly through all realistic CSS selectors (.foo::before, standalone ::before, :hover::before, and invalid inputs like :::). The added test directly covers the regression, and no existing test surfaces break.

No files require special attention.

Reviews (1): Last reviewed commit: "ensure `::before` gets parsed as a singl..." | Re-trigger Greptile

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 361d0fbb-03b1-45fb-8404-d70098630907

📥 Commits

Reviewing files that changed from the base of the PR and between 2c4726d and 6349d5e.

📒 Files selected for processing (2)
  • packages/tailwindcss/src/selector-parser.test.ts
  • packages/tailwindcss/src/selector-parser.ts

Walkthrough

This PR adds support for parsing CSS pseudo-element selectors using double-colon syntax (e.g., ::before, ::after). The parser's tokenization logic now detects when a colon character immediately follows an existing colon in the buffer and concatenates them into a single token instead of treating them as separate selector nodes. A test case validates that .foo::before is parsed as a compound selector containing the element selector and the pseudo-element selector node.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix parsing bug in SelectorParser' clearly and concisely describes the main change: fixing a parsing bug in the SelectorParser component.
Description check ✅ Passed The description is directly related to the changeset, explaining the bug (incorrect parsing of pseudo-element selectors), showing the before/after behavior, and outlining the test plan.
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.

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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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

@RobinMalfait RobinMalfait merged commit d03edef into main May 20, 2026
9 checks passed
@RobinMalfait RobinMalfait deleted the fix/pseudo-element-in-selector-parser branch May 20, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant