@@ -1399,55 +1399,83 @@ namespace Sass {
13991399 Compound_Selector* head = s->head ();
14001400 Complex_Selector::Combinator combinator = s->combinator ();
14011401 Selector_List* sl = new (ctx.mem ) Selector_List (s->pstate ());
1402-
14031402 if (head) {
14041403 // check if we have a parent selector reference (expands to list)
1405- if (head->length () > 0 && dynamic_cast <Parent_Selector*>((*head)[0 ])) {
1404+ if (head->length () > 1 && dynamic_cast <Parent_Selector*>((*head)[0 ])) {
14061405 // do we have any parents to interpolate
1407- Selector_List* pr = selector ();
1408- if (pr && pr->length () > 0 ) {
1409- for (size_t n = 0 , nL = pr->length (); n < nL; ++n) {
1410- if (tail) {
1411- vector<Selector_List*> rv;
1412- Selector_List* tails = operator ()(tail);
1413- for (size_t m = 0 , mL = tails->length (); m < mL ; ++m) {
1414- Complex_Selector* ns = (*pr)[n]->cloneFully (ctx);
1415- if (s->has_line_feed ()) ns->has_line_feed (true );
1416- Complex_Selector* tt = (*tails)[m];
1417- Complex_Selector* last = ns->last ();
1418- if (combinator != Complex_Selector::ANCESTOR_OF) {
1419- Complex_Selector* cp = 0 ;
1420- cp = new (ctx.mem ) Complex_Selector (s->pstate ());
1421- cp->head (head); cp->tail (tt);
1422- cp->combinator (combinator);
1423- last->tail (cp);
1424- } else {
1425- last->tail (tt);
1426- }
1427- for (size_t i = 1 , iL = head->length (); i < iL; ++i) {
1428- // add simple selectors
1429- *last->head () << (*head)[i];
1430- }
1431- *sl << ns;
1432- }
1433- // EO foreach parentized tail
1434- } else {
1435- Complex_Selector* ns = (*pr)[n]->cloneFully (ctx);
1436- Complex_Selector* last = ns->last ();
1437- ns->combinator (combinator);
1438- for (size_t i = 1 , iL = head->length (); i < iL; ++i) {
1439- // add simple selectors
1440- *last->head () << (*head)[i];
1406+ if (Selector_List* pr = selector ()) {
1407+ // parent will be prefixed
1408+ Selector_List* ns = pr->cloneFully (ctx);
1409+ // the tail can be re-attached unchanged
1410+ for (size_t n = 0 , nL = ns->length (); n < nL; ++n) {
1411+ Complex_Selector* lst_t = (*ns)[n]->last ();
1412+ Compound_Selector* lst_h = lst_t ->head ();
1413+ for (size_t i = 1 , L = head->length (); i < L; ++i) *lst_h << (*head)[i];
1414+ lst_t ->tail (tail); // now connect old tail back to new intermediate
1415+ lst_t ->combinator (combinator); // and dont forget the combinator
1416+ // if (s->has_line_feed()) lst_t->has_line_feed(true); // and dont forget the combinator
1417+ }
1418+ return ns;
1419+ }
1420+ else {
1421+ Complex_Selector* cpy = s->cloneFully (ctx);
1422+ cpy->head (new (ctx.mem ) Compound_Selector (head->pstate ()));
1423+ for (size_t i = 1 , L = head->length (); i < L; ++i)
1424+ *cpy->head () << (*head)[i];
1425+ *sl << s;
1426+ return sl;
1427+ }
1428+ }
1429+
1430+ // have a simple
1431+ if (head->length () == 1 && dynamic_cast <Parent_Selector*>((*head)[0 ])) {
1432+ // do we have any parents to interpolate
1433+ if (Selector_List* pr = selector ()) {
1434+ // parent will be prefixed
1435+ Selector_List* ns = pr->cloneFully (ctx);
1436+ // the tail can be re-attached unchanged
1437+ for (size_t n = 0 , nL = ns->length (); n < nL; ++n) {
1438+ Complex_Selector* lst = (*ns)[n]->last ();
1439+ lst->tail (tail);
1440+ if (combinator != Complex_Selector::ANCESTOR_OF) {
1441+ if (lst->combinator ()!= Complex_Selector::ANCESTOR_OF) {
1442+ Complex_Selector* ins = s->clone (ctx);
1443+ ins->head (0 );
1444+ ins->tail (tail);
1445+ lst->tail (ins);
1446+ } else {
1447+ lst->combinator (combinator);
14411448 }
1442- *sl << ns;
14431449 }
1450+ if (s->has_line_feed ()) lst->has_line_feed (true );
1451+ if (s->has_line_break ()) lst->has_line_break (true );
14441452 }
1445- parentized = true ;
1453+ return ns;
1454+ }
1455+ else {
1456+ Complex_Selector* ss = s->cloneFully (ctx);
1457+ // check if complex selector can be eliminated
1458+ if (s->combinator () == Complex_Selector::ANCESTOR_OF)
1459+ {
1460+ if (s->has_line_feed ()) tail->has_line_feed (true );
1461+ if (s->has_line_break ()) tail->has_line_break (true );
1462+ *sl << tail;
1463+ }
1464+ else
1465+ {
1466+ *sl << ss;
1467+ }
1468+ return sl;
14461469 }
14471470
14481471 }
14491472
14501473 }
1474+ else
1475+ {
1476+ *sl << s;
1477+ return sl;
1478+ }
14511479
14521480 if (parentized == false ) {
14531481 if (s->tail ()) {
0 commit comments