Need help understanding selector-extend() behavior with placeholder selectors.

50 views
Skip to first unread message

and...@skybound.ca

unread,
Aug 19, 2015, 1:28:54 AM8/19/15
to Sass
I've been trying to understand the algorithm for selector-extend() and have a question.

Input:

a {
   foo
: selector-extend('a.foo.baz', '.foo', '.baz');
}

Output:

a {
   foo
: a.foo.baz, a.baz;
}

This makes sense so far.  For the second output selector, .foo was replaced with .baz, and was then removed because it is a duplicate class name.  However, when a placeholder selector appears in the first argument, the situation changes:

Input:

a {
   foo
: selector-extend('%a.foo.baz', '.foo', '.baz');
}

Output:

a {
   foo
: %a.baz;
}


Now the original selector is not being included in the output.  Indeed "%a.foo.baz" is a superselector of "%a.baz" and it makes sense to remove it.  But could someone please explain why this unification only happened when a placeholder selector appeared in the input, and not otherwise?

Natalie Weizenbaum

unread,
Aug 21, 2015, 4:06:22 PM8/21/15
to sass-lang
Sass guarantees that the selector resulting from an @extend will always match the original selector with the same specificity as that selector. This means that the original will never be omitted, even if a superselector of it is generated—except when it contains a placeholder. Because placeholders can't be emitted to the document anyway, specificity isn't a reason to keep them around. So they are omitted if a superselector is generated.

--
You received this message because you are subscribed to the Google Groups "Sass" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sass-lang+...@googlegroups.com.
To post to this group, send email to sass...@googlegroups.com.
Visit this group at http://groups.google.com/group/sass-lang.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages