visitRuleset method

void visitRuleset (Ruleset rulesetNode, VisitArgs visitArgs)

Implementation

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

  final List<Extend> allSelectorsExtendList = <Extend>[];

  // get &:extend(.a); rules which apply to all selectors in this ruleset
  final List<Node> rules = rulesetNode.rules;
  final int ruleCnt = rules?.length ?? 0;
  for (int i = 0; i < ruleCnt; i++) {
    if (rulesetNode.rules[i] is Extend) {
      allSelectorsExtendList.add(rules[i]);
      rulesetNode.extendOnEveryPath = true;
    }
  }

  // now find every selector and apply the extends that apply to all extends
  // and the ones which apply to an individual extend
  final List<List<Selector>> paths = rulesetNode.paths;
  for (int i = 0; i < paths.length; i++) {
    final List<Selector>  selectorPath = paths[i];
    final Selector        selector = selectorPath.last;
    final List<Extend>    selExtendList = selector.extendList;

    List<Extend> extendList = selExtendList != null
        ? (selExtendList.sublist(0)..addAll(allSelectorsExtendList))
        : allSelectorsExtendList;

    if (extendList != null) {
      extendList = extendList
          .map((Extend allSelectorsExtend) => allSelectorsExtend.clone())
          .toList();
    }

    for (int j = 0; j < extendList.length; j++) {
      foundExtends = true;
      final Extend extend = extendList[j]
          ..findSelfSelectors(selectorPath)
          ..ruleset = rulesetNode;
      if (j == 0) extend.firstExtendOnThisSelectorPath = true;
      allExtendsStack.last.add(extend);
    }
  }

  contexts.add(rulesetNode.selectors);

//3.0.0 20150714
// visitRuleset: function (rulesetNode, visitArgs) {
//     if (rulesetNode.root) {
//         return;
//     }
//
//     var i, j, extend, allSelectorsExtendList = [], extendList;
//
//     // get &:extend(.a); rules which apply to all selectors in this ruleset
//     var rules = rulesetNode.rules, ruleCnt = rules ? rules.length : 0;
//     for (i = 0; i < ruleCnt; i++) {
//         if (rulesetNode.rules[i] instanceof tree.Extend) {
//             allSelectorsExtendList.push(rules[i]);
//             rulesetNode.extendOnEveryPath = true;
//         }
//     }
//
//     // now find every selector and apply the extends that apply to all extends
//     // and the ones which apply to an individual extend
//     var paths = rulesetNode.paths;
//     for (i = 0; i < paths.length; i++) {
//         var selectorPath = paths[i],
//             selector = selectorPath[selectorPath.length - 1],
//             selExtendList = selector.extendList;
//
//         extendList = selExtendList ? utils.copyArray(selExtendList).concat(allSelectorsExtendList)
//                                    : allSelectorsExtendList;
//
//         if (extendList) {
//             extendList = extendList.map(function(allSelectorsExtend) {
//                 return allSelectorsExtend.clone();
//             });
//         }
//
//         for (j = 0; j < extendList.length; j++) {
//             this.foundExtends = true;
//             extend = extendList[j];
//             extend.findSelfSelectors(selectorPath);
//             extend.ruleset = rulesetNode;
//             if (j === 0) { extend.firstExtendOnThisSelectorPath = true; }
//             this.allExtendsStack[this.allExtendsStack.length - 1].push(extend);
//         }
//     }
//
//     this.contexts.push(rulesetNode.selectors);
// },
}