-
Notifications
You must be signed in to change notification settings - Fork 26
Concatenative selectors #17
Comments
It's wrong, but only because type selectors don't have an identifying prefix. For all other selectors, you can just naively concatenate them - So this fails only in two cases:
In either case, you just have to do some minor rewriting to make sure the type selector goes first - the first case should result in
You're misreading a bit - if the parent selector uses commas (it's a selector list of length >1), you have to enclose it in a So |
Is it possible to add some sort of check for this? Right now this is prone to accidental use for cases like |
@taion, that's a good point. Could be a pretty quick RegEx check, using something like: /^&(?: *[a-zA-Z\.#:>\[*+~]|(?:\|\|))/ However, there are pieces that (I think, maybe @tabatkins can confirm) this plugin and the spec diverge, the plugin allows for: a {
color: blue;
& & {
color: orange;
}
& b & {
color: red;
}
} which compiles to: a {
color: blue;
}
a a {
color: orange;
}
a b a {
color: red;
} But the Spec doesn't treat the |
The .foo {
color: red;
@nest & .bar, .baz {
color: blue;
}
}
/* Invalid because not all selectors in the list
contain a nesting selector */ But the plugin compiles it to: .foo {
color: red;
}
.foo .bar, .baz {
color: blue;
} |
Correct, the spec treats |
FWIW, I'm a little bit less worried about those edge cases – more as a defensive thing, preventing people from using the nesting syntax for concatenation in "obviously wrong" cases. |
It seems like this plugin cannot emulate what you are saying the specification defines. For instance, are we saying that class selectors cannot be extended? I imagine almost anyone writing BEM-like CSS is probably using this plugin (alone or within cssnext) to do things like |
👍 to that – I can't imagine many people are writing |
Yeah, I believe this (see below) is invalid as the spec is written. .button {
&__primary {
&--toggled {}
}
} I think @taion brings up a really valid point though if this plugin is to respect the spec then it should conform. Obviously the concern is that this type of change would be a major breaking type of change. |
Okay, I can update the plugin to effectively work more like This would definitely be a major release change, and, sadly, I’m certain many developers will, at some point, blindly pull the major release and discover that all of their BEM concatenations are broken. |
There could be a "loose" option that allows selector concatenation. |
Missing semicolon on nesting selectors, as shown on the first example. It´s not a rendering issue but would be great to add or have it. Input
Output
|
bit confused does this mean that |
It's not invalid in the spec, but it's meaningless and will never match anything, because |
Hmm OK, so it's that this isn't actually polyfillable. If you don't mind me asking why not have it be the selector? that approach seems more useful am I just looking at it the wrong way? |
Correct, it's not quite polyfillable exactly, without a ton of expensive effort in JS. You definitely can't faithfully polyfill it in all cases as a rewrite step. (You can in the vast majority of cases, tho. Just rejecting more than one It's not text munging because text munging is weird and hacky and always ends up with unexpected consequences. We have real information in the browser; we can use that to do cool things that are more sophisticated than what you can do as a text-rewrite step. |
I think it's very possible to throw on selectors with multiple This is equivalent to checking |
BEM user here. It would be bad if all of the sudden I couldn't do |
@gaastonsr, we’ll allow a “loose” option for such things, but it should be off by default, because we want to follow the spec. At the same time, having a separate plugin for loose mode seems excessive. |
I stopped documenting this usage in v3 and I’ve finally removed it in v4. For non-spec compliant nesting, we have the Sassy PostCSS Nested. |
@tabatkins is there any reason I can't do |
Hi @jonathantneal, thanks for making such a cool postcss plugin!
I feel like I've found a potential bug with this. The spec doesn't mention this behaviour specifically, but I'm quite sure it is undesired.
Input:
This plugins output:
I would expect to see an error, I think, as the spec suggests
&
is equivalent of:matches()
- which, to my understanding, means they shouldn't concatenate like this.Perhaps @tabatkins could clarify this?
The text was updated successfully, but these errors were encountered: