debugOutputAstAsDart function

String debugOutputAstAsDart(
  1. dynamic ast, {
  2. bool emitNullSafeSyntax = false,
})

Implementation

String debugOutputAstAsDart(
  dynamic /* o . Statement | o . Expression | o . Type | List < dynamic > */ ast, {
  bool emitNullSafeSyntax = false,
}) {
  var converter = _DartEmitterVisitor(
    _debugModuleUrl,
    emitNullSafeSyntax: emitNullSafeSyntax,
  );
  var ctx = EmitterVisitorContext.createRoot();
  late List<Object> asts;
  if (ast is! List<Object>) {
    asts = [ast as Object];
  }
  for (var ast in asts) {
    if (ast is o.Statement) {
      ast.visitStatement(converter, ctx);
    } else if (ast is o.Expression) {
      ast.visitExpression(converter, ctx);
    } else if (ast is o.OutputType) {
      ast.visitType(converter, ctx);
    } else {
      throw StateError("Don't know how to print debug info for $ast");
    }
  }
  return ctx.toSource();
}