Example #1
0
		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();
		}
Example #2
0
			public bool Visit(AstNode node)
			{
				int type = node.GetType();
				if (type == Token.SCRIPT)
				{
					return true;
				}
				if (node.GetParent() == null)
				{
					throw new InvalidOperationException("No parent for node: " + node + "\n" + node.ToSource(0));
				}
				return true;
			}