mirror of
https://github.com/servo/servo.git
synced 2025-06-20 07:08:59 +01:00
style: Simplify a bit media query construction.
MozReview-Commit-ID: 3eqezFFWgNZ
This commit is contained in:
parent
88505dc2ff
commit
001c50bcca
1 changed files with 11 additions and 15 deletions
|
@ -77,17 +77,10 @@ impl MediaQuery {
|
||||||
/// Return a media query that never matches, used for when we fail to parse
|
/// Return a media query that never matches, used for when we fail to parse
|
||||||
/// a given media query.
|
/// a given media query.
|
||||||
fn never_matching() -> Self {
|
fn never_matching() -> Self {
|
||||||
Self::new(Some(Qualifier::Not), MediaQueryType::All, vec![])
|
Self {
|
||||||
}
|
qualifier: Some(Qualifier::Not),
|
||||||
|
media_type: MediaQueryType::All,
|
||||||
/// Trivially constructs a new media query.
|
expressions: vec![],
|
||||||
pub fn new(qualifier: Option<Qualifier>,
|
|
||||||
media_type: MediaQueryType,
|
|
||||||
expressions: Vec<Expression>) -> MediaQuery {
|
|
||||||
MediaQuery {
|
|
||||||
qualifier: qualifier,
|
|
||||||
media_type: media_type,
|
|
||||||
expressions: expressions,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,9 +202,12 @@ impl MediaQuery {
|
||||||
|
|
||||||
let media_type = match input.try(|i| i.expect_ident_cloned()) {
|
let media_type = match input.try(|i| i.expect_ident_cloned()) {
|
||||||
Ok(ident) => {
|
Ok(ident) => {
|
||||||
let result: Result<_, ParseError> = MediaQueryType::parse(&*ident)
|
MediaQueryType::parse(&*ident)
|
||||||
.map_err(|()| input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone())));
|
.map_err(|()| {
|
||||||
result?
|
input.new_custom_error(
|
||||||
|
SelectorParseErrorKind::UnexpectedIdent(ident.clone())
|
||||||
|
)
|
||||||
|
})?
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
// Media type is only optional if qualifier is not specified.
|
// Media type is only optional if qualifier is not specified.
|
||||||
|
@ -229,7 +225,7 @@ impl MediaQuery {
|
||||||
// Parse any subsequent expressions
|
// Parse any subsequent expressions
|
||||||
loop {
|
loop {
|
||||||
if input.try(|input| input.expect_ident_matching("and")).is_err() {
|
if input.try(|input| input.expect_ident_matching("and")).is_err() {
|
||||||
return Ok(MediaQuery::new(qualifier, media_type, expressions))
|
return Ok(MediaQuery { qualifier, media_type, expressions })
|
||||||
}
|
}
|
||||||
expressions.push(Expression::parse(context, input)?)
|
expressions.push(Expression::parse(context, input)?)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue