public override string ToSource(int depth)
{
StringBuilder sb = new StringBuilder();
sb.Append(MakeIndent(depth));
sb.Append("function");
if (functionName != null)
{
sb.Append(" ");
sb.Append(functionName.ToSource(0));
}
if (@params == null)
{
sb.Append("() ");
}
else
{
sb.Append("(");
PrintList(@params, sb);
sb.Append(") ");
}
if (isExpressionClosure)
{
AstNode body = GetBody();
if (body.GetLastChild() is ReturnStatement)
{
// omit "return" keyword, just print the expression
body = ((ReturnStatement)body.GetLastChild()).GetReturnValue();
sb.Append(body.ToSource(0));
if (functionType == FUNCTION_STATEMENT)
{
sb.Append(";");
}
}
else
{
// should never happen
sb.Append(" ");
sb.Append(body.ToSource(0));
}
}
else
{
sb.Append(GetBody().ToSource(depth).Trim());
}
if (functionType == FUNCTION_STATEMENT)
{
sb.Append("\n");
}
return sb.ToString();
}