Skip to content

fix: parse non-selector pseudo-class arguments as identifiers - #355

Merged
bartveneman merged 4 commits into
mainfrom
claude/brave-thompson-u3gmqa
Nov 12, 2026
Merged

bartveneman merged 4 commits into
mainfrom
claude/brave-thompson-u3gmqa

Conversation

@bartveneman

Copy link
Copy Markdown
Member

Summary

This PR adds support for parsing pseudo-class and pseudo-element function arguments that are not selector lists. Previously, all pseudo-function arguments were either parsed as selector lists (for :is(), :where(), :not(), etc.) or skipped entirely. Now, arguments for pseudo-classes like ::part(), ::highlight(), :state(), :dir(), and custom pseudo-classes are properly parsed as identifier arguments.

Key Changes

  • Added SELECTOR_PSEUDOS set: Defines which pseudo-classes/elements accept selector list arguments (:is(), :where(), :not(), :has(), :host(), ::slotted(), etc.)
  • Implemented parse_ident_arguments() method: Parses non-selector pseudo arguments by:
    • Treating whitespace, commas, and comments as argument separators
    • Merging adjacent tokens into single IDENTIFIER nodes
    • Preserving commas as OPERATOR children to maintain CSS round-trip fidelity
    • Properly tracking line and column positions across multiple lines
  • Updated parse_lang_identifiers() signature: Now accepts line and column parameters to correctly position parsed language identifiers, and preserves commas as OPERATOR nodes
  • Enhanced pseudo-function parsing logic: Added conditional branching to distinguish between selector-accepting pseudos, :lang(), and other identifier-accepting pseudos
  • Added imports: IDENTIFIER and OPERATOR constants from arena module

Notable Implementation Details

  • Commas are preserved as OPERATOR nodes in the AST rather than being discarded, enabling accurate CSS serialization
  • Comments and whitespace act as argument delimiters, allowing constructs like ::part(a/* comment */b) to parse as two separate arguments
  • Line and column tracking is maintained across multi-line pseudo-function arguments
  • The implementation handles edge cases like empty arguments and consecutive separators gracefully

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Package Size Increase

📦 Package 📏 Base Size 📏 Source Size 📈 Size Change
@projectwallace/css-parser 49.3 kB 49.8 kB +442 B

@pkg-pr-new

pkg-pr-new Bot commented Nov 12, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@projectwallace/css-parser@0f9f520

commit: 0f9f520

@bartveneman bartveneman changed the title Parse non-selector pseudo-class arguments as identifiers fix: parse non-selector pseudo-class arguments as identifiers Nov 12, 2026
@bartveneman
bartveneman merged commit de8b63b into main Nov 12, 2026
17 checks passed
@bartveneman
bartveneman deleted the claude/brave-thompson-u3gmqa branch November 12, 2026 20:55
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.

2 participants