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

Fix extending inner of wrapped selectors (unwrap) #2032

Merged
merged 1 commit into from
Apr 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 49 additions & 10 deletions src/extend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "parser.hpp"
#include "node.hpp"
#include "sass_util.hpp"
#include "remove_placeholders.hpp"
#include "debug.hpp"
#include <iostream>
#include <deque>
Expand Down Expand Up @@ -1944,19 +1945,57 @@ namespace Sass {
}
}

for (Complex_Selector* cs : *pNewSelectors) {
while (cs) {
if (cs->head()) {
for (Simple_Selector* ss : *cs->head()) {
if (Wrapped_Selector* ws = dynamic_cast<Wrapped_Selector*>(ss)) {
if (Selector_List* sl = dynamic_cast<Selector_List*>(ws->selector())) {
bool extended = false;
ws->selector(extendSelectorList(sl, ctx, subset_map, false, extended));
Remove_Placeholders remove_placeholders(ctx);
// it seems that we have to remove the place holders early here
// normally we do this as the very last step (compare to ruby sass)
pNewSelectors = remove_placeholders.remove_placeholders(pNewSelectors);

// unwrap all wrapped selectors with inner lists
for (Complex_Selector* cur : *pNewSelectors) {
// process tails
while (cur) {
// process header
if (cur->head()) {
// create a copy since we add multiple items if stuff get unwrapped
Compound_Selector* cpy_head = SASS_MEMORY_NEW(ctx.mem, Compound_Selector, cur->pstate());
for (Simple_Selector* hs : *cur->head()) {
if (Wrapped_Selector* ws = dynamic_cast<Wrapped_Selector*>(hs)) {
if (Selector_List* sl = dynamic_cast<Selector_List*>(ws->selector())) {
// special case for ruby ass
if (sl->empty()) {
// this seems inconsistent but it is how ruby sass seems to remove parentheses
*cpy_head << SASS_MEMORY_NEW(ctx.mem, Type_Selector, hs->pstate(), ws->name());
}
// has wrapped selectors
else {
// extend the inner list of wrapped selector
Selector_List* ext_sl = extendSelectorList(sl, ctx, subset_map);
for (size_t i = 0; i < ext_sl->length(); i += 1) {
if (Complex_Selector* ext_cs = ext_sl->at(i)) {
// create clones for wrapped selector and the inner list
Wrapped_Selector* cpy_ws = SASS_MEMORY_NEW(ctx.mem, Wrapped_Selector, *ws);
Selector_List* cpy_ws_sl = SASS_MEMORY_NEW(ctx.mem, Selector_List, sl->pstate());
// remove parent selectors from inner selector
if (ext_cs->first()) *cpy_ws_sl << ext_cs->first();
// assign list to clone
cpy_ws->selector(cpy_ws_sl);
// append the clone
*cpy_head << cpy_ws;
}
}
}
} else {
*cpy_head << hs;
}
} else {
*cpy_head << hs;
}
}
// replace header
cur->head(cpy_head);
}
}
cs = cs->tail();
// process tail
cur = cur->tail();
}
}
return pNewSelectors;
Expand Down
4 changes: 4 additions & 0 deletions src/extend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ namespace Sass {
public:
static Node subweave(Node& one, Node& two, Context& ctx);
static Selector_List* extendSelectorList(Selector_List* pSelectorList, Context& ctx, ExtensionSubsetMap& subset_map, bool isReplace, bool& extendedSomething);
static Selector_List* extendSelectorList(Selector_List* pSelectorList, Context& ctx, ExtensionSubsetMap& subset_map, bool isReplace = false) {
bool extendedSomething = false;
return extendSelectorList(pSelectorList, ctx, subset_map, isReplace, extendedSomething);
}
Extend(Context&, ExtensionSubsetMap&);
~Extend() { }

Expand Down
6 changes: 2 additions & 4 deletions src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1889,8 +1889,7 @@ namespace Sass {
ExtensionSubsetMap subset_map;
extender->populate_extends(extendee, ctx, subset_map);

bool extendedSomething;
Selector_List* result = Extend::extendSelectorList(selector, ctx, subset_map, false, extendedSomething);
Selector_List* result = Extend::extendSelectorList(selector, ctx, subset_map, false);

Listize listize(ctx.mem);
return result->perform(&listize);
Expand All @@ -1906,8 +1905,7 @@ namespace Sass {
ExtensionSubsetMap subset_map;
replacement->populate_extends(original, ctx, subset_map);

bool extendedSomething;
Selector_List* result = Extend::extendSelectorList(selector, ctx, subset_map, true, extendedSomething);
Selector_List* result = Extend::extendSelectorList(selector, ctx, subset_map, true);

Listize listize(ctx.mem);
return result->perform(&listize);
Expand Down
2 changes: 1 addition & 1 deletion src/remove_placeholders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Sass {

void fallback_impl(AST_Node* n) {}

private:
public:
Selector_List* remove_placeholders(Selector_List*);

public:
Expand Down