Skip to content

feat: Parse nested element selector #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 1, 2025
Merged

Conversation

nzakas
Copy link
Member

@nzakas nzakas commented May 28, 2025

This adds support for parsing most nested element selectors:

div {
	a {}
	a.foo {}
	a[href] {}
	a, b {}
	a > b {}
	a + b {}
}

The only pattern it doesn't currently cover is when a pseudoclass or pseudoelement is immediately attached to the element, like this:

div {
    a:hover {}
}

That's because a:hover looks like a property and I haven't yet figured out an efficient way to discover whether it's a property or a selector.

refs #33

@coveralls
Copy link

coveralls commented May 28, 2025

Pull Request Test Coverage Report for Build 15310219514

Details

  • 27 of 27 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.003%) to 98.603%

Totals Coverage Status
Change from base Build 15302932740: 0.003%
Covered Lines: 11738
Relevant Lines: 11870

💛 - Coveralls

@@ -60,8 +75,7 @@ export const structure = {
]]
};

export function parse(isStyleBlock) {
const consumer = isStyleBlock ? consumeDeclaration : consumeRule;
export function parse(isStyleBlock, { allowNestedRules = false } = {}) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I needed to add a new parameter because previously isStyleBlock meant it could only contain declarations, which is still true for at-rules but not for regular rules.

Copy link

@snitin315 snitin315 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Leaving it open for 2nd review

@snitin315 snitin315 moved this from Needs Triage to Second Review Needed in Triage May 31, 2025
Copy link
Member

@fasttime fasttime left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@fasttime fasttime merged commit ed3ae55 into main Jun 1, 2025
31 checks passed
@github-project-automation github-project-automation bot moved this from Second Review Needed to Complete in Triage Jun 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

5 participants