detachedRuleset method

Node detachedRuleset ()

Search for

{ rules }

returns Node = MixinDefinition | DetachedRuleset

Implementation

Node detachedRuleset() {
  List<MixinArgs> params;
  bool variadic;

  parserInput.save();
  if (parserInput.$re(_detachedRulesetRegExp) != null) {
    // DR args currently only implemented for each() function, and not
    // yet settable as `@dr: #(@arg) {}`
    // This should be done when DRs are merged with mixins.
    // See: https://github.com/less/less-meta/issues/16
    final MixinReturner argInfo = mixin.args(isCall: false);
    params = argInfo.args;
    variadic = argInfo.variadic;
    if (parserInput.$char(')') == null) {
      parserInput.restore();
      return null;
    }
  }

  final Ruleset blockRuleset = this.blockRuleset();
  if (blockRuleset != null) {
    parserInput.forget();
    if (params != null) {
      return MixinDefinition(null, params, blockRuleset.rules, null,
          variadic: variadic);
    }
    return DetachedRuleset(blockRuleset);
  }
  parserInput.restore();
  return null;

// 3.5.3 20180708
//  detachedRuleset: function() {
//      var argInfo, params, variadic;
//
//      parserInput.save();
//      if (parserInput.$re(/^[.#]\(/)) {
//          /**
//           * DR args currently only implemented for each() function, and not
//           * yet settable as `@dr: #(@arg) {}`
//           * This should be done when DRs are merged with mixins.
//           * See: https://github.com/less/less-meta/issues/16
//           */
//          argInfo = this.mixin.args(false);
//          params = argInfo.args;
//          variadic = argInfo.variadic;
//          if (!parserInput.$char(')')) {
//              parserInput.restore();
//              return;
//          }
//      }
//      var blockRuleset = this.blockRuleset();
//      if (blockRuleset) {
//          parserInput.forget();
//          if (params) {
//              return new tree.mixin.Definition(null, params, blockRuleset, null, variadic);
//          }
//          return new tree.DetachedRuleset(blockRuleset);
//      }
//      parserInput.restore();
//  },
}