flatten method

void flatten(
  1. StyleSheet styleSheet
)

Replace the rule set that contains nested rules with the flatten rule sets.

Implementation

void flatten(StyleSheet styleSheet) {
  // TODO(terry): Iterate over topLevels instead of _expansions it's already
  //              a map (this maybe quadratic).
  _expansions.forEach((RuleSet ruleSet, List<RuleSet> newRules) {
    var index = styleSheet.topLevels.indexOf(ruleSet);
    if (index == -1) {
      // Check any @media directives for nested rules and replace them.
      var found = _MediaRulesReplacer.replace(styleSheet, ruleSet, newRules);
      assert(found);
    } else {
      styleSheet.topLevels.insertAll(index + 1, newRules);
    }
  });
  _expansions.clear();
}