fromTypeLink function
Creates an AST from code generation from typeLink
.
Implementation
o.OutputType fromTypeLink(TypeLink? typeLink, LibraryReader library) {
if (typeLink == null || typeLink.isDynamic || typeLink.isPrivate) {
return o.DYNAMIC_TYPE;
}
var typeArguments = <o.OutputType>[];
for (var i = 0; i < typeLink.generics.length; i++) {
typeArguments.add(fromTypeLink(typeLink.generics[i], library));
}
// When `typeLink` represents a type parameter, it doesn't require an import.
final importUrl = typeLink.import != null
? library.pathToUrl(typeLink.import).toString()
: null;
var outputType = o.ExternalType(
CompileIdentifierMetadata(
name: typeLink.symbol,
moduleUrl: importUrl,
typeArguments: typeArguments,
),
typeArguments,
);
if (typeLink.isNullable) {
outputType = outputType.asNullable();
}
return outputType;
}