Skip to content

Commit

Permalink
Don't drop pseudo elements in wrapped selectors
Browse files Browse the repository at this point in the history
The extend visitor currently mutates some selectors, even ones that
get extended. This patch works around a specific use case that breaks
foundation.

Spec sass/sass-spec#949
Fixes sass#2200
  • Loading branch information
xzyfer committed Oct 17, 2016
1 parent 7e6c36b commit 0091e0a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/debugger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ inline void debug_ast(AST_Node* node, std::string ind, Env* env)
std::cerr << ind << "Sequence_Selector " << selector
<< " (" << pstate_source_position(node) << ")"
<< " <" << selector->hash() << ">"
<< " [length:" << longToHex(selector->length()) << "]"
<< " [weight:" << longToHex(selector->specificity()) << "]"
<< " [@media:" << selector->media_block() << "]"
<< (selector->is_invisible() ? " [INVISIBLE]": " -")
Expand Down
31 changes: 12 additions & 19 deletions src/extend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1722,23 +1722,6 @@ namespace Sass {
SimpleSequence_Selector* pHead = pIter->head();

if (pHead) {
if (seen.find(*pHead) == seen.end()) {
for (Simple_Selector* pSimple : *pHead) {
if (Wrapped_Selector* ws = dynamic_cast<Wrapped_Selector*>(pSimple)) {
if (CommaSequence_Selector* sl = dynamic_cast<CommaSequence_Selector*>(ws->selector())) {
for (Sequence_Selector* cs : sl->elements()) {
while (cs) {
if (complexSelectorHasExtension(cs, ctx, subset_map, seen)) {
hasExtension = true;
break;
}
cs = cs->tail();
}
}
}
}
}
}
SubsetMapEntries entries = subset_map.get_v(pHead->to_str_vec());
for (ExtensionPair ext : entries) {
// check if both selectors have the same media block parent
Expand Down Expand Up @@ -1989,8 +1972,18 @@ namespace Sass {
CommaSequence_Selector* cpy_ws_sl = SASS_MEMORY_NEW(ctx.mem, CommaSequence_Selector, sl->pstate());
// remove parent selectors from inner selector
if (ext_cs->first()) {
if (ext_cs->first()->has_wrapped_selector()) {
continue; // ignore this case for now
// if (ext_cs->first()->has_wrapped_selector()) {
// continue; // ignore this case for now
// }
Wrapped_Selector* ext_ws = dynamic_cast<Wrapped_Selector*>(ext_cs->first()->head()->first());
if (ext_ws/* && ext_cs->length() == 1*/) {
CommaSequence_Selector* ws_cs = dynamic_cast<CommaSequence_Selector*>(ext_ws->selector());
SimpleSequence_Selector* ws_ss = ws_cs->first()->head();
if (!(
dynamic_cast<Pseudo_Selector*>(ws_ss->first()) ||
dynamic_cast<Element_Selector*>(ws_ss->first()) ||
dynamic_cast<Placeholder_Selector*>(ws_ss->first())
)) continue;
}
*cpy_ws_sl << ext_cs->first();
}
Expand Down

0 comments on commit 0091e0a

Please sign in to comment.