Skip to content
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

nth() doesn't take & as an argument #1267

Closed
cristianl opened this issue Jun 10, 2015 · 2 comments
Closed

nth() doesn't take & as an argument #1267

cristianl opened this issue Jun 10, 2015 · 2 comments

Comments

@cristianl
Copy link

Libsass fails to compile a stylesheet if you try to use the nth() function with & as the first argument; it works if you assign & to a variable first. This is inconsistent with Ruby Sass.

Rationale:
According to the docs (http://sass-lang.com/documentation/Sass/Script/Functions.html#selector_parse-instance_method), & returns a Sass::Script::Value::List. nth() takes a list as its first argument.

Example:

.container {
  .box {
    $_last-selector: nth(&, -1);
    $_targeted-element: nth($_last-selector, -1);
    content: "#{$_targeted-element}";
  }
}

Expected output (from Ruby Sass 3.4.13):

.container .box {
  content: ".box";
}

Result in Libsass 3.2.4: Error — "invalid selector after & on line 3 at column 43"


When I use nth() with a list that was declared manually, Libsass and Sass behave consistently. For instance, if I save the value of & in a variable:

.container {
  .box {
    $_ampersand-list: &;
    $_last-selector: nth($_ampersand-list, -1);
    $_targeted-element: nth($_last-selector, -1);
    content: "#{$_targeted-element}";
  }
}

Output (same in Libsass 3.2.4 and Ruby Sass 3.4.13):

.container .box {
  content: ".box";
}

This also works on Libsass 3.2.4, as expected:

$selector-list: ('.foo' '.bar', '.baz' '.qux');

$_last-selector: nth($selector-list, -1);
$_targeted-element: nth($_last-selector, -1);

#{$_targeted-element} {
  color: whitesmoke;
}

Output (same in Libsass 3.2.4 and Ruby Sass 3.4.13):

.qux {
  color: whitesmoke;
}

This might be related to the issue with @at-root and interpolation (#1043, #1210), though it's closer to how Libsass behaved until 3.2.2 (when interpolated in @at-root, the value of & would simply be ignored), not the current behavior, from 3.2.3 (the value of & is output, but the selector is nested inside its parent, not the root of the stylesheet).

UPDATE: This seems to be another instance of the issue in #1260 and #1122, i.e. & fails in the context of function arguments.

@xzyfer
Copy link
Contributor

xzyfer commented Jun 11, 2015

You're correct this is due to & not being evaluated as a function parameter. As a work around you can use #{&}.

@xzyfer
Copy link
Contributor

xzyfer commented Jun 11, 2015

Closing as this is a duplicate of #1260.

@xzyfer xzyfer closed this as completed Jun 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants