emit method

  1. @override
String emit({
  1. int indent = 0,
})
override

Implementation

@override
String emit({int indent = 0}) {
  final String tabs = "\t" * indent;

  final String paramText = parameters.map((p) => p.emit()).join(", ");

  final String retStr = returnType != null ? ": $returnType" : "";

  final String prefix = isLocal ? "local " : "";

  String output = "$tabs${prefix}function $name($paramText)$retStr\n\n";

  final bool hasTryCatch = body.any((n) => n is LuauTryCatch);
  final bool endsWithReturn =
      body.isNotEmpty && body.last is LuauReturnStatement;
  for (var node in body) {
    output += node.emit(indent: indent + 1);
  }
  if (hasTryCatch && !endsWithReturn) {
    output += "$tabs\treturn\n";
  }
  output += "${tabs}end\n\n";

  return output;
}