visitRuleSet method
void
visitRuleSet(
- RuleSet node
)
override
Implementation
@override
void visitRuleSet(RuleSet node) {
final oldParent = _parentRuleSet;
var oldNestedSelectorGroups = _nestedSelectorGroup;
if (_nestedSelectorGroup == null) {
// Create top-level selector (may have nested rules).
final newSelectors = node.selectorGroup!.selectors.toList();
_topLevelSelectorGroup = SelectorGroup(newSelectors, node.span);
_nestedSelectorGroup = _topLevelSelectorGroup;
} else {
// Generate new selector groups from the nested rules.
_nestedSelectorGroup = _mergeToFlatten(node);
}
_parentRuleSet = node;
super.visitRuleSet(node);
_parentRuleSet = oldParent;
// Remove nested rules; they're all flatten and in the _expandedRuleSets.
node.declarationGroup.declarations
.removeWhere((declaration) => declaration is RuleSet);
_nestedSelectorGroup = oldNestedSelectorGroups;
// If any expandedRuleSets and we're back at the top-level rule set then
// there were nested rule set(s).
if (_parentRuleSet == null) {
if (_expandedRuleSets.isNotEmpty) {
// Remember ruleset to replace with these flattened rulesets.
_expansions[node] = _expandedRuleSets;
_expandedRuleSets = [];
}
assert(_flatDeclarationGroup == null);
assert(_nestedSelectorGroup == null);
}
}