processRule method

List<CSSRule>? processRule([
  1. SelectorGroup? selectorGroup
])

Implementation

List<CSSRule>? processRule([SelectorGroup? selectorGroup]) {
  if (selectorGroup == null) {
    final directive = processDirective();
    if (directive != null) {
      _maybeEat(TokenKind.SEMICOLON);
      return [directive];
    }
    selectorGroup = processSelectorGroup();
  }
  if (selectorGroup != null) {
    final declarations = processDeclarations();
    CSSStyleDeclaration declaration = declarations.whereType<CSSStyleDeclaration>().last;
    Iterable childRules = declarations.whereType<CSSStyleRule>();
    CSSStyleRule rule = CSSStyleRule(selectorGroup, declaration);
    List<CSSRule> rules = [rule];
    for (CSSStyleRule childRule in childRules) {
      // child Rule
      for (Selector selector in childRule.selectorGroup.selectors) {
        // parentRule
        for (Selector parentSelector in selectorGroup.selectors) {
          List<SimpleSelectorSequence> newSelectorSequences =
              mergeNestedSelector(parentSelector.simpleSelectorSequences, selector.simpleSelectorSequences);
          selector.simpleSelectorSequences.clear();
          selector.simpleSelectorSequences.addAll(newSelectorSequences);
        }
      }
      rules.add(childRule);
    }
    return rules;
  }
  return null;
}