-
Notifications
You must be signed in to change notification settings - Fork 463
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
selectors are not correctly parentized in respect to placeholders #1654
Comments
This looks like a ruby sass bug to me, please see this sample: %foo {
border: none;
&bar {
display: block;
}
&.bar {
display: block;
}
}
.zoo {
@extend %foo;
&baz {
display: block;
}
&.baz {
display: block;
}
} Results in ruby sass to: .zoo {
border: none; }
.bar.zoo {
display: block; }
.zoobaz {
display: block; }
.zoo.baz {
display: block; } From the semantics I don't see why libsass should be wrong here? //CC @nex3 @chriseppstein |
@mgreter – We only ran into this issue when using the BEM shorthand notation ( Ruby Sass behaved as we expected. |
What's the reason for having ... &__bar {
display: block;
} ... when it is never output? I mean you seem to expect it to be never output? |
@mgreter – I'll defer to @tomgenoni for the first question but I should have noted that both |
As you can see in my sample posted above, the "prefix" doesn't matter at all. |
@mgreter This is just a reduced case to reproduce the issue. It's a change in behavior from the previous version. You can see the expected output with an earlier version of Libsass and Ruby Sass at http://sassmeister.com/gist/4c34daba378d7269af35 |
@mgreter IMHO this is a bug. It's work noting that
Maybe @chriseppstein can give more information on the exact semantics. |
You all see that ruby sass is not consistent between |
Does this resolve the confusion? |
Not really, why does it work different for |
OK, I think I need to repeat my sample from above, since I'm not sure you see the difference!? .zoo {
&baz {
display: block;
}
&.baz {
display: block;
}
} .zoobaz {
display: block; }
.zoo.baz {
display: block; } vs. %foo {
&bar {
display: block;
}
&.bar {
display: block;
}
}
zoo {
@extend %foo;
} zoo.bar {
display: block;
} This doesn't seem consistent!? |
I think I get it now, so @xzyfer AFAIK you made that implementation. Any thoughts on that one? |
IMO that's pretty funky and not as I intuitively expected it to be. I always thought of it like "add the optional placeholder postfix and the block where the %foo {
&bar {
display: inner;
}
&.bar {
display: outer;
}
}
zoo {
@extend %foobar;
} Ruby Sass result: zoo {
display: inner; } |
I didn't know that about %placeholders. @mgreter the extends implementation IMHO it would be worth while doing a line by line reimplementation of the
|
It appears that with the BEM selector the
expected:
with Libsass v3.3.1:
|
The actual reason is that we parentize selectors after the evaluation step. Ruby sass seems to do it before, but I still try to get together more spec test, so we don't implement it wrongly again. I wonder why this sample does not give any errors nor can I figure out what the correct extend name should be:
@chriseppstein any suggestions if this should be extendable at all or if it should error? |
OK, got some something: moo {
&%foo {
&bar {
display: inner;
}
&.bar {
display: outer;
}
}
}
zoo {
&foo {
@extend moo%foobar;
}
} results in zoofoo {
display: inner; } Is this the expected behavior? Still not very intuitive IMHO! |
It should error. But the reason it is erroring is that you have two element selectors and so there is no way to extend one element by another because every selector can match at most one element name.
Bingo. Before we called them placeholders we called them "silent classes". When in doubt, replace the
I don't see why. Just remove any special handling of placeholder selectors. Treat them exactly like class names. After extend, you remove all selectors that have a placeholder as any selector component.
Yes, this is expected. If we did the operation in the order you suggest, then @extend would not be stable against refactoring the selector hierarchy. This should never happen, nesting is just another way of forming CSS selectors and should never change the semantics of those final selectors. E.g. if someone has written You're not the only one who is confused by this. A lot of people have a hard time understanding |
Using gulp/grunt-sass with libsass v3.3.1:
Outputs
Expected output
cc @danoc
The text was updated successfully, but these errors were encountered: