transform method
Given a mixin's defined arguments return a cloned mixin definition that has replaced all defined arguments with user's supplied VarUsages.
Implementation
MixinDefinition transform(List<List<Expression>> callArgs) {
// TODO(terry): Handle default arguments and varArgs.
// Transform mixin with callArgs.
for (var index = 0; index < _definedArgs!.length; index++) {
var definedArg = _definedArgs![index];
VarDefinition? varDef;
if (definedArg is VarDefinition) {
varDef = definedArg;
} else if (definedArg is VarDefinitionDirective) {
var varDirective = definedArg;
varDef = varDirective.def;
}
var callArg = callArgs[index];
// Is callArg a var definition with multi-args (expressions > 1).
var defArgs = _varDefsAsCallArgs(callArg);
if (defArgs.isNotEmpty) {
// Replace call args with the var def parameters.
callArgs.insertAll(index, defArgs);
callArgs.removeAt(index + defArgs.length);
callArg = callArgs[index];
}
var expressions = varUsages[varDef!.definedName];
expressions!.forEach((k, v) {
for (var usagesIndex in v) {
k.expressions.replaceRange(usagesIndex, usagesIndex + 1, callArg);
}
});
}
// Clone the mixin
return mixinDef.clone();
}