-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Omitting "&" on an "& when" block #2887
Comments
The argument is quite artificial. A contra-arg using equal analogy: .a {
& { color: blue; } // OK
}
.a {
{ color: blue; } // Error
} In general, I would not mind any less verbose and less cluttered syntax but this particular case this looks like spoiling the language with just more quite random syntax constructions (we've already allowed various Counting that, I don't see how:
is really more friendly than:
(Not counting that personally I'd also be very cautious with ever saying that just to safe myself from continuously saying later "In the docs they are not quite correct and |
Playing devil's advocate: if you want to take syntax clarity of free-form conditional blocks to its logical conclusion, then shouldn't you instead be taking a page out of the book of .a {
@when (1=1) {
color: blue;
}
} Because conceptually, mixin and selector guards work exactly like |
@rjgotten Which was what was proposed in #2072 (along with the concept of nested @when and grouped decision trees via @select). I specifically wanted to make this issue a very narrow proposal (basically: "Can Well, technically it's not an "alternative syntax", since we were talking about Anyway, while it's a long / broad thread, I'll close this for #2072. |
Moving this discussion from #1293
There was a comment today on issue #1293 that got me thinking about the
& when
statement often used as a stand-in for an "if" statement. (Yes, not a one-to-one stand-in, I don't want to open a side-track of imperative v. declarative keywords.)One thing that occurred to me about this. We had discussed
@when
in issue #2072, but some of the resistance to @when in the original discussion is the additional at-rule. However, thinking about it now, it shouldn't be needed.Considering that these two blocks are equal:
Then these two statements should also be accepted by the parser as equal.
If for no other reason than
& when
is syntactically awkward. Omitting&
to still imply a selector join with the parent selector has existed all along, so omitting&
to imply a guard on the parent selector doesn't seem like a leap. Also, block-root functions are now accepted by the parser for use with plugins, so it no longer looks as strange as it might have in 2013.I feel
when ()
would be a bit easier for new Less users to understand than& when()
if we just say, "For now, pretend that when() means if() and we'll get to the more advanced reasons about the differences later." I mean, we don't have to explicitly state that in the documentation. It just requires a little less understanding of Less's use of&
and such to get how to use it. And the syntax is cleaner. It's just a small trim on the syntax.The text was updated successfully, but these errors were encountered: