public override string ToCode(ToCodeFormat format) { StringBuilder sb = new StringBuilder(); sb.Append(m_field.ToString()); if (m_initializer != null) { if (m_ccSpecialCase) { sb.Append(UseCCOn ? "/*@cc_on=" : "/*@="); } else { if (Parser.Settings.OutputMode == OutputMode.MultipleLines && Parser.Settings.IndentSize > 0) { sb.Append(" = "); } else { sb.Append('='); } } bool useParen = false; // a comma operator is the only thing with a lesser precedence than an assignment BinaryOperator binOp = m_initializer as BinaryOperator; if (binOp != null && binOp.OperatorToken == JSToken.Comma) { useParen = true; } if (useParen) { sb.Append('('); } sb.Append(m_initializer.ToCode(m_ccSpecialCase ? ToCodeFormat.Preprocessor : ToCodeFormat.Normal)); if (useParen) { sb.Append(')'); } if (m_ccSpecialCase) { sb.Append("@*/"); } } return(sb.ToString()); }
public override string ToCode(ToCodeFormat format) { StringBuilder sb = new StringBuilder(); // passing a "T" format means nested try's don't actually nest -- they // just add the catch clauses to the end if (format != ToCodeFormat.NestedTry) { sb.Append("try"); if (TryBlock == null) { // empty body sb.Append("{}"); } else { sb.Append(TryBlock.ToCode(ToCodeFormat.NestedTry)); } } else { sb.Append(TryBlock.ToCode(ToCodeFormat.NestedTry)); } // handle the catch clause (if any) // catch should always have braces around it string catchString = ( CatchBlock == null ? string.Empty : CatchBlock.Count == 0 ? "{}" : CatchBlock.ToCode(ToCodeFormat.AlwaysBraces) ); if (catchString.Length > 0) { Parser.Settings.NewLine(sb); sb.Append("catch("); if (m_catchVariable != null) { sb.Append(m_catchVariable.ToString()); } else if (m_catchVarName != null) { sb.Append(m_catchVarName); } sb.Append(')'); sb.Append(catchString); } // handle the finally, if any // finally should always have braces around it string finallyString = ( FinallyBlock == null ? string.Empty : FinallyBlock.ToCode(ToCodeFormat.AlwaysBraces) ); if (finallyString.Length > 0) { Parser.Settings.NewLine(sb); sb.Append("finally"); sb.Append(finallyString); } return(sb.ToString()); }