Skip to content
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

Add support for child pseudo classes to parent selector lists #104

Closed
wants to merge 3 commits into from

Conversation

whiteinge
Copy link

Here's one possible fix for #103. Suggestions or other fixes very welcome. I haven't done heavy testing/benchmarking with this code yet but I wanted to start a discussion here.

Some questions I had:

  • Are there other CSS selectors that contain commas where this will break or become troublesome?
  • This fix ignores the amount of whitespace in between selectors in a selector list and always outputs , as a delimiter -- does that matter?

Closes #103

@@ -94,7 +94,10 @@ function escape(str: string) {
* Interpolate the `&` with style name.
*/
function interpolate(selector: string, styleName: string) {
return selector.replace(/&/g, styleName);
return styleName
.split(/, */)
Copy link
Owner

Choose a reason for hiding this comment

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

The issue is it needs a proper parser because it’s valid to have a comma in a CSS selector, I.e. the selector is escaped or part of a content string or some other match. Although unlikely, it should be handled.

Copy link
Author

Choose a reason for hiding this comment

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

Makes sense. I was afraid of that -- a parser is a whole different kind of lift. Thanks for the reply, I'll give it some more thought.

@whiteinge whiteinge closed this Nov 10, 2021
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.

Selector list parents plus pseudo class children don't apply to all parent selectors
2 participants