diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2018-06-26 00:30:52 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2018-07-01 00:06:35 +0200 |
commit | 84280c5203aa1882cbf4b79b156dbbb75c90b2c8 (patch) | |
tree | cb402a69c9954a2f518751f08b2f7df22d40ea77 /components/selectors/parser.rs | |
parent | aca724ec79cd1393987a8fa83215ae44f1be532b (diff) | |
download | servo-84280c5203aa1882cbf4b79b156dbbb75c90b2c8.tar.gz servo-84280c5203aa1882cbf4b79b156dbbb75c90b2c8.zip |
style: Deindent the serialization loop.
Bug: 1471063
Reviewed-by: xidorn
MozReview-Commit-ID: GPlUAx7YXVb
Diffstat (limited to 'components/selectors/parser.rs')
-rw-r--r-- | components/selectors/parser.rs | 123 |
1 files changed, 62 insertions, 61 deletions
diff --git a/components/selectors/parser.rs b/components/selectors/parser.rs index 3210f1085b0..ac539045115 100644 --- a/components/selectors/parser.rs +++ b/components/selectors/parser.rs @@ -1007,72 +1007,73 @@ impl<Impl: SelectorImpl> ToCss for Selector<Impl> { debug_assert!(!combinators_exhausted); // https://drafts.csswg.org/cssom/#serializing-selectors + if compound.is_empty() { + continue; + } - if !compound.is_empty() { - // 1. If there is only one simple selector in the compound selectors - // which is a universal selector, append the result of - // serializing the universal selector to s. - // - // Check if `!compound.empty()` first--this can happen if we have - // something like `... > ::before`, because we store `>` and `::` - // both as combinators internally. - // - // If we are in this case, after we have serialized the universal - // selector, we skip Step 2 and continue with the algorithm. - let (can_elide_namespace, first_non_namespace) = match &compound[0] { - &Component::ExplicitAnyNamespace | - &Component::ExplicitNoNamespace | - &Component::Namespace(_, _) => (false, 1), - &Component::DefaultNamespace(_) => (true, 1), - _ => (true, 0), - }; - let mut perform_step_2 = true; - if first_non_namespace == compound.len() - 1 { - match (combinators.peek(), &compound[first_non_namespace]) { - // We have to be careful here, because if there is a - // pseudo element "combinator" there isn't really just - // the one simple selector. Technically this compound - // selector contains the pseudo element selector as well - // -- Combinator::PseudoElement, just like - // Combinator::SlotAssignment, don't exist in the - // spec. - (Some(&&Component::Combinator(Combinator::PseudoElement)), _) | - (Some(&&Component::Combinator(Combinator::SlotAssignment)), _) => (), - (_, &Component::ExplicitUniversalType) => { - // Iterate over everything so we serialize the namespace - // too. - for simple in compound.iter() { - simple.to_css(dest)?; - } - // Skip step 2, which is an "otherwise". - perform_step_2 = false; - }, - (_, _) => (), - } + // 1. If there is only one simple selector in the compound selectors + // which is a universal selector, append the result of + // serializing the universal selector to s. + // + // Check if `!compound.empty()` first--this can happen if we have + // something like `... > ::before`, because we store `>` and `::` + // both as combinators internally. + // + // If we are in this case, after we have serialized the universal + // selector, we skip Step 2 and continue with the algorithm. + let (can_elide_namespace, first_non_namespace) = match compound[0] { + Component::ExplicitAnyNamespace | + Component::ExplicitNoNamespace | + Component::Namespace(..) => (false, 1), + Component::DefaultNamespace(..) => (true, 1), + _ => (true, 0), + }; + let mut perform_step_2 = true; + if first_non_namespace == compound.len() - 1 { + match (combinators.peek(), &compound[first_non_namespace]) { + // We have to be careful here, because if there is a + // pseudo element "combinator" there isn't really just + // the one simple selector. Technically this compound + // selector contains the pseudo element selector as well + // -- Combinator::PseudoElement, just like + // Combinator::SlotAssignment, don't exist in the + // spec. + (Some(&&Component::Combinator(Combinator::PseudoElement)), _) | + (Some(&&Component::Combinator(Combinator::SlotAssignment)), _) => (), + (_, &Component::ExplicitUniversalType) => { + // Iterate over everything so we serialize the namespace + // too. + for simple in compound.iter() { + simple.to_css(dest)?; + } + // Skip step 2, which is an "otherwise". + perform_step_2 = false; + }, + (_, _) => (), } + } - // 2. Otherwise, for each simple selector in the compound selectors - // that is not a universal selector of which the namespace prefix - // maps to a namespace that is not the default namespace - // serialize the simple selector and append the result to s. - // - // See https://github.com/w3c/csswg-drafts/issues/1606, which is - // proposing to change this to match up with the behavior asserted - // in cssom/serialize-namespaced-type-selectors.html, which the - // following code tries to match. - if perform_step_2 { - for simple in compound.iter() { - if let Component::ExplicitUniversalType = *simple { - // Can't have a namespace followed by a pseudo-element - // selector followed by a universal selector in the same - // compound selector, so we don't have to worry about the - // real namespace being in a different `compound`. - if can_elide_namespace { - continue; - } + // 2. Otherwise, for each simple selector in the compound selectors + // that is not a universal selector of which the namespace prefix + // maps to a namespace that is not the default namespace + // serialize the simple selector and append the result to s. + // + // See https://github.com/w3c/csswg-drafts/issues/1606, which is + // proposing to change this to match up with the behavior asserted + // in cssom/serialize-namespaced-type-selectors.html, which the + // following code tries to match. + if perform_step_2 { + for simple in compound.iter() { + if let Component::ExplicitUniversalType = *simple { + // Can't have a namespace followed by a pseudo-element + // selector followed by a universal selector in the same + // compound selector, so we don't have to worry about the + // real namespace being in a different `compound`. + if can_elide_namespace { + continue; } - simple.to_css(dest)?; } + simple.to_css(dest)?; } } |