Skip to content

Commit 4ebec9a

Browse files
committed
Merge pull request #1009 from mgreter/bugfix/issue_950
Enable to extend selector groups
2 parents 1f8b7ad + c1c6411 commit 4ebec9a

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

expand.cpp

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -436,26 +436,29 @@ namespace Sass {
436436
To_String to_string(&ctx);
437437
Selector_List* extender = static_cast<Selector_List*>(selector_stack.back());
438438
if (!extender) return 0;
439-
Selector_List* org_extendee = static_cast<Selector_List*>(e->selector());
440-
Selector_List* extendee = static_cast<Selector_List*>(org_extendee->perform(contextualize_eval->with(0, env, backtrace)));
441-
if (extendee->length() != 1) {
442-
error("selector groups may not be extended", extendee->pstate(), backtrace);
443-
}
444-
Complex_Selector* c = (*extendee)[0];
445-
if (!c->head() || c->tail()) {
446-
error("nested selectors may not be extended", c->pstate(), backtrace);
447-
}
448-
Compound_Selector* s = c->head();
449-
s->is_optional(org_extendee->is_optional());
450-
// // need to convert the compound selector into a by-value data structure
451-
// vector<string> target_vec;
452-
// for (size_t i = 0, L = s->length(); i < L; ++i)
453-
// { target_vec.push_back((*s)[i]->perform(&to_string)); }
454-
455-
for (size_t i = 0, L = extender->length(); i < L; ++i) {
456-
// let's test this out
457-
// cerr << "REGISTERING EXTENSION REQUEST: " << (*extender)[i]->perform(&to_string) << " <- " << s->perform(&to_string) << endl;
458-
ctx.subset_map.put(s->to_str_vec(), make_pair((*extender)[i], s));
439+
Contextualize_Eval* eval = contextualize_eval->with(0, env, backtrace);
440+
Selector_List* selector_list = static_cast<Selector_List*>(e->selector());
441+
Selector_List* contextualized = static_cast<Selector_List*>(selector_list->perform(eval));
442+
// ToDo: remove once feature proves stable!
443+
// if (contextualized->length() != 1) {
444+
// error("selector groups may not be extended", extendee->pstate(), backtrace);
445+
// }
446+
for (auto complex_sel : contextualized->elements()) {
447+
Complex_Selector* c = complex_sel;
448+
if (!c->head() || c->tail()) {
449+
error("nested selectors may not be extended", c->pstate(), backtrace);
450+
}
451+
Compound_Selector* compound_sel = c->head();
452+
compound_sel->is_optional(selector_list->is_optional());
453+
// // need to convert the compound selector into a by-value data structure
454+
// vector<string> target_vec;
455+
// for (size_t i = 0, L = compound_sel->length(); i < L; ++i)
456+
// { target_vec.push_back((*compound_sel)[i]->perform(&to_string)); }
457+
for (size_t i = 0, L = extender->length(); i < L; ++i) {
458+
// let's test this out
459+
// cerr << "REGISTERING EXTENSION REQUEST: " << (*extender)[i]->perform(&to_string) << " <- " << compound_sel->perform(&to_string) << endl;
460+
ctx.subset_map.put(compound_sel->to_str_vec(), make_pair((*extender)[i], compound_sel));
461+
}
459462
}
460463
return 0;
461464
}

0 commit comments

Comments
 (0)