createDiTokenExpression function

Expression createDiTokenExpression(
  1. CompileTokenMetadata token
)

Implementation

o.Expression createDiTokenExpression(CompileTokenMetadata token) {
  if (token.identifierIsInstance) {
    return o
        .importExpr(token.identifier!)
        .instantiate(
          // If there is also a value, assume it is the first argument.
          //
          // i.e. const OpaqueToken('literalValue')
          token.value != null
              ? [o.literal(token.value)]
              : const <o.Expression>[],
          type: o.importType(token.identifier, [], [
            o.TypeModifier.constModifier,
          ]),
          // Add any generic types attached to the type.
          //
          // Only a value of `null` precisely means "no generic types", not [].
          genericTypes: token.identifier!.typeArguments.isNotEmpty
              ? token.identifier!.typeArguments
              : null,
        );
  } else if (token.value != null) {
    return o.literal(token.value);
  } else {
    return o.importExpr(token.identifier!);
  }
}