0

So I'm using some pretty complicated Sass to remove every other selector from "&"

.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}";
    }
}

My expected result for the content attribute is:

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

When using Ruby Sass, this is precisely what I get. When using Libsass, I get this error:

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

This error is referring to code within the custom "to-string" function I'm using:

@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;
}

More specifically, this line:

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

It appears that the value I am passing to the to-string function (which is the $selectors variable) is empty, when it shouldn't be. I initially define it as being empty ($selectors: ();), but then I append every other item from &. So I'm unsure why it's empty at this point.

Here is a Sassmesiter demonstrating the issue: http://sassmeister.com/gist/332dae9a27983edd9d15

Change the compiler in the above demo to Libsass to see it error.

I'm unsure if this is an issue with my code or with Libsass. I don't want to open an issue on Libsass unless I know for sure it is a Libsass problem.

Thanks

ESR
  • 1,669
  • 1
  • 18
  • 22

1 Answers1

0

Ok I got to the bottom of this. Fairly certain it's a Libsass issue.

It looks like you can't loop through each item in & directly, but if I store & in a variable, it proceeds to work.

So to clarify, changing this:

@each $item in & {
    ...
}

to this:

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

Solves the issue.

ESR
  • 1,669
  • 1
  • 18
  • 22