blakeembrey / free-style

Make CSS easier and more maintainable by using JavaScript
MIT License
707 stars 29 forks source link

Selector list parents plus pseudo class children don't apply to all parent selectors #103

Open whiteinge opened 2 years ago

whiteinge commented 2 years ago

If a parent style uses a selector list and a child style uses both the parent reference (&) and a pseudo class, that pseudo class isn't present on all parent selectors as expected.

E.g.:

const className = Style.registerStyle({
  "& > input, & .foo > input": {
    "&:focus": { background: "green" },
  },
});

Produces .asdf > input, .asdf .foo > input:focus {...} on the last selector only, and not .asdf > input:focus, .asdf .foo > input:focus {...} on all selectors as expected.

blakeembrey commented 2 years ago

Here’s a previous issue related too: https://github.com/blakeembrey/free-style/issues/72.

whiteinge commented 2 years ago

Oh, thanks for the link. I did search the issues before opening this but 'selector list' and 'pseudo class' don't appear in those others and I didn't think to just search for 'comma' :stuck_out_tongue: .

I can definitely appreciate not wanting to introduce a parser. That said, I do wonder if we could get by with a very naive one since, I think, we only care about top-level selector lists. Offhand:

Can you think of anything I'm overlooking? I wonder if it could be as simple as splitting on any commas outside pairs of ( and [ -- and maybe " and ' too (or will those always appear inside one of the first two?). I'll poke around the spec and some existing parsers.