Format style component.

This commit is contained in:
chansuke 2018-09-09 16:24:45 +02:00 committed by Emilio Cobos Álvarez
parent 31fc6cd565
commit 8dab4d659a
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
120 changed files with 2207 additions and 1417 deletions

View file

@ -110,8 +110,9 @@ impl<'b> TopLevelRuleParser<'b> {
// If there's anything that isn't a namespace rule (or import rule, but
// we checked that already at the beginning), reject with a
// StateError.
if new_state == State::Namespaces &&
ctx.rule_list[ctx.index..].iter().any(|r| !matches!(*r, CssRule::Namespace(..)))
if new_state == State::Namespaces && ctx.rule_list[ctx.index..]
.iter()
.any(|r| !matches!(*r, CssRule::Namespace(..)))
{
self.dom_error = Some(RulesMutateError::InvalidState);
return false;
@ -227,7 +228,7 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
}
if !self.check_state(State::Body) {
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
AtRuleParser::parse_prelude(&mut self.nested(), name, input)
@ -254,7 +255,8 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
) -> CssRule {
match prelude {
AtRuleNonBlockPrelude::Import(url, media) => {
let loader = self.loader
let loader = self
.loader
.expect("Expected a stylesheet loader for @import");
let import_rule = loader.request_stylesheet(
@ -299,7 +301,7 @@ impl<'a, 'i> QualifiedRuleParser<'i> for TopLevelRuleParser<'a> {
input: &mut Parser<'i, 't>,
) -> Result<Self::Prelude, ParseError<'i>> {
if !self.check_state(State::Body) {
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
QualifiedRuleParser::parse_prelude(&mut self.nested(), input)
@ -312,15 +314,12 @@ impl<'a, 'i> QualifiedRuleParser<'i> for TopLevelRuleParser<'a> {
location: SourceLocation,
input: &mut Parser<'i, 't>,
) -> Result<CssRule, ParseError<'i>> {
QualifiedRuleParser::parse_block(
&mut self.nested(),
prelude,
location,
input,
).map(|result| {
self.state = State::Body;
result
})
QualifiedRuleParser::parse_block(&mut self.nested(), prelude, location, input).map(
|result| {
self.state = State::Body;
result
},
)
}
}
@ -338,11 +337,7 @@ impl<'a, 'b> NestedRuleParser<'a, 'b> {
input: &mut Parser,
rule_type: CssRuleType,
) -> Arc<Locked<CssRules>> {
let context = ParserContext::new_with_rule_type(
self.context,
rule_type,
self.namespaces,
);
let context = ParserContext::new_with_rule_type(self.context, rule_type, self.namespaces);
let nested_parser = NestedRuleParser {
stylesheet_origin: self.stylesheet_origin,
@ -478,12 +473,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
);
Ok(CssRule::FontFeatureValues(Arc::new(self.shared_lock.wrap(
FontFeatureValuesRule::parse(
&context,
input,
family_names,
source_location,
),
FontFeatureValuesRule::parse(&context, input, family_names, source_location),
))))
},
AtRuleBlockPrelude::CounterStyle(name) => {
@ -493,16 +483,9 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
self.namespaces,
);
Ok(CssRule::CounterStyle(Arc::new(
self.shared_lock.wrap(
parse_counter_style_body(
name,
&context,
input,
source_location,
)?.into(),
),
)))
Ok(CssRule::CounterStyle(Arc::new(self.shared_lock.wrap(
parse_counter_style_body(name, &context, input, source_location)?.into(),
))))
},
AtRuleBlockPrelude::Media(media_queries) => {
Ok(CssRule::Media(Arc::new(self.shared_lock.wrap(MediaRule {
@ -535,9 +518,9 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
self.namespaces,
);
Ok(CssRule::Viewport(Arc::new(self.shared_lock.wrap(
ViewportRule::parse(&context, input)?,
))))
Ok(CssRule::Viewport(Arc::new(
self.shared_lock.wrap(ViewportRule::parse(&context, input)?),
)))
},
AtRuleBlockPrelude::Keyframes(name, vendor_prefix) => {
let context = ParserContext::new_with_rule_type(
@ -549,11 +532,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
Ok(CssRule::Keyframes(Arc::new(self.shared_lock.wrap(
KeyframesRule {
name,
keyframes: parse_keyframe_list(
&context,
input,
self.shared_lock,
),
keyframes: parse_keyframe_list(&context, input, self.shared_lock),
vendor_prefix,
source_location,
},
@ -566,8 +545,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
self.namespaces,
);
let declarations =
parse_property_declaration_list(&context, input);
let declarations = parse_property_declaration_list(&context, input);
Ok(CssRule::Page(Arc::new(self.shared_lock.wrap(PageRule {
block: Arc::new(self.shared_lock.wrap(declarations)),
source_location,