eval method

  1. @override
Ruleset eval (Contexts context)
override

Implementation

@override
Ruleset eval(Contexts context) {
  final Node result =
      Variable(variable, index, currentFileInfo).eval(context);
  DetachedRuleset detachedRuleset;
  final LessExceptionError error = LessExceptionError(
      LessError(message: 'Could not evaluate variable call $variable'));

  if (result is! DetachedRuleset) {
    List<Node> rules;
    Ruleset rs;
    if (result is Ruleset) {
      rs = result;
    } else if (result is Nodeset) {
      rules = result.rules;
    } else if (result.value is List<Node>) {
      rules = result.value;
    } else {
      throw error;
    }
    detachedRuleset = DetachedRuleset(rs ?? Ruleset(null, rules));
  } else {
    detachedRuleset = result;
  }

  if (detachedRuleset.ruleset != null) {
    return detachedRuleset.callEval(context);
  }

  throw error;

// 3.8.1 20181129
//  VariableCall.prototype.eval = function (context) {
//      var rules, detachedRuleset = new Variable(this.variable, this.getIndex(), this.fileInfo()).eval(context),
//          error = new LessError({message: 'Could not evaluate variable call ' + this.variable});
//
//      if (!detachedRuleset.ruleset) {
//          if (detachedRuleset.rules) {
//              rules = detachedRuleset;
//          }
//          else if (Array.isArray(detachedRuleset)) {
//              rules = new Ruleset('', detachedRuleset);
//          }
//          else if (Array.isArray(detachedRuleset.value)) {
//              rules = new Ruleset('', detachedRuleset.value);
//          }
//          else {
//              throw error;
//          }
//          detachedRuleset = new DetachedRuleset(rules);
//      }
//      if (detachedRuleset.ruleset) {
//          return detachedRuleset.callEval(context);
//      }
//      throw error;
//  };
}