visitRuleset method

void visitRuleset(
  1. Ruleset rulesetNode,
  2. VisitArgs visitArgs
)

Implementation

void visitRuleset(Ruleset rulesetNode, VisitArgs visitArgs) {
  if (rulesetNode.root) return;

  final allExtends = allExtendsStack.last;
  final extendVisitor = this;
  final selectorsToAdd = <List<Selector>>[];

  // look at each selector path in the ruleset, find any extend matches and then copy, find and replace
  for (var extendIndex = 0; extendIndex < allExtends.length; extendIndex++) {
    for (var pathIndex = 0;
        pathIndex < rulesetNode.paths.length;
        pathIndex++) {
      final selectorPath = rulesetNode.paths[pathIndex];

      // extending extends happens initially, before the main pass
      if (rulesetNode.extendOnEveryPath) continue;
      final extendList = selectorPath.last.extendList;
      if (extendList?.isNotEmpty ?? false) continue;

      final matches = findMatch(allExtends[extendIndex], selectorPath);

      if (matches.isNotEmpty) {
        allExtends[extendIndex].hasFoundMatches = true;
        allExtends[extendIndex]
            .selfSelectors
            .forEach((Selector selfSelector) {
          final extendedSelectors = extendVisitor.extendSelector(
              matches, selectorPath, selfSelector,
              isVisible: allExtends[extendIndex].isVisible());
          selectorsToAdd.add(extendedSelectors);
        });
      }
    }
  }
  rulesetNode.paths.addAll(selectorsToAdd);

//2.5.3 20151120
// visitRuleset: function (rulesetNode, visitArgs) {
//         if (rulesetNode.root) {
//             return;
//         }
//         var matches, pathIndex, extendIndex, allExtends = this.allExtendsStack[this.allExtendsStack.length - 1],
//             selectorsToAdd = [], extendVisitor = this, selectorPath;
//
//         // look at each selector path in the ruleset, find any extend matches and then copy, find and replace
//
//         for (extendIndex = 0; extendIndex < allExtends.length; extendIndex++) {
//             for (pathIndex = 0; pathIndex < rulesetNode.paths.length; pathIndex++) {
//                 selectorPath = rulesetNode.paths[pathIndex];
//
//                 // extending extends happens initially, before the main pass
//                 if (rulesetNode.extendOnEveryPath) { continue; }
//                 var extendList = selectorPath[selectorPath.length - 1].extendList;
//                 if (extendList && extendList.length) { continue; }
//
//                 matches = this.findMatch(allExtends[extendIndex], selectorPath);
//
//                 if (matches.length) {
//                     allExtends[extendIndex].hasFoundMatches = true;
//
//                     allExtends[extendIndex].selfSelectors.forEach(function(selfSelector) {
//                         var extendedSelectors;
//                         extendedSelectors = extendVisitor.extendSelector(matches, selectorPath, selfSelector, allExtends[extendIndex].isVisible());
//                         selectorsToAdd.push(extendedSelectors);
//                     });
//                 }
//             }
//         }
//         rulesetNode.paths = rulesetNode.paths.concat(selectorsToAdd);
//     },
}