Skip to content

Nested rule support#337

Open
nzakas wants to merge 1 commit intocsstree:masterfrom
eslint:nesting
Open

Nested rule support#337
nzakas wants to merge 1 commit intocsstree:masterfrom
eslint:nesting

Conversation

@nzakas
Copy link
Contributor

@nzakas nzakas commented Apr 11, 2025

This pull request includes changes to improve the handling of nested selectors in the Block parsing logic and updates to the corresponding test fixtures.

Note: I couldn't quite figure out how to detect element selectors for nesting. All of the other selector types are supported. I could use some help figuring out the element selector piece.

Fixes #268

Improvements to nested selector handling:

  • lib/syntax/node/Block.js: Added support for new selector types including Delim, Hash, Colon, and LeftSquareBracket, and introduced a new function isSelectorStart to improve detection of selector starts. [1] [2] [3]

Updates to test fixtures:

  • fixtures/ast/rule/nesting.json: Updated test cases to include various nested selector scenarios such as nested class selectors, ID selectors, attribute selectors, universal selectors, and pseudo-class selectors. [1] [2] [3]

@coveralls
Copy link

Coverage Status

coverage: 98.882% (+0.002%) from 98.88%
when pulling 5f60dc7 on eslint:nesting
into 9558ba7 on csstree:master.

@nzakas nzakas changed the title Nested selector support Nested rule support Apr 14, 2025
@nzakas
Copy link
Contributor Author

nzakas commented Apr 14, 2025

I tried a couple times to get the nested element selectors working and I couldn't figure it out. @lahmatiy I'd appreciate some guidance here.

@nzakas
Copy link
Contributor Author

nzakas commented May 15, 2025

@lahmatiy friendly reminder I'm looking for feedback here. Nesting is a pretty important feature and it's difficult to use CSSTree on modern CSS without some kind of support for it.

@gbrlmtrz
Copy link

👍 lets have this one please!

@nzakas
Copy link
Contributor Author

nzakas commented Oct 24, 2025

@gbrlmtrz you can check out the ESLint fork, which has support for most nested selectors: https://github.com/eslint/csstree.

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.

Nested attribute selector without & is parsed as raw

3 participants