You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Less fails to parse valid Custom Property values (ex: @apply polyfill) #2715
In a more complex situations it's also always possible to use @import (inline).
As for attempts like %(~"%d", @ruleset); - No, Less variables are not macros, they are not expanded regardless of context, and specifically for unnamed rulesets the only proper syntax is @ruleset() within a ruleset body and not as a property value.
@donny-dont Note I do not decide anything (I did not close the proposal) - I'm only a critic.
Well, Tab Atkins generated tens of CSS standard proposals (named "ideas") and while Google guys may push this into their browser even tomorrow, this is still too far from becoming even CSS draft thing (remember CSS vars not entering CSS world for about ten years?).
@seven-phases-max apologies for the implication. I just wanted to make a note that Polymer is pushing the mixin proposal and Chrome is likely to implement it once its shaped up which was something @Jamtis didn't really communicate.
I'm fairly new to using LESS is there any sort of plugin system for the parser in these sorts of scenarios? Something like an experimental flag you can turn on and off?
We have a spec for this; a polyfill exists; Chrome has implemented it; Polymer is already using it in a 1.0 release; and websites are already using Polymer.
I think it's a perfectly reasonable expectation for Less to support the syntax at a bare minimum level.
Less already passes @apply, --foo: bar;, and var(--foo) through. The only thing missing is getting Less to pass through the { ... } in --foo: { property: value; } with the same basic processing given to other css blocks; instead of coming to a hard stop and throwing a parse error.
Reacted by ElsewhereGames, Michael Stramel, Henk Rijneveld, Matthew Dean and reswitchtech
This is the relevant section up top, which I may be mis-interpreting.
The allowed syntax for custom properties is extremely permissive. The <declaration-value> production matches any sequence of one or more tokens, so long as the sequence does not contain <bad-string-token>, <bad-url-token>, unmatched <)-token>, <]-token>, or <}-token>, or top-level <semicolon-token> tokens or <delim-token> tokens with a value of "!".
So, important takeaways are:
Only the top-level semicolon-token matters. I interpret that to mean "not within some other matched pair"? But I could be misinterpreting what "top-level" means.
Maybe the JS example given on that page is misleading, (-foo: if(x > 5) this.width = 10; is valid.) But an unspaced = certainly is not a typical CSS token, nor is this.width. Without clarification, and given how permissive error recovery is on browsers, I don't think we can assume any parsing error for anything. We already know that the @apply syntax is valid (with a set of rules), even if it has a custom application. So we know that custom properties allow for multiple semi-colons within {}; it's therefore logical that this language implies something about the permissive nature within matching (), [], {}. There's a lot we don't know here, and without knowing what can go in a custom property, I think we have to assume anything can go in it, as long as it follows a particular structure ("so long as the sequence does not contain <bad-string-token>, <bad-url-token>, unmatched <)-token>, <]-token>, or <}-token>") and pass that property along to the browser. I believe the intent here is to create maximum flexibility for developers, while creating the bare minimum requirements for successful parsing.
So, you can't do this:
.bar {
--foo: {;
--baz: ";}
...because the syntax wants to allow you to put in anything, including multiple semi-colons, but it wants to be able to know when you're done. That's where the matching quotes / braces / parentheses / brackets come into play. As long as you can indicate you've "closed" your syntax in some way, I believe the intention here is that you can do what you want within that syntax.
As for possible implementation... It's not a big problem to allow anything there until ; but then we still should handle at least strings, urls and nested {} (as they may contain ; inside). Obviously this would mean no Less code within.
A step further would be to treat it (at the parsing stage) as a sort of DR (w/o its outer {}) with just more tokens allowed (though it looks like a dead-way since you can't reuse DR-parser for something like --var: (1 > 2) / {whatever} foo;)
And finally, for something more convenient I can't honestly see anything but writing a full-featured CSS-tokeniser with some of the Less features (tokens and then their evaluation) allowed in. A biiiiiiiig problem in other words :(
Only the top-level semicolon-token matters. I interpret that to mean "not within some other matched pair"? But I could be misinterpreting what "top-level" means.
Yes I'm pretty sure it's about the terminating ;. I.e. as in: --var: ";" url(;) {;}; is valid and --var: ; {} foo; is not (the first ; by being "top-level" terminates the statement).
I'm not sure about just (;) though.
My only thought is that we could maaaaybe allow interpolation syntax, in case you wanted to generate custom properties. But maybe that's sort of a "round 2 if there's interest" kind of idea.
I'm not sure about just (;) though.
I'm not either? I believe specs often have parsing details published somewhere (like token path diagrams), but I'm not sure if it exists in this case. As a stage 1 - only requiring matching {}, (), and quotes, and dumping anything into an anonymous node until a top-level ; seems fine. Matching brackets [] may not be necessary, but they're also mentioned and it's fairly trivial once all the other pieces are there.
I don't think we need to specially tokenize anything, or get into mixing this with DR stuff. After all, someone could end up with:
.weird {
--php: ($x=5/* + 15 */+5; echo $x;);
--example: [My DR will be --this: {
blah: nope;
--never mind i gave up;
no wait here it --is: {
lol: cats;
}
}];
}
In other words, it would be better for Less to wipe its hands clean of dealing with the contents of custom properties.
Also, it's technically feasible for a Less plugin author to write a visitor plugin that takes pieces and sends matching custom properties back through the Less parser to create new nodes. All we should really do is dump the contents into a rule node and mark the rule as a custom property, then just as faithfully dump the output.
Probably, but this means a downgrade - like now one can write: --var: darken(red, 5%) + 1;
and it works, but then (for the sake of --fortran: read (*, *, iostat=ierr) radius, height;) it won't :(
We can have an option for this probably (like --oh-no-yet-another-option-for-custom-properties-to-be-parsed-one-way-or-another: on :)
Probably, but this means a downgrade - like now one can write --var: darken(red, 5%); and it works, but then (for the sake of --fortran: read (*, *, iostat=ierr) radius, height;) it won't :(
🤔 Well..... yes I see what you mean, which is why maybe interpolation of some kind might be necessary? We could basically at the parser treat things similar to:
Yes, interpolation will do the trick. Though it still would be nice to a DR-ike parsing as an experimental option (I'm pretty sure many will prefer real --var: darken(red, 5%); to imaginary --javascript: 1 = 2; at least until such custom property hacking becomes widespread :)
In other words, I'm fine with both ways (separately or simultaneously).
I think I have a fairly robust implementation / solution for this. I used a number of code examples from this thread in tests. So, custom property values and unknown at-rules are essentially treated as escaped quoted values to allow interpolation. Check out #3213.
Activity
seven-phases-max commentedon Oct 21, 2015
I'm afraid non-CSS syntax support is beyond Less scope. So my -1.
Either way notice you can emit whatever code into the output with escaping. E.g.:
Or in more hackish multiline way:
In a more complex situations it's also always possible to use
@import (inline).As for attempts like
%(~"%d", @ruleset);- No, Less variables are not macros, they are not expanded regardless of context, and specifically for unnamed rulesets the only proper syntax is@ruleset()within a ruleset body and not as a property value.nicholas-brandt commentedon Oct 21, 2015
Well I agree with you that non-standard syntax should generally not be supported.
However this means that LESS in incompatible with Polymer in many cases.
Thanks for the reply anyway. 👍
donny-dont commentedon Dec 5, 2015
Not sure if this makes a difference in your decision @seven-phases-max but there is an open spec for an
@applyrule, http://tabatkins.github.io/specs/css-apply-rule/#issue-882293bd.Also see Polymer/polymer#1373 as it sounds like something Google is going to really push through the process.
And SASS seems to be addressing this sass/sass#1128
seven-phases-max commentedon Dec 5, 2015
@donny-dont Note I do not decide anything (I did not close the proposal) - I'm only a critic.
Well, Tab Atkins generated tens of CSS standard proposals (named "ideas") and while Google guys may push this into their browser even tomorrow, this is still too far from becoming even CSS draft thing (remember CSS
varsnot entering CSS world for about ten years?).donny-dont commentedon Dec 5, 2015
@seven-phases-max apologies for the implication. I just wanted to make a note that Polymer is pushing the mixin proposal and Chrome is likely to implement it once its shaped up which was something @Jamtis didn't really communicate.
I'm fairly new to using LESS is there any sort of plugin system for the parser in these sorts of scenarios? Something like an experimental flag you can turn on and off?
seven-phases-max commentedon Dec 10, 2015
I'm reopening this to be able to redirect duplicate requests here.
ebidel commentedon Jan 22, 2016
/sub
dantman commentedon May 9, 2016
We have a spec for this; a polyfill exists; Chrome has implemented it; Polymer is already using it in a 1.0 release; and websites are already using Polymer.
I think it's a perfectly reasonable expectation for Less to support the syntax at a bare minimum level.
Less already passes
@apply,--foo: bar;, andvar(--foo)through. The only thing missing is getting Less to pass through the{ ... }in--foo: { property: value; }with the same basic processing given to other css blocks; instead of coming to a hard stop and throwing a parse error.stramel commentedon Aug 3, 2016
I think the full spec of CSS Variables should be supported by LESS. Would love for this to happen!
18 remaining items
seven-phases-max commentedon Feb 15, 2018
mm, is it? For me https://www.w3.org/TR/css-variables/#syntax sounds like any token (except those listed there) can be anywhere there (regardless of either kind of parens). Or does this assumed by some other paragraph? Could you, please point me, where it says about any character, or anything specific about values inside parens? (unless it's
url(...)of course)?In other words, are either of
--var: ?;,--var: (?);or--var: [¾];actually valid?matthew-dean commentedon Feb 15, 2018
This is the relevant section up top, which I may be mis-interpreting.
So, important takeaways are:
Only the top-level semicolon-token matters. I interpret that to mean "not within some other matched pair"? But I could be misinterpreting what "top-level" means.
Maybe the JS example given on that page is misleading, (
-foo: if(x > 5) this.width = 10;is valid.) But an unspaced=certainly is not a typical CSS token, nor isthis.width. Without clarification, and given how permissive error recovery is on browsers, I don't think we can assume any parsing error for anything. We already know that the@applysyntax is valid (with a set of rules), even if it has a custom application. So we know that custom properties allow for multiple semi-colons within{}; it's therefore logical that this language implies something about the permissive nature within matching(),[],{}. There's a lot we don't know here, and without knowing what can go in a custom property, I think we have to assume anything can go in it, as long as it follows a particular structure ("so long as the sequence does not contain<bad-string-token>,<bad-url-token>, unmatched<)-token>,<]-token>, or<}-token>") and pass that property along to the browser. I believe the intent here is to create maximum flexibility for developers, while creating the bare minimum requirements for successful parsing.So, you can't do this:
...because the syntax wants to allow you to put in anything, including multiple semi-colons, but it wants to be able to know when you're done. That's where the matching quotes / braces / parentheses / brackets come into play. As long as you can indicate you've "closed" your syntax in some way, I believe the intention here is that you can do what you want within that syntax.
matthew-dean commentedon Feb 15, 2018
As to this:
I don't know.
Should we treat them as valid? IMO yes. Because we don't / can't know, but we can successfully parse it without too much trouble.
seven-phases-max commentedon Feb 15, 2018
As for possible implementation... It's not a big problem to allow anything there until
;but then we still should handle at least strings, urls and nested{}(as they may contain;inside). Obviously this would mean no Less code within.A step further would be to treat it (at the parsing stage) as a sort of DR (w/o its outer
{}) with just more tokens allowed (though it looks like a dead-way since you can't reuse DR-parser for something like--var: (1 > 2) / {whatever} foo;)And finally, for something more convenient I can't honestly see anything but writing a full-featured CSS-tokeniser with some of the Less features (tokens and then their evaluation) allowed in. A biiiiiiiig problem in other words :(
seven-phases-max commentedon Feb 15, 2018
Yes I'm pretty sure it's about the terminating
;. I.e. as in:--var: ";" url(;) {;};is valid and--var: ; {} foo;is not (the first;by being "top-level" terminates the statement).I'm not sure about just
(;)though.matthew-dean commentedon Feb 15, 2018
My only thought is that we could maaaaybe allow interpolation syntax, in case you wanted to generate custom properties. But maybe that's sort of a "round 2 if there's interest" kind of idea.
I'm not either? I believe specs often have parsing details published somewhere (like token path diagrams), but I'm not sure if it exists in this case. As a stage 1 - only requiring matching
{},(), and quotes, and dumping anything into an anonymous node until a top-level;seems fine. Matching brackets[]may not be necessary, but they're also mentioned and it's fairly trivial once all the other pieces are there.I don't think we need to specially tokenize anything, or get into mixing this with DR stuff. After all, someone could end up with:
In other words, it would be better for Less to wipe its hands clean of dealing with the contents of custom properties.
Also, it's technically feasible for a Less plugin author to write a visitor plugin that takes pieces and sends matching custom properties back through the Less parser to create new nodes. All we should really do is dump the contents into a rule node and mark the rule as a custom property, then just as faithfully dump the output.
matthew-dean commentedon Feb 15, 2018
Note that if we modify the above example, THIS should be considered invalid:
seven-phases-max commentedon Feb 15, 2018
Probably, but this means a downgrade - like now one can write:
--var: darken(red, 5%) + 1;and it works, but then (for the sake of
--fortran: read (*, *, iostat=ierr) radius, height;) it won't :(We can have an option for this probably (like
--oh-no-yet-another-option-for-custom-properties-to-be-parsed-one-way-or-another: on:)matthew-dean commentedon Feb 15, 2018
🤔 Well..... yes I see what you mean, which is why maybe interpolation of some kind might be necessary? We could basically at the parser treat things similar to:
(With the aforementioned caveats of proper matching tokens?)
I mean.... the alternative is that we essentially recommend escaping syntax. Just would be nice for fewer modifications of in-place CSS code.
seven-phases-max commentedon Feb 15, 2018
Yes, interpolation will do the trick. Though it still would be nice to a DR-ike parsing as an experimental option (I'm pretty sure many will prefer real
--var: darken(red, 5%);to imaginary--javascript: 1 = 2;at least until such custom property hacking becomes widespread :)In other words, I'm fine with both ways (separately or simultaneously).
matthew-dean commentedon Jun 2, 2018
I think I have a fairly robust implementation / solution for this. I used a number of code examples from this thread in tests. So, custom property values and unknown at-rules are essentially treated as escaped quoted values to allow interpolation. Check out #3213.
Fixes #3147 #2715 (#3213)
matthew-dean commentedon Jun 22, 2018
Fixed.