|
6 | 6 | #include "parser.hpp"
|
7 | 7 | #include "node.hpp"
|
8 | 8 | #include "sass_util.hpp"
|
| 9 | +#include "remove_placeholders.hpp" |
9 | 10 | #include "debug.hpp"
|
10 | 11 | #include <iostream>
|
11 | 12 | #include <deque>
|
@@ -1944,19 +1945,57 @@ namespace Sass {
|
1944 | 1945 | }
|
1945 | 1946 | }
|
1946 | 1947 |
|
1947 |
| - for (Complex_Selector* cs : *pNewSelectors) { |
1948 |
| - while (cs) { |
1949 |
| - if (cs->head()) { |
1950 |
| - for (Simple_Selector* ss : *cs->head()) { |
1951 |
| - if (Wrapped_Selector* ws = dynamic_cast<Wrapped_Selector*>(ss)) { |
1952 |
| - if (Selector_List* sl = dynamic_cast<Selector_List*>(ws->selector())) { |
1953 |
| - bool extended = false; |
1954 |
| - ws->selector(extendSelectorList(sl, ctx, subset_map, false, extended)); |
| 1948 | + Remove_Placeholders remove_placeholders(ctx); |
| 1949 | + // it seems that we have to remove the place holders early here |
| 1950 | + // normally we do this as the very last step (compare to ruby sass) |
| 1951 | + pNewSelectors = remove_placeholders.remove_placeholders(pNewSelectors); |
| 1952 | + |
| 1953 | + // unwrap all wrapped selectors with inner lists |
| 1954 | + for (Complex_Selector* cur : *pNewSelectors) { |
| 1955 | + // process tails |
| 1956 | + while (cur) { |
| 1957 | + // process header |
| 1958 | + if (cur->head()) { |
| 1959 | + // create a copy since we add multiple items if stuff get unwrapped |
| 1960 | + Compound_Selector* cpy_head = SASS_MEMORY_NEW(ctx.mem, Compound_Selector, cur->pstate()); |
| 1961 | + for (Simple_Selector* hs : *cur->head()) { |
| 1962 | + if (Wrapped_Selector* ws = dynamic_cast<Wrapped_Selector*>(hs)) { |
| 1963 | + if (Selector_List* sl = dynamic_cast<Selector_List*>(ws->selector())) { |
| 1964 | + // special case for ruby ass |
| 1965 | + if (sl->empty()) { |
| 1966 | + // this seems inconsistent but it is how ruby sass seems to remove parentheses |
| 1967 | + *cpy_head << SASS_MEMORY_NEW(ctx.mem, Type_Selector, hs->pstate(), ws->name()); |
| 1968 | + } |
| 1969 | + // has wrapped selectors |
| 1970 | + else { |
| 1971 | + // extend the inner list of wrapped selector |
| 1972 | + Selector_List* ext_sl = extendSelectorList(sl, ctx, subset_map); |
| 1973 | + for (size_t i = 0; i < ext_sl->length(); i += 1) { |
| 1974 | + if (Complex_Selector* ext_cs = ext_sl->at(i)) { |
| 1975 | + // create clones for wrapped selector and the inner list |
| 1976 | + Wrapped_Selector* cpy_ws = SASS_MEMORY_NEW(ctx.mem, Wrapped_Selector, *ws); |
| 1977 | + Selector_List* cpy_ws_sl = SASS_MEMORY_NEW(ctx.mem, Selector_List, sl->pstate()); |
| 1978 | + // remove parent selectors from inner selector |
| 1979 | + if (ext_cs->first()) *cpy_ws_sl << ext_cs->first(); |
| 1980 | + // assign list to clone |
| 1981 | + cpy_ws->selector(cpy_ws_sl); |
| 1982 | + // append the clone |
| 1983 | + *cpy_head << cpy_ws; |
| 1984 | + } |
| 1985 | + } |
| 1986 | + } |
| 1987 | + } else { |
| 1988 | + *cpy_head << hs; |
| 1989 | + } |
| 1990 | + } else { |
| 1991 | + *cpy_head << hs; |
1955 | 1992 | }
|
1956 | 1993 | }
|
| 1994 | + // replace header |
| 1995 | + cur->head(cpy_head); |
1957 | 1996 | }
|
1958 |
| - } |
1959 |
| - cs = cs->tail(); |
| 1997 | + // process tail |
| 1998 | + cur = cur->tail(); |
1960 | 1999 | }
|
1961 | 2000 | }
|
1962 | 2001 | return pNewSelectors;
|
|
0 commit comments