зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #19536 - style: Move the code to parse a list of compound selectors (from emilio:compound-selector-list); r=mbrubeck
I'll need this for ::slotted(). Source-Repo: https://github.com/servo/servo Source-Revision: c6bf85eca90b9cb71ff05d4454a43a7da5fc3ac8 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 02f9868af7469734b70d02e8ddb0470a9c8d407d
This commit is contained in:
Родитель
8093a3dd29
Коммит
be9bd84788
|
@ -55,6 +55,7 @@ pub enum SelectorParseErrorKind<'i> {
|
|||
EmptySelector,
|
||||
DanglingCombinator,
|
||||
NonSimpleSelectorInNegation,
|
||||
NonCompoundSelector,
|
||||
UnexpectedTokenInAttributeSelector(Token<'i>),
|
||||
PseudoElementExpectedColon(Token<'i>),
|
||||
PseudoElementExpectedIdent(Token<'i>),
|
||||
|
@ -209,6 +210,33 @@ impl<Impl: SelectorImpl> SelectorList<Impl> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Parse a comma separated list of compound selectors.
|
||||
pub fn parse_compound_selector_list<'i, 't, P, Impl>(
|
||||
parser: &P,
|
||||
input: &mut CssParser<'i, 't>,
|
||||
) -> Result<Box<[Selector<Impl>]>, ParseError<'i, P::Error>>
|
||||
where
|
||||
P: Parser<'i, Impl=Impl>,
|
||||
Impl: SelectorImpl,
|
||||
{
|
||||
let location = input.current_source_location();
|
||||
let selectors = input.parse_comma_separated(|input| {
|
||||
Selector::parse(parser, input)
|
||||
})?;
|
||||
|
||||
// Ensure they're actually all compound selectors.
|
||||
if selectors
|
||||
.iter()
|
||||
.flat_map(|x| x.iter_raw_match_order())
|
||||
.any(|s| s.is_combinator()) {
|
||||
return Err(location.new_custom_error(
|
||||
SelectorParseErrorKind::NonCompoundSelector
|
||||
))
|
||||
}
|
||||
|
||||
Ok(selectors.into_boxed_slice())
|
||||
}
|
||||
|
||||
/// Ancestor hashes for the bloom filter. We precompute these and store them
|
||||
/// inline with selectors to optimize cache performance during matching.
|
||||
/// This matters a lot.
|
||||
|
|
|
@ -11,7 +11,7 @@ use gecko_bindings::structs::RawServoSelectorList;
|
|||
use gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI};
|
||||
use selector_parser::{Direction, SelectorParser};
|
||||
use selectors::SelectorList;
|
||||
use selectors::parser::{Selector, SelectorMethods, SelectorParseErrorKind};
|
||||
use selectors::parser::{self as selector_parser, Selector, SelectorMethods, SelectorParseErrorKind};
|
||||
use selectors::visitor::SelectorVisitor;
|
||||
use std::fmt;
|
||||
use string_cache::{Atom, Namespace, WeakAtom, WeakNamespace};
|
||||
|
@ -400,16 +400,12 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
|
|||
NonTSPseudoClass::Dir(Box::new(direction))
|
||||
},
|
||||
"-moz-any" => {
|
||||
let selectors = parser.parse_comma_separated(|input| {
|
||||
Selector::parse(self, input)
|
||||
})?;
|
||||
// Selectors inside `:-moz-any` may not include combinators.
|
||||
if selectors.iter().flat_map(|x| x.iter_raw_match_order()).any(|s| s.is_combinator()) {
|
||||
return Err(parser.new_custom_error(
|
||||
SelectorParseErrorKind::UnexpectedIdent("-moz-any".into())
|
||||
))
|
||||
}
|
||||
NonTSPseudoClass::MozAny(selectors.into_boxed_slice())
|
||||
NonTSPseudoClass::MozAny(
|
||||
selector_parser::parse_compound_selector_list(
|
||||
self,
|
||||
parser,
|
||||
)?
|
||||
)
|
||||
}
|
||||
_ => return Err(parser.new_custom_error(
|
||||
SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name.clone())
|
||||
|
|
Загрузка…
Ссылка в новой задаче