checkValidNodes method

void checkValidNodes (List<Node> rules, { bool isRoot })

Check for errors in root

Implementation

void checkValidNodes(List<Node> rules, {bool isRoot}) {
  if (rules == null) return;

  for (int i = 0; i < rules.length; i++) {
    final Node ruleNode = rules[i];
    if (isRoot && ruleNode is Declaration && !ruleNode.variable) {
      error(
          message:
              'Properties must be inside selector blocks. They cannot be in the root',
          index: ruleNode.index,
          filename: ruleNode.currentFileInfo?.filename);
    }
    if (ruleNode is Call) {
      error(
          message: "Function '${ruleNode.name}' is undefined",
          index: ruleNode.index,
          filename: ruleNode.currentFileInfo?.filename);
    }
    if ((ruleNode.type != null) && !ruleNode.allowRoot) {
      error(
          message:
              '${ruleNode.type} node returned by a function is not valid here',
          index: ruleNode.index,
          filename: ruleNode.currentFileInfo?.filename);
    }
  }

//3.0.0 20160714
// checkValidNodes: function(rules, isRoot) {
//     if (!rules) {
//         return;
//     }
//
//     for (var i = 0; i < rules.length; i++) {
//         var ruleNode = rules[i];
//         if (isRoot && ruleNode instanceof tree.Declaration && !ruleNode.variable) {
//             throw { message: "Properties must be inside selector blocks. They cannot be in the root",
//                 index: ruleNode.getIndex(), filename: ruleNode.fileInfo() && ruleNode.fileInfo().filename};
//         }
//         if (ruleNode instanceof tree.Call) {
//             throw { message: "Function '" + ruleNode.name + "' is undefined",
//                 index: ruleNode.getIndex(), filename: ruleNode.fileInfo() && ruleNode.fileInfo().filename};
//         }
//         if (ruleNode.type && !ruleNode.allowRoot) {
//             throw { message: ruleNode.type + " node returned by a function is not valid here",
//                 index: ruleNode.getIndex(), filename: ruleNode.fileInfo() && ruleNode.fileInfo().filename};
//         }
//     }
// },
}