-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Each() function #2786
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
Each() function #2786
Conversation
expressions = [], | ||
isSemiColonSeparated, value, arg; | ||
|
||
parserInput.save(); | ||
|
||
while (true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matthew-dean By the way. If we allow all these "mixin-like" arguments for functions, will there be any difference between mixin.arguments()
and function.arguments()
beside the "named arguments" thing? Obviously I'm just considering if this code can be reused somehow. I understand that because of the "named args" they need to return different structures, but are there any other differences?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were various bits I modified from mixin args to functions args. One is that there are legacy IE "function-like" calls that need to be parsed but that mixins don't parse. (Which I'm not sure are still needed, but it's possible that legacy CSS code continues to persist in currently-used mixins.) It's possible that may be the only real variation, at least for calls. The code for mixin args is re-used between both mixin calls and mixin definitions, so it's possible we could collapse args for "function calls" and "mixin calls", and break out mixin definitions? Or maybe could just collapse all 3 with appropriate if
statements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks... Yes, it seems to need more investigations on possible unifications.
I was just about to experiment with some @var(args...);
stuff, and realized that having three distinct functions to handle pretty much the same syntax would be somewhat an overkill. Additionally I recall that for #1857, I was also thinking of allowing @arg...
stuff for functions too, but quickly bailed out because of all these differences :(
Closing this PR. |
The each() function relies on the root function functionality of the recent
@plugin
PR, so those files show as part of this PR.This addresses the thread in: #2270 and probably a lot of other related looping / lambda issues. There were a lot of syntax suggestions in #2270, so feedback welcome.
Basically, each has a pretty simple signature:
each([list], [variableNames], [ruleset])
Variable names are optional, but necessary if you want to do fancy things with nested
each
es (like access the parent item or index), just because of the way variable scope works in Less.Just like the
@arguments
variable, the each function assigns a special var for the list item and index, named by default@item
and@index
.So, it looks like this:
Here's an advanced
each()
example added to tests:One minor note: this PR also separates list functions into their own function file.