Skip to content

Fix dashed idents being parsed as type selectors in pseudo-element functions#186

Merged
bartveneman merged 1 commit intomainfrom
claude/fix-dashed-ident-parsing-k0B1K
Mar 16, 2026
Merged

Fix dashed idents being parsed as type selectors in pseudo-element functions#186
bartveneman merged 1 commit intomainfrom
claude/fix-dashed-ident-parsing-k0B1K

Conversation

@bartveneman
Copy link
Member

Summary

Fixed a parsing issue where dashed identifiers (CSS custom property names like --my-ident) were incorrectly being classified as type selectors when used as arguments to pseudo-element functions like ::view-transition-new() and ::view-transition-old().

Key Changes

  • Added validation in parse_type_or_namespace_selector() to detect and reject dashed identifiers (starting with --) from being parsed as type selectors
  • Imported CHAR_MINUS_HYPHEN constant to support the dashed identifier detection
  • Added comprehensive test coverage for dashed idents in various pseudo-element contexts:
    • ::view-transition-new(--custom-name)
    • ::view-transition-old(--custom-name)
    • ::slotted(--custom-name)
    • Selector lists with multiple view-transition pseudo-elements
    • Verification that normal idents in pseudo-class functions like :is() still work correctly

Implementation Details

The fix checks if an identifier token starts with two consecutive hyphens (--), which is the CSS syntax for custom property names. When detected, the parser returns null instead of creating a TYPE_SELECTOR node, allowing the dashed ident to be handled appropriately by the pseudo-element function's argument parsing logic.

https://claude.ai/code/session_018QWguHVy1uENPc16qgjLcz

A dashed ident like --light-box-img is a CSS custom property name, not a
valid type selector. When used as an argument to pseudo-element functions
such as ::view-transition-new(--light-box-img) and
::view-transition-old(--light-box-img), the parser was incorrectly
producing a TYPE_SELECTOR node for the dashed ident, causing downstream
tools (e.g. css-analyzer) to misclassify it as a custom element.

Fix: in parse_type_or_namespace_selector, bail out early with null when
the ident token starts with -- so it is never wrapped in TYPE_SELECTOR.

Fixes projectwallace/css-analyzer#539

https://claude.ai/code/session_018QWguHVy1uENPc16qgjLcz
@codecov-commenter
Copy link

Bundle Report

Changes will increase total bundle size by 101 bytes (0.06%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
@projectwallace/css-parser-esm 159.26kB 101 bytes (0.06%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: @projectwallace/css-parser-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
parse-selector.js 101 bytes 19.98kB 0.51%

Files in parse-selector.js:

  • ./src/parse-selector.ts → Total Size: 19.5kB

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.23%. Comparing base (b5fb784) to head (0f04e24).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #186   +/-   ##
=======================================
  Coverage   95.22%   95.23%           
=======================================
  Files          16       16           
  Lines        2869     2873    +4     
  Branches      803      806    +3     
=======================================
+ Hits         2732     2736    +4     
  Misses        137      137           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bartveneman bartveneman merged commit 4c318ae into main Mar 16, 2026
4 of 5 checks passed
@bartveneman bartveneman deleted the claude/fix-dashed-ident-parsing-k0B1K branch March 16, 2026 14:28
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.

3 participants