diff --git a/src/fn_selectors.cpp b/src/fn_selectors.cpp index eb2e1382b5..34142bb81c 100644 --- a/src/fn_selectors.cpp +++ b/src/fn_selectors.cpp @@ -16,18 +16,21 @@ namespace Sass { List* arglist = ARG("$selectors", List); // Not enough parameters - if( arglist->length() == 0 ) - error("$selectors: At least one selector must be passed for `selector-nest'", pstate, traces); + if (arglist->length() == 0) { + error( + "$selectors: At least one selector must be passed for `selector-nest'", + pstate, traces); + } // Parse args into vector of selectors SelectorStack parsedSelectors; for (size_t i = 0, L = arglist->length(); i < L; ++i) { Expression_Obj exp = Cast(arglist->value_at_index(i)); if (exp->concrete_type() == Expression::NULL_VAL) { - std::stringstream msg; - msg << "$selectors: null is not a valid selector: it must be a string,\n"; - msg << "a list of strings, or a list of lists of strings for 'selector-nest'"; - error(msg.str(), pstate, traces); + error( + "$selectors: null is not a valid selector: it must be a string,\n" + "a list of strings, or a list of lists of strings for 'selector-nest'", + pstate, traces); } if (String_Constant_Obj str = Cast(exp)) { str->quote_mark(0); @@ -42,23 +45,18 @@ namespace Sass { return SASS_MEMORY_NEW(Null, pstate); } - // Set the first element as the `result`, keep appending to as we go down the parsedSelector vector. + // Set the first element as the `result`, keep + // appending to as we go down the parsedSelector vector. SelectorStack::iterator itr = parsedSelectors.begin(); - SelectorListObj result = *itr; + SelectorListObj& result = *itr; ++itr; for(;itr != parsedSelectors.end(); ++itr) { - SelectorListObj child = *itr; - std::vector exploded; - selector_stack.push_back(result); + SelectorListObj& child = *itr; original_stack.push_back(result); SelectorListObj rv = child->resolve_parent_refs(original_stack, traces); - selector_stack.pop_back(); + result->elements(rv->elements()); original_stack.pop_back(); - for (size_t m = 0, mLen = rv->length(); m < mLen; ++m) { - exploded.push_back((*rv)[m]); - } - result->elements(exploded); } return Cast(Listize::perform(result)); @@ -71,34 +69,36 @@ namespace Sass { // Not enough parameters if (arglist->empty()) { - error("$selectors: At least one selector must be " - "passed for `selector-append'", pstate, traces); + error( + "$selectors: At least one selector must be " + "passed for `selector-append'", + pstate, traces); } // Parse args into vector of selectors SelectorStack parsedSelectors; parsedSelectors.push_back({}); for (size_t i = 0, L = arglist->length(); i < L; ++i) { - Expression_Obj exp = Cast(arglist->value_at_index(i)); + Expression* exp = Cast(arglist->value_at_index(i)); if (exp->concrete_type() == Expression::NULL_VAL) { - std::stringstream msg; - msg << "$selectors: null is not a valid selector: it must be a string,\n"; - msg << "a list of strings, or a list of lists of strings for 'selector-append'"; - error(msg.str(), pstate, traces); + error( + "$selectors: null is not a valid selector: it must be a string,\n" + "a list of strings, or a list of lists of strings for 'selector-append'", + pstate, traces); } if (String_Constant* str = Cast(exp)) { str->quote_mark(0); } std::string exp_src = exp->to_string(); SelectorListObj sel = Parser::parse_selector(exp_src.c_str(), ctx, traces, - exp->pstate(), pstate.src, - /*allow_parent=*/true); + exp->pstate(), pstate.src, + /*allow_parent=*/true); - for (auto complex : sel->elements()) { + for (auto& complex : sel->elements()) { if (complex->empty()) { complex->append(SASS_MEMORY_NEW(CompoundSelector, "[phony]")); } - if (CompoundSelectorObj comp = Cast(complex->first())) { + if (CompoundSelector* comp = Cast(complex->first())) { comp->hasRealParent(true); complex->chroots(true); } @@ -108,13 +108,14 @@ namespace Sass { if (!sel->has_real_parent_ref()) { auto parent = parsedSelectors.back(); - for (auto complex : parent->elements()) { - if (CompoundSelectorObj comp = Cast(complex->first())) { + for (auto& complex : parent->elements()) { + if (CompoundSelector* comp = Cast(complex->first())) { comp->hasRealParent(false); } } error("Can't append \"" + sel->to_string() + "\" to \"" + - parent->to_string() + "\" for `selector-append'", pstate, traces); + parent->to_string() + "\" for `selector-append'", + pstate, traces); } // Build the resolved stack from the left. It's cheaper to directly @@ -155,7 +156,7 @@ namespace Sass { List* l = SASS_MEMORY_NEW(List, sel->pstate(), sel->length(), SASS_COMMA); for (size_t i = 0, L = sel->length(); i < L; ++i) { - SimpleSelectorObj ss = (*sel)[i]; + const SimpleSelectorObj& ss = sel->get(i); std::string ss_string = ss->to_string() ; l->append(SASS_MEMORY_NEW(String_Quoted, ss->pstate(), ss_string)); }