From 7334298f3018f4be1b20bdaf58efd4f67beeda4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jim=C3=A9nez=20Moreno?= Date: Wed, 14 Jun 2017 17:47:30 +0200 Subject: [PATCH] stylo: set location for NestedRuleParser during prelude parsing --- components/style/stylesheets/rule_parser.rs | 31 +++++++++++++-------- tests/unit/style/stylesheets.rs | 6 ++-- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/components/style/stylesheets/rule_parser.rs b/components/style/stylesheets/rule_parser.rs index 34db0c1d69f..0cecb8bf36a 100644 --- a/components/style/stylesheets/rule_parser.rs +++ b/components/style/stylesheets/rule_parser.rs @@ -257,15 +257,19 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> { } } +pub struct QualifiedRuleParserPrelude { + selectors: SelectorList, + source_location: SourceLocation, +} impl<'a, 'i> QualifiedRuleParser<'i> for TopLevelRuleParser<'a> { - type Prelude = SelectorList; + type Prelude = QualifiedRuleParserPrelude; type QualifiedRule = CssRule; type Error = SelectorParseError<'i, StyleParseError<'i>>; #[inline] fn parse_prelude<'t>(&mut self, input: &mut Parser<'i, 't>) - -> Result, ParseError<'i>> { + -> Result> { self.state = State::Body; // "Freeze" the namespace map (no more namespace rules can be parsed @@ -281,7 +285,7 @@ impl<'a, 'i> QualifiedRuleParser<'i> for TopLevelRuleParser<'a> { #[inline] fn parse_block<'t>( &mut self, - prelude: SelectorList, + prelude: QualifiedRuleParserPrelude, input: &mut Parser<'i, 't> ) -> Result> { QualifiedRuleParser::parse_block(&mut self.nested(), prelude, input) @@ -482,33 +486,38 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> { } impl<'a, 'b, 'i> QualifiedRuleParser<'i> for NestedRuleParser<'a, 'b> { - type Prelude = SelectorList; + type Prelude = QualifiedRuleParserPrelude; type QualifiedRule = CssRule; type Error = SelectorParseError<'i, StyleParseError<'i>>; fn parse_prelude<'t>(&mut self, input: &mut Parser<'i, 't>) - -> Result, ParseError<'i>> { + -> Result> { let selector_parser = SelectorParser { stylesheet_origin: self.stylesheet_origin, namespaces: self.context.namespaces.unwrap(), }; - SelectorList::parse(&selector_parser, input) + let location = get_location_with_offset(input.current_source_location(), + self.context.line_number_offset); + let selectors = SelectorList::parse(&selector_parser, input)?; + + Ok(QualifiedRuleParserPrelude { + selectors: selectors, + source_location: location, + }) } fn parse_block<'t>( &mut self, - prelude: SelectorList, + prelude: QualifiedRuleParserPrelude, input: &mut Parser<'i, 't> ) -> Result> { - let location = get_location_with_offset(input.current_source_location(), - self.context.line_number_offset); let context = ParserContext::new_with_rule_type(self.context, Some(CssRuleType::Style)); let declarations = parse_property_declaration_list(&context, input); Ok(CssRule::Style(Arc::new(self.shared_lock.wrap(StyleRule { - selectors: prelude, + selectors: prelude.selectors, block: Arc::new(self.shared_lock.wrap(declarations)), - source_location: location, + source_location: prelude.source_location, })))) } } diff --git a/tests/unit/style/stylesheets.rs b/tests/unit/style/stylesheets.rs index a7929f89467..1c806af2e9c 100644 --- a/tests/unit/style/stylesheets.rs +++ b/tests/unit/style/stylesheets.rs @@ -116,7 +116,7 @@ fn test_parse_stylesheet() { ]))), source_location: SourceLocation { line: 3, - column: 31, + column: 9, }, }))), CssRule::Style(Arc::new(stylesheet.shared_lock.wrap(StyleRule { @@ -143,7 +143,7 @@ fn test_parse_stylesheet() { ]))), source_location: SourceLocation { line: 11, - column: 27, + column: 9, }, }))), CssRule::Style(Arc::new(stylesheet.shared_lock.wrap(StyleRule { @@ -205,7 +205,7 @@ fn test_parse_stylesheet() { ]))), source_location: SourceLocation { line: 15, - column: 20, + column: 9, }, }))), CssRule::Keyframes(Arc::new(stylesheet.shared_lock.wrap(KeyframesRule {