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
Nested lists get flattened in javascript evaluation #1939
Using the rest variable (...) I ran into this weird behavior: lists in the rest variable get flattened when passing into a javascript function like in the example below!
Is this behavior intentional? I was not expecting nested lists to get flattened like that.
Btw., speaking of multidimensional arrays, don't miss that 1 2 3, 4 5, 6 is also a two-dimensional value list in Less (i.e. I wonder how we expect it to be expanded within a javascript evaluation statement).
Hmmm, then implementing the behavior I was expecting would most likely be a breaking change. Wonder if this is used anywhere in the real world...
Looks like 1 2 3, 4 5, 6 you mention turns into [1 2 3, 4 5, 6] - which is invalid and throws errors - so turning that into a multidimensional lists in javascript won't be breaking anything :D
@csshat Btw, LessHat relies on current behavior. At minimum their .transition mixin needs to know whether the arguments list was created as space separated or comma separated.
Both Less and JS are capable of handling lists/arrays of arbitrary nesting depths - logically.
The problem lies in:
Translating value lists (comma separated) and expression lists (space separated) into arrays for javascript consumption loses value/expression context (important when outputing to Less).
Less(/CSS?) syntax only really supports 1(?) possible structure of nested lists; expression lists nested in an value list. Which means that you can loop through your lists and do crazy stuff all you want - but once you need to output a nested list - there's only one game in town.
It's rather trivial to translate both value/expression lists into arrays for javascript consumption (see 39b366e).
But are there any functions exposed when in javascript to handle value/expression lists? I'm thinking functions that would accept a string, eg 1 1 1, 1 1 1, 1 1 1, and return a meaningful object which could have a toString method that would ensure proper value/expression-list formating when returned to Less...
but once you need to output a nested list - there's only one game in town.
Not quite, we still can loop though every item and output through +: and +_: (though all this goes quite verbose) and/or use whatever custom delimiter (with ~"" after all).
P.S.
Less(/CSS?) syntax only really supports 1(?) possible structure of nested lists; expression lists nested in an value list.
Nope as well, consider this example:
@a: 1 2 3;
@b: a b c;
@c: x, y, z;
@d: @a, @b @c;
@e: @d @d;
div {.some-mixin(@a @b, @c, @d; @e;)}
.some-mixin(@list...) {
hello-multiverse: @list;
}
I.e. technically any "type" (i.e. , or ) of array may contain values of any type of array.
I.e. technically any "type" (i.e. , or ) of array may contain values of any type of array.
Which of course does not cancel the fact that in context of CSS a space separated list containing a comma separated list does not make any sense (i.e. only 1 2, 3 4, 5 6 -> [[1, 2], [3, 4], [5, 6]] and vice-versa is reasonable), so in a perfect world a more elegant/generic method to handle such things in a library seems to be to interpret lowest level array as space separated list and higher level array(s) as comma-separated one (if the function/mixin expects multidimensional array as parameter(s) or returns it).
Activity
seven-phases-max commentedon Mar 27, 2014
This issue is somewhat expected since
1, 2, 3; 4, 5; 6syntax was added later than the variable-in-backticks expansion code (i.e. the latter is simply not adapted to support multidimensional value lists). See https://github.com/less/less.js/blob/v1.7.0/lib/less/tree.js#L44. PRs are welcome ;).Btw., speaking of multidimensional arrays, don't miss that
1 2 3, 4 5, 6is also a two-dimensional value list in Less (i.e. I wonder how we expect it to be expanded within a javascript evaluation statement).phloe commentedon Mar 28, 2014
Hmmm, then implementing the behavior I was expecting would most likely be a breaking change. Wonder if this is used anywhere in the real world...
Looks like
1 2 3, 4 5, 6you mention turns into[1 2 3, 4 5, 6]- which is invalid and throws errors - so turning that into a multidimensional lists in javascript won't be breaking anything :Dphloe commentedon Mar 28, 2014
It was almost too easy getting nested lists passed into javascript :) (see https://github.com/rasmusfl0e/less.js/commit/39b366ef790ffa0e899aca6ea26ee4e7db008501)
Going from javascript to less is more problematic though; the level of nesting is limited to 2 by syntax, eg
1 2 3, 4 5, 6- but deeper nesting is possible through rest variables. Hmmm...SomMeri commentedon Mar 29, 2014
I just came to report this :).
Here is my test case:
Current output is:
I expected this:
SomMeri commentedon Mar 29, 2014
@csshat Btw, LessHat relies on current behavior. At minimum their
.transitionmixin needs to know whether the arguments list was created as space separated or comma separated.phloe commentedon Mar 30, 2014
Yeah - context is important.
Both Less and JS are capable of handling lists/arrays of arbitrary nesting depths - logically.
The problem lies in:
It's rather trivial to translate both value/expression lists into arrays for javascript consumption (see 39b366e).
But are there any functions exposed when in javascript to handle value/expression lists? I'm thinking functions that would accept a string, eg
1 1 1, 1 1 1, 1 1 1, and return a meaningful object which could have a toString method that would ensure proper value/expression-list formating when returned to Less...seven-phases-max commentedon Apr 2, 2014
Not quite, we still can loop though every item and output through
+:and+_:(though all this goes quite verbose) and/or use whatever custom delimiter (with~""after all).P.S.
Nope as well, consider this example:
I.e. technically any "type" (i.e.
,or) of array may contain values of any type of array.seven-phases-max commentedon Apr 3, 2014
Which of course does not cancel the fact that in context of CSS a space separated list containing a comma separated list does not make any sense (i.e. only
1 2, 3 4, 5 6->[[1, 2], [3, 4], [5, 6]]and vice-versa is reasonable), so in a perfect world a more elegant/generic method to handle such things in a library seems to be to interpret lowest level array as space separated list and higher level array(s) as comma-separated one (if the function/mixin expects multidimensional array as parameter(s) or returns it).