Skip to content

v0.31.0 RuleListParser::new_for_stylesheet not returning all classes #366

Closed
@j-mendez

Description

@j-mendez

Hi, thank you for the crate! It looks like v0.31.0 using RuleListParser::new_for_stylesheet all of the classes set are not returned.
I have a large stylesheet that parses correctly in v0.25.0 but, the same logic on v0.31.0 only 3 classes out of like 1000 get applied.

Trying to figure out how to debug the issue:

attached is the SelectorList:

use crate::engine::styles::errors::RuleParseErrorKind;
use cssparser::{AtRuleParser, ParseError, QualifiedRuleParser};
use scraper::selector::Simple;
use selectors::parser::ParseRelative;
use std::sync::Arc;

#[derive(Debug)]
pub enum CssRule {
    StyleRule {
        selectors: selectors::SelectorList<Simple>,
        block: Arc<String>,
    },
}

pub struct Parser;

impl<'i> selectors::parser::Parser<'i> for Parser {
    type Impl = Simple;
    type Error = RuleParseErrorKind<'i>;
}

pub type SelectorList = selectors::SelectorList<Simple>;

pub struct RulesParser;

impl<'i> QualifiedRuleParser<'i> for RulesParser {
    type Prelude = SelectorList;
    type QualifiedRule = CssRule;
    type Error = RuleParseErrorKind<'i>;

    fn parse_prelude<'t>(
        &mut self,
        parser: &mut cssparser::Parser<'i, 't>,
    ) -> Result<Self::Prelude, ParseError<'i, Self::Error>> {
        SelectorList::parse(&Parser, parser, ParseRelative::No)
    }

    fn parse_block<'t>(
        &mut self,
        prelude: Self::Prelude,
        _location: &cssparser::ParserState,
        _parser: &mut cssparser::Parser<'i, 't>,
    ) -> Result<Self::QualifiedRule, ParseError<'i, Self::Error>> {
        Ok(CssRule::StyleRule {
            selectors: prelude,
            block: Arc::new(String::new()),
        })
    }
}

impl<'i> AtRuleParser<'i> for RulesParser {
    type Prelude = ();
    type AtRule = CssRule;
    type Error = RuleParseErrorKind<'i>;
}

main:

    let mut _css_parser = cssparser::Parser::new(css_rules);
    let css_rules_parser = cssparser::RuleListParser::new_for_stylesheet(
        &mut _css_parser,
        crate::engine::styles::rules::RulesParser,
    );

    let mut rules = Vec::new();

    for result in css_rules_parser {
        match result {
            Ok(crate::engine::styles::rules::CssRule::StyleRule { selectors, block }) => {
                for selector in selectors.0 {
                    rules.push((selector, block.clone()));
                }
            }
            _ => (),
        };
    }

    println!("CSS RULES: {:?}", rules);

I have an example repo of the issue in this project across two branches kayle. The branch with the correct class list is called victor-stub ( thank you @SimonSapin ).

wasm-pack build --target nodejs to build the wasm crate and in the root folder run yarn test:puppeteer:innate for the test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions