Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3007 from mgreter/bugfix/3006-extend-with-parent
Browse files Browse the repository at this point in the history
Fix extend issue being stuck in endless loop
  • Loading branch information
mgreter authored Oct 23, 2019
2 parents e116b49 + fdf63e4 commit e820c83
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/eval_selectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ namespace Sass {
SelectorList* Eval::operator()(ComplexSelector* s)
{
bool implicit_parent = !exp.old_at_root_without_rule;
if (is_in_selector_schema) exp.pushToSelectorStack({});
if (is_in_selector_schema) exp.pushNullSelector();
SelectorListObj other = s->resolve_parent_refs(
exp.getSelectorStack(), traces, implicit_parent);
if (is_in_selector_schema) exp.popFromSelectorStack();
exp.getOriginalStack(), traces, implicit_parent);
if (is_in_selector_schema) exp.popNullSelector();

for (size_t i = 0; i < other->length(); i++) {
ComplexSelectorObj sel = other->at(i);
Expand Down
29 changes: 23 additions & 6 deletions src/expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@ namespace Sass {
return 0;
}

void Expand::pushNullSelector()
{
pushToSelectorStack({});
pushToOriginalStack({});
}

void Expand::popNullSelector()
{
popFromOriginalStack();
popFromSelectorStack();
}

SelectorStack Expand::getOriginalStack()
{
return originalStack;
}

SelectorStack Expand::getSelectorStack()
{
return selector_stack;
Expand Down Expand Up @@ -153,15 +170,15 @@ namespace Sass {
Block* bb = operator()(r->block());
Keyframe_Rule_Obj k = SASS_MEMORY_NEW(Keyframe_Rule, r->pstate(), bb);
if (r->schema()) {
pushToSelectorStack({});
pushNullSelector();
k->name(eval(r->schema()));
popFromSelectorStack();
popNullSelector();
}
else if (r->selector()) {
if (SelectorListObj s = r->selector()) {
pushToSelectorStack({});
pushNullSelector();
k->name(eval(s));
popFromSelectorStack();
popNullSelector();
}
}

Expand Down Expand Up @@ -288,10 +305,10 @@ namespace Sass {
Block* ab = a->block();
SelectorList* as = a->selector();
Expression* av = a->value();
pushToSelectorStack({});
pushNullSelector();
if (av) av = av->perform(&eval);
if (as) as = eval(as);
popFromSelectorStack();
popNullSelector();
Block* bb = ab ? operator()(ab) : NULL;
Directive* aa = SASS_MEMORY_NEW(Directive,
a->pstate(),
Expand Down
3 changes: 3 additions & 0 deletions src/expand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ namespace Sass {
SelectorListObj& selector();
SelectorListObj& original();
SelectorListObj popFromSelectorStack();
SelectorStack getOriginalStack();
SelectorStack getSelectorStack();
void pushNullSelector();
void popNullSelector();
void pushToSelectorStack(SelectorListObj selector);

SelectorListObj popFromOriginalStack();
Expand Down
8 changes: 4 additions & 4 deletions src/extender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,10 +1070,10 @@ namespace Sass {
// the result so that, if two selectors are identical, we keep the first one.
std::vector<ComplexSelectorObj> result; size_t numOriginals = 0;

// Use label to quit outer loop
redo:
size_t i = selectors.size();
outer: // Use label to continue loop
while (--i != std::string::npos) {

for (size_t i = selectors.size() - 1; i != std::string::npos; i--) {
const ComplexSelectorObj& complex1 = selectors[i];
// Check if selector in known in existing "originals"
// For custom behavior dart-sass had `isOriginal(complex1)`
Expand All @@ -1083,7 +1083,7 @@ namespace Sass {
for (size_t j = 0; j < numOriginals; j++) {
if (ObjEqualityFn(result[j], complex1)) {
rotateSlice(result, 0, j + 1);
goto redo;
goto outer;
}
}
result.insert(result.begin(), complex1);
Expand Down
4 changes: 2 additions & 2 deletions src/extender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ namespace Sass {
std::unordered_map<
SimpleSelectorObj,
size_t,
ObjHash,
ObjEquality
ObjPtrHash,
ObjPtrEquality
> sourceSpecificity;

// ##########################################################################
Expand Down

0 comments on commit e820c83

Please sign in to comment.