【问题标题】:Sass won't compile when using Libsass (argument must not be empty)使用 Libsass 时 Sass 不会编译(参数不能为空)
【发布时间】:2015-09-04 11:07:46
【问题描述】:

所以我正在使用一些非常复杂的 Sass 从“&”中删除所有其他选择器

.test, .test-2, .test-3, .test-4 {
    $selectors: (&);
    @if length(&) != 1 {
        $selectors: (); // Works only with Ruby Sass
        $i: 1;
        @each $item in (&) {
            $i: $i + 1;
            @if $i % 2 == 0 {
                $i: 0;
            }@else{
                $selectors: append($selectors, $item);
            }
        }
      $selectors: to-string($selectors, ", ");
        content: "#{$selectors}";
    }
}

我对内容属性的预期结果是:

content: ".test-2, .test-4";

当使用 Ruby Sass 时,这正是我得到的。使用 Libsass 时出现此错误:

argument `$list` of `nth($list, $n)` must not be empty 

这个错误是指我正在使用的自定义“to-string”函数中的代码:

@function to-string($list, $glue: '', $is-nested: false, $recursive: false) {
    $result: null;
    @for $i from 1 through length($list) {
        $e: nth($list, $i);
        @if type-of($e) == list and $recursive {
            $result: $result#{to-string($e, $glue, true)};
        }  
        @else {
            $result: if(
                $i != length($list) or $is-nested, 
                $result#{$e}#{$glue}, $result#{$e}
            );
        }
    }
    @return $result;
}

更具体地说,这一行:

$e: nth($list, $i);

看来,我传递给to-string 函数(即$selectors 变量)的值是空的,而它不应该是空的。我最初将其定义为空 ($selectors: ();),但随后我从 & 中附加所有其他项目。所以我不确定为什么此时它是空的。

这里有一个 Sassmesiter 演示了这个问题:http://sassmeister.com/gist/332dae9a27983edd9d15

把上面demo中的编译器改成Libsass看看报错。

我不确定这是我的代码还是 Libsass 的问题。我不想在 Libsass 上打开一个问题,除非我确定这是一个 Libsass 问题。

谢谢

【问题讨论】:

    标签: sass libsass


    【解决方案1】:

    好的,我明白了。相当肯定这是一个 Libsass 问题。

    看起来你不能直接循环遍历& 中的每个项目,但是如果我将& 存储在一个变量中,它就会继续工作。

    所以澄清一下,改变这个:

    @each $item in & {
        ...
    }
    

    到这里:

    $this: &;
    @each $item in $this {
        ...
    }
    

    解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-26
      • 1970-01-01
      • 2015-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-13
      相关资源
      最近更新 更多