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 extend issue being stuck in endless loop #3007

Merged
merged 2 commits into from
Oct 23, 2019
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
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