-
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
Is escaping supposed to work with @supports? #3059
Comments
This is a stone age hack. Use Passing Rulesets to Mixins instead, e.g.: // usage:
.foo {
.if-small-caps({
font-variant-caps: small-caps;
});
}
// impl:
.if-small-caps(@style) {
@supports (font-variant-caps: small-caps) {
@style();
}
} I'll add |
I would tend to disagree. Wrapping media queries (or support queries in this instance) in mixins is just one additional layer of abstraction. I much prefer something like Since |
Well, the problem with these "macro-like" variable usage is that it needs a special dedicated support everywhere it's used and inherits all the cons of the vanilla text-replacement macros w/o bringing in any pros of them (at least a consistency of where and how they can be used). Someone would also find it useful to have something like: @var: ~"rgb(128,";
color: @var 255, 0); with the equal justification ("I don't need any abstraction level bla-bla-bla"). |
o_O Er, an un-parseable monstrosity is not an equal example. I'm not sure I agree with the description that it's a macro. It's creating an anonymous node, and it can go where anonymous nodes can go. Between However, it COULD look like: @var: ~"rgb(128,";
color: @var ~"255, 0)"; ...because it's just output of two simple anonymous nodes. There's nothing wrong with that in Less, so I don't get the argument. Anonymous node output is available pretty much (almost) anyplace in Less. If a variable that evaluates to an anonymous node is not working as expected, it's a bug. It has nothing to do with "macros". Your argument seems to be just that you don't like the way that code looks, which is fine. Or that alternatives should be promoted, which is also fine. But that's really just a matter of programmer preference. It's still important that the feature is consistent as-is. |
Other alternatives as future features might be:
However, those are just alternatives for possible future discussions, and neither is related to the core issue of this thread, which is just at-rule consistency. |
Absolutely equal. Content of ~"(min-width: 768px)" is never parsed so it's possible only because the |
I think we're both agreeing on the same thing, and just suggesting a different outcome. Those patterns were hard-coded into So, I wouldn't suggest special-casing variable support to Probably the original version of |
Which, 🤔 when I phrase it that way, kind of implicitly DOES make it sound like a feature request. So I withdraw saying it's a bug, as it was designed that way intentionally. I would support it as a natural evolution of that feature though. |
Yes, and this essentially brings us to #1648 (comment). So I'm just asking again maybe it's time to stop abusing variables as macros and bring macros in. The problem is that with allowing a more relaxed "where vars can be used w/o any syntax check" thing we just open the box of "uh-oh, I misprinted some ; - shouldn't compiler give me a error?"... @min768: pi();
// OK
@media @min768 {
.element {font-size: 1.2rem}
}
// ...
#define min333 pi() // <- whatever syntax
// error - not valid media query:
@media min333 {
.element {font-size: 1.2rem}
} While escaping thing (e.g. |
Oh okay, the linked comment illuminates your thinking a little better. I'm only familiar with macros in Microsoft Windows & Office programming, which is recording and replaying a sequence of actions, and not just used for text replacement. (Is that a convention of text-based editors?) Because I'm not familiar with whatever usage you might be familiar with, I don't really understand what your example is doing. So because I don't understand your example, and the example doesn't use actual media queries (as far as I can tell?), I'm not sure why macros are advantageous as you understand them. I think one thing we can agree with: we both hate this as typical syntax So I get where you're coming from, basically: "If it's a hack, why expand usage of the hack?" And my position is essentially, "If this hack is going to continue to be used, it should at the least be consistent." So, if this hack is going to go away, then it probably needs a proper feature proposal. Otherwise (and maybe even if that feature will happen at some point in the future), it seems reasonable to extend to |
In above example (here I'm obviously talking about the simplest 'macro'-variants like those in C or PHP), we define a macro Though it might be a relatively tricky to implement within Less parser since it does not have a separate tokenizer stage - where a macro substitution could be easily injected. |
Hmm.... so if I understand correctly, the difference between I don't think that's a tricky as you might think, as long as:
I don't think the macro reference could be a naked keyword for the Less parser, but if it was a special character that couldn't be mistaken for anything else, then you could easily add to a macro dictionary and quickly swap out values while parsing. @define tablet "(min-width: 768px)";
@define mobile "(min-width: 640px"; // note missing parentheses
.box {
@media ~tablet~ {
// ...
}
// could easily throw immediate parsing error
@media ~mobile~ {
// ...
}
}
@define mobile "(min-width: 440px)"; // this does nothing, since it's not like a variable Wrapping the macros / text snippets in quotes would allow for things like including semi-colons in your macro, since we already support quote escapes (and don't support semi-colon escapes). And using something like Of course, Thanks for explaining a bit more. Is my understanding of macros basically correct? |
I suppose something like this would be not too challenging, parser-wise, if we added a second tilde @define selectors ".title, #main";
.box {
.other-selector, ~~selectors, .and-one-more {
// easy detection of unique characters, and quick exit (lookup) at first non-alpha character
} |
By the way, at-rule-based defines or even ~selectors: ".title, #main";
.box {
.other-selector, ~~selectors, .and-one-more {
// easy detection of unique characters, and quick exit (lookup) at first non-alpha character
}
}
~tablet: "@media (min-width: 768px)";
.box-2 {
color: red;
~~tablet {
// just spit-balling, there's a lot of possibility here
}
~~tablet and (max-width: 1024px) {
// okay now I really like this macro idea
}
} Or something like that. It's still quick to parse (faster than using |
I'd rather prefer a substituted macro identifier to may have either form. E.g. "compatible" But in general, yes, I assumed something like you wrote above... |
(to be moved to a separate ticket or even |
The problem is that it's a much more difficult problem / rewrite for the parser AFAIK (and also- is it not a more complex feature than a well-defined and limited system?) If you're just going to search and replace anything with anything, you might as well be using Gulp or PostCSS. I'm not sure why Less would need to be involved at that point. It's too generic. And I would probably vehemently oppose a "feature" that would instantly make a
I think you're onto the right idea, though. So yes, when you have a complete proposal in |
Some food for thought regarding the 'stone age media hack': #media {
@phone : { min-width : 0 }
@tablet : { min-width : 768px }
@desktop : { min-width : 1024px }
}
@media (#media[@tablet]()) {
...
} Wouldn't it be nice if that 'just worked' ™ ? |
What is the point of having ±tablet {
} be the proper code? .media(tablet, {
}); ) <- that's food for thought (still comparing count of parens vs. Personally I just can't see how (No, I'm not proposing a hack similar to |
I kind of like the explicitness of it in showing to readers that they're unambiguously dealing with a media query. But I agree that the amount of braces required in |
Errrr I get that we might support that output at some point, but that doesn't seem like the ideal solution to this problem. I'm kinda with @seven-phases-max on this one. |
The real deal is not the property lookup; the real deal is expanding a detached ruleset inside the braced section of a media query. You could continue to write the media query without the fancy lookup stuff, e.g. @media (@tablet) {
// ...
} But you'd be able to define the variable in question without resorting to escaped literals, e.g. @tablet: { min-width: 768px } And as a result the compiler keeps a firm hand on syntax validation and can bail on failure. That way you won't have to implement C-like pre-processor macros, which fly sort of in the face of the lazy evaluation in Less, imho. Could even have it handle @tablet-range : { min-width: 768px; max-width: 1024px }
@media (@tablet-range) {
// ...
} To produce @media (min-width: 768px) and (max-width: 1024px) {
// ...
}} And ofcourse; if you expand a DR, that means inside the DR, you can continue to use variables, mixins, etc. at will, should you really have a need to do truly complicated |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
cool. the issue is closed now so we can forget about it |
Much to my surprise, since
@supports
is bubbling like@media
, it seems that you can’t use any arbitrary string as a variable value for it.While
results in
Escaping a string with
@supports
results in
It failed in any implementation I tried (more or less 20) so I guess this is probably a core issue/feature request?
Is this result to be expected?
Problem is you can have awful feature queries like
and escaping would be very welcome for such cases, especially as people discover
@supports
with the grid spec, Open Type features and stuff.The text was updated successfully, but these errors were encountered: