visitIncludeMixinAtDeclaration method

  1. @override
void visitIncludeMixinAtDeclaration(
  1. IncludeMixinAtDeclaration node
)
override

Implementation

@override
void visitIncludeMixinAtDeclaration(IncludeMixinAtDeclaration node) {
  if (map.containsKey(node.include.name)) {
    var mixinDef = map[node.include.name];

    // Fix up any mixin that is really a Declaration but has includes.
    if (mixinDef is MixinRulesetDirective) {
      if (!_allIncludes(mixinDef.rulesets) && currDeclGroup != null) {
        var index = _findInclude(currDeclGroup!.declarations, node);
        if (index != -1) {
          currDeclGroup!.declarations
              .replaceRange(index, index + 1, [NoOp()]);
        }
        _messages.warning(
            'Using top-level mixin ${node.include.name} as a declaration',
            node.span);
      } else {
        // We're a list of @include(s) inside of a mixin ruleset - convert
        // to a list of IncludeMixinAtDeclaration(s).
        var origRulesets = mixinDef.rulesets;
        var rulesets = <Declaration>[];
        if (origRulesets.every((ruleset) => ruleset is IncludeDirective)) {
          for (var ruleset in origRulesets) {
            rulesets.add(IncludeMixinAtDeclaration(
                ruleset as IncludeDirective, ruleset.span));
          }
          _IncludeReplacer.replace(_styleSheet!, node, rulesets);
        }
      }
    }

    if (mixinDef!.definedArgs.isNotEmpty && node.include.args.isNotEmpty) {
      var callMixin = _createCallDeclMixin(mixinDef);
      mixinDef = callMixin.transform(node.include.args);
    }

    if (mixinDef is MixinDeclarationDirective) {
      _IncludeReplacer.replace(
          _styleSheet!, node, mixinDef.declarations.declarations);
    }
  } else {
    _messages.warning('Undefined mixin ${node.include.name}', node.span);
  }

  super.visitIncludeMixinAtDeclaration(node);
}