Passing a variable list through .for loop using Less 2.6.1 is unable to compile

放肆的年华 提交于 2019-12-12 01:27:18

问题


I have been using a Less mixin which makes looping in Less, less verbose and is really handy: https://github.com/seven-phases-max/less.curious/

I upgraded from Less 2.6.0 to Less 2.6.1 and now the Less will not compile.

Here's the Less code:

// ............................................................
// .for

.for(@i, @n) {.-each(@i)}
.for(@n)     when (isnumber(@n)) {.for(1, @n)}
.for(@i, @n) when not (@i = @n)  {
.for((@i + (@n - @i) / abs(@n - @i)), @n);
}

// ............................................................
// .for-each

.for(@array)   when (default()) {.for-impl_(length(@array))}
.for-impl_(@i) when (@i > 1)    {.for-impl_((@i - 1))}
.for-impl_(@i) when (@i > 0)    {.-each(extract(@array, @i))}

@gray-base: #000;
@gray-darker: #222;
@gray-dark: #333;
@gray: #555;
@gray-light: #777;
@gray-lighter: #eee;

@gray-type:
 gray,
 gray-base,
 gray-dark,
 gray-darker,
 gray-light,
 gray-lighter;

.gray-type {
    // Mixin to generate the gray font colours for p tags in the font stacks.
    .for(@gray-type); .-each(@name) {
        .@{name} {
            color: @@name;
        }
    }   
}

Here's the expected output:

.gray-type .gray {
  color: #555;
}
.gray-type .gray-base {
  color: #000;
}
.gray-type .gray-dark {
  color: #333;
}
.gray-type .gray-darker {
  color: #222;
}
.gray-type .gray-light {
  color: #777;
}
.gray-type .gray-lighter {
  color: #eee;
}

After upgrading to Less 2.6.1 I get the following error:

>> SyntaxError: variable @[object Object],[object Object] is undefined in less/style.less on line 41, column 3:
>> 40       // Mixin to generate the gray font colours for p tags in the font stacks.
>> 41       .for(@gray-type); .-each(@name) {
>> 42           .@{name} {
Warning: Error compiling less/style.less Use --force to continue.

I think the problem is related to the hyphens being stripped from the variables during compilation, therefore making the variables passed though the list invalid.

Any help would be greatly appreciated.

来源:https://stackoverflow.com/questions/36352716/passing-a-variable-list-through-for-loop-using-less-2-6-1-is-unable-to-compile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!