Beispiel #1
0
        public override string ToCode(ToCodeFormat format)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(JSScanner.GetOperatorString(OperatorToken));
            if (Operand != null)
            {
                string operandString = Operand.ToCode(format);
                if (NeedsParentheses)
                {
                    sb.Append('(');
                    sb.Append(operandString);
                    sb.Append(')');
                }
                else
                {
                    if (operandString.Length > 0)
                    {
                        // make sure that - - or + + doesn't get crunched to -- or ++
                        // (which would totally change the meaning of the code)
                        if ((OperatorToken == JSToken.Minus && operandString[0] == '-') ||
                            (OperatorToken == JSToken.Plus && operandString[0] == '+'))
                        {
                            sb.Append(' ');
                        }
                    }
                    sb.Append(operandString);
                }
            }
            return(sb.ToString());
        }