예제 #1
0
        /// <summary>
        /// Appends the script to represent this object to the StringBuilder.
        /// </summary>
        /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
        /// <param name="options">The options to use when appending JavaScript</param>
        /// <param name="allowReservedWords"></param>
        protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            builder.Append("[");

            bool isFirst = true;

            foreach (Expression element in _elements.WithConvertedNulls())
            {
                if (isFirst)
                {
                    isFirst = false;
                }
                else
                {
                    builder.Append(",");
                }

                element.AppendScript(builder, options, allowReservedWords);
            }

            builder.Append("]");
        }
        /// <summary>
        /// Appends the script to represent this object to the StringBuilder.
        /// </summary>
        /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
        /// <param name="options">The options to use when appending JavaScript</param>
        /// <param name="allowReservedWords"></param>
        protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            if (!_expressions.Any())
            {
                throw new InvalidOperationException("Expressions cannot be empty.");
            }

            builder.Append("var ");

            bool first = true;

            foreach (Expression expression in _expressions)
            {
                if (!first)
                {
                    builder.Append(",");
                }
                else
                {
                    first = false;
                }

                expression.AppendScript(builder, options, allowReservedWords);
            }
        }
예제 #3
0
        /// <summary>
        /// Appends the script to represent this object to the StringBuilder.
        /// </summary>
        /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
        /// <param name="options">The options to use when appending JavaScript</param>
        /// <param name="allowReservedWords"></param>
        protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            builder.Append(_value ? TrueValue : FalseValue);
        }
예제 #4
0
        protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (builder == null)
            {
                throw new ArgumentException("builder");
            }

            builder.Append("this");
        }
예제 #5
0
        /// <summary>
        /// Appends the script to represent this object to the StringBuilder.
        /// </summary>
        /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
        /// <param name="options">The options to use when appending JavaScript</param>
        /// <param name="allowReservedWords"></param>
        protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            builder.Append(_value.ToString(CultureInfo.InvariantCulture));
        }
예제 #6
0
        /// <summary>
        /// Appends the script to represent this object to the StringBuilder.
        /// </summary>
        /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
        /// <param name="options">The options to use when appending JavaScript</param>
        /// <param name="allowReservedWords"></param>
        protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            _name.AppendScript(builder, options, allowReservedWords);
            builder.Append(":");
            _statement.AppendScript(builder, options, allowReservedWords);
            _statement.AppendRequiredTerminator(builder);
        }
        /// <summary>
        /// Appends the script to represent this object to the StringBuilder.
        /// </summary>
        /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
        /// <param name="options">The options to use when appending JavaScript</param>
        /// <param name="allowReservedWords"></param>
        protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            if (!allowReservedWords)
            {
                EnsureNoReservedWords();
            }

            builder.Append(_name);
        }
예제 #8
0
        /// <summary>
        /// Appends the script to represent this object to the StringBuilder.
        /// </summary>
        /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
        /// <param name="options">The options to use when appending JavaScript</param>
        /// <param name="allowReservedWords"></param>
        protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            builder.Append(JS.QuoteString(_value, options.PreferredQuoteChar));
        }
예제 #9
0
        /// <summary>
        /// Appends the script to represent this object to the StringBuilder.
        /// </summary>
        /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
        /// <param name="options">The options to use when appending JavaScript</param>
        /// <param name="allowReservedWords"></param>
        protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            if (_expression == null)
            {
                throw new InvalidOperationException();
            }

            builder.Append("throw ");
            _expression.AppendScript(builder, options, allowReservedWords);
        }
예제 #10
0
        /// <summary>
        /// Appends the script to represent this object to the StringBuilder.
        /// </summary>
        /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
        /// <param name="options">The options to use when appending JavaScript</param>
        /// <param name="allowReservedWords"></param>
        protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            builder.Append("break");

            if (_label != null)
            {
                builder.Append(" ");
                _label.AppendScript(builder, options, allowReservedWords);
            }
        }
예제 #11
0
        /// <summary>
        /// Appends the script to represent this object to the StringBuilder.
        /// </summary>
        /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
        /// <param name="options">The options to use when appending JavaScript</param>
        /// <param name="allowReservedWords"></param>
        protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            builder.Append("{");

            foreach (Statement statement in _statements.WithConvertedNulls())
            {
                statement.AppendScript(builder, options, allowReservedWords);
                statement.AppendRequiredTerminator(builder);
            }

            builder.Append("}");
        }
예제 #12
0
        /// <summary>
        /// Appends the script to represent this object to the StringBuilder.
        /// </summary>
        /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
        /// <param name="options">The options to use when appending JavaScript</param>
        /// <param name="allowReservedWords"></param>
        protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            if (_expression == null)
            {
                throw new InvalidOperationException();
            }

            builder.Append("switch(");
            _expression.AppendScript(builder, options, allowReservedWords);
            builder.Append("){");

            bool defaultPassed = false;

            foreach (CaseStatement @case in _cases)
            {
                if (@case == null)
                {
                    continue;
                }

                if (defaultPassed)
                {
                    throw new InvalidOperationException();
                }

                @case.AppendScript(builder, options);

                if (@case.Value == null)
                {
                    defaultPassed = true;
                }
            }

            builder.Append("}");
        }
예제 #13
0
        /// <summary>
        /// Appends the script to represent the comment to the StringBuilder.
        /// </summary>
        /// <param name="builder">The StringBuilder to which the comment is appended.</param>
        /// <param name="options">The options to use when appending JavaScript</param>
        /// <param name="allowReservedWords"></param>
        protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (AddExtraLineBreaks)
            {
                builder.AppendLine();
            }

            CommentStyle style = Style;

            if (style == CommentStyle.Auto)
            {
                style = Content.Contains("/*") || Content.Contains("*/") || Content.Contains("\r\n")
                    ? CommentStyle.OneLineComments
                    : CommentStyle.MultipleLineComments;
            }

            switch (style)
            {
                case CommentStyle.OneLineComments:
                    foreach (var line in Content.Split(new[] { "\r\n"}, StringSplitOptions.None))
                    {
                        builder.Append("// ");
                        builder.AppendLine(line);
                    }
                    break;
                case CommentStyle.MultipleLineComments:
                    builder.Append("/* ");
                    builder.Append(Content);
                    builder.Append(" */");
                    if (AddExtraLineBreaks)
                    {
                        builder.AppendLine();
                    }
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
예제 #14
0
        /// <summary>
        /// Appends the script to represent this object to the StringBuilder.
        /// </summary>
        /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
        /// <param name="options">The options to use when appending JavaScript</param>
        /// <param name="allowReservedWords"></param>
        protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            if (_condition == null)
            {
                throw new InvalidOperationException();
            }

            if (_statement == null)
            {
                throw new InvalidOperationException();
            }

            builder.Append("while(");
            _condition.AppendScript(builder, options, allowReservedWords);
            builder.Append(")");
            _statement.AppendScript(builder, options, allowReservedWords);
            _statement.AppendRequiredTerminator(builder);
        }
예제 #15
0
        /// <summary>
        /// Appends the script to represent this object to the StringBuilder.
        /// </summary>
        /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
        /// <param name="options">The options to use when appending JavaScript</param>
        /// <param name="allowReservedWords"></param>
        internal protected override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            bool noLeftSide  = false;
            bool noRightSide = false;

            switch (_operator)
            {
            case UnaryOperator.Number:
                builder.Append("+");
                break;

            case UnaryOperator.Negative:
                builder.Append("-");
                break;

            case UnaryOperator.BitwiseNot:
                builder.Append("~");
                break;

            case UnaryOperator.LogicalNot:
                builder.Append("!");
                break;

            case UnaryOperator.PreIncrement:
                builder.Append("++");
                break;

            case UnaryOperator.PreDecrement:
                builder.Append("--");
                break;

            case UnaryOperator.TypeOf:
                builder.Append("typeof ");
                break;

            case UnaryOperator.New:
                builder.Append("new ");
                break;

            case UnaryOperator.Delete:
                builder.Append("delete ");
                break;

            case UnaryOperator.Group:
                builder.Append("(");
                break;

            default:
                noLeftSide = true;
                break;
            }

            Expression operand = _operand ?? new NullExpression();

            operand.AppendScript(builder, options, allowReservedWords);

            switch (_operator)
            {
            case UnaryOperator.PostIncrement:
                builder.Append("++");
                break;

            case UnaryOperator.PostDecrement:
                builder.Append("--");
                break;

            case UnaryOperator.Group:
                builder.Append(")");
                break;

            default:
                noRightSide = true;
                break;
            }

            if (noLeftSide && noRightSide)
            {
                throw new InvalidOperationException("This operator yielded no result.");
            }
        }
예제 #16
0
        /// <summary>
        /// Converts the object to a string containing the JavaScript that it represents.
        /// </summary>
        /// <param name="includeTerminator">If true, a statement terminator is appended if required.</param>
        /// <param name="options">The options to use when generating JavaScript.</param>
        /// <param name="allowReservedWords">Indicate to the statement/expression that the use of reserved words is allowed.</param>
        /// <returns>A string containing the JavaScript that it represents.</returns>
        public string ToString(bool includeTerminator, ScriptOptions options, bool allowReservedWords)
        {
            StringBuilder builder = new StringBuilder();

            if (options.WrapInScriptBlock)
            {
                builder.Append("<script type=\"text/javascript\">");
            }

            AppendScript(builder, options, allowReservedWords);

            if (includeTerminator)
            {
                AppendRequiredTerminator(builder);
            }

            if (options.WrapInScriptBlock)
            {
                builder.Append("</script>");
            }

            return builder.ToString();
        }
예제 #17
0
 /// <summary>
 /// Appends the script to represent this object to the StringBuilder.
 /// </summary>
 /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
 /// <param name="options">The options to use when appending JavaScript</param>
 /// <param name="allowReservedWords">Indicate to the statement/expression that the use of reserved words is allowed.</param>
 protected internal abstract void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords);
예제 #18
0
 /// <summary>
 /// Appends the script to represent this object to the StringBuilder.
 /// </summary>
 /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
 /// <param name="options">The options to use when appending JavaScript</param>
 /// <param name="allowReservedWords"></param>
 protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
 {
 }
        private void InternalAppendScript(StringBuilder builder, ScriptOptions options)
        {
            if (_parent != null)
            {
                _parent.InternalAppendScript(builder, options);

                builder.Append(" else ");
            }

            if (Condition == null)
            {
                throw new InvalidOperationException("Condition cannot be null.");
            }

            builder.Append("if(");
            Condition.AppendScript(builder, options, false);
            builder.Append(")");

            Statement then = ThenStatement ?? new EmptyStatement();

            then.AppendScript(builder, options, false);
            then.AppendRequiredTerminator(builder);
        }
        /// <summary>
        /// Appends the script to represent this object to the StringBuilder.
        /// </summary>
        /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
        /// <param name="options">The options to use when appending JavaScript</param>
        /// <param name="allowReservedWords"></param>
        protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            Expression operand = _operand;

            if (operand.PrecedenceLevel.RequiresGrouping(PrecedenceLevel, Association.LeftToRight))
            {
                operand = JS.Group(_operand);
            }

            operand.AppendScript(builder, options, allowReservedWords);

            builder.Append("(");

            bool isFirst = true;

            foreach (Expression param in _arguments.WithConvertedNulls())
            {
                if (isFirst)
                {
                    isFirst = false;
                }
                else
                {
                    builder.Append(",");
                }

                param.AppendScript(builder, options, allowReservedWords);
            }

            builder.Append(")");
        }
        internal protected override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            Expression operandLeft  = _operandLeft ?? new NullExpression();
            Expression operandRight = _operandRight ?? new NullExpression();

            if (operandLeft.PrecedenceLevel.RequiresGrouping(PrecedenceLevel, Association.LeftToRight))
            {
                operandLeft = JS.Group(operandLeft);
            }

            if (operandRight.PrecedenceLevel.RequiresGrouping(PrecedenceLevel, Association.RightToLeft))
            {
                operandRight = JS.Group(operandRight);
            }

            operandLeft.AppendScript(builder, options, allowReservedWords);

            switch (_operator)
            {
            case BinaryOperator.Assign:
                builder.Append("=");
                break;

            case BinaryOperator.Add:
                builder.Append("+");
                break;

            case BinaryOperator.AddAndAssign:
                builder.Append("+=");
                break;

            case BinaryOperator.Subtract:
                builder.Append("-");
                break;

            case BinaryOperator.SubtractAndAssign:
                builder.Append("-=");
                break;

            case BinaryOperator.Multiply:
                builder.Append("*");
                break;

            case BinaryOperator.MultiplyAndAssign:
                builder.Append("*=");
                break;

            case BinaryOperator.Divide:
                builder.Append("/");
                break;

            case BinaryOperator.DivideAndAssign:
                builder.Append("/=");
                break;

            case BinaryOperator.Remain:
                builder.Append("%");
                break;

            case BinaryOperator.RemainAndAssign:
                builder.Append("%=");
                break;

            case BinaryOperator.BitwiseAnd:
                builder.Append("&");
                break;

            case BinaryOperator.BitwiseAndAndAssign:
                builder.Append("&=");
                break;

            case BinaryOperator.BitwiseOr:
                builder.Append("|");
                break;

            case BinaryOperator.BitwiseOrAndAssign:
                builder.Append("|=");
                break;

            case BinaryOperator.BitwiseXor:
                builder.Append("^");
                break;

            case BinaryOperator.BitwiseXorAndAssign:
                builder.Append("^=");
                break;

            case BinaryOperator.ShiftLeft:
                builder.Append("<<");
                break;

            case BinaryOperator.ShiftLeftAndAssign:
                builder.Append("<<=");
                break;

            case BinaryOperator.ShiftRight:
                builder.Append(">>");
                break;

            case BinaryOperator.ShiftRightAndAssign:
                builder.Append(">>=");
                break;

            case BinaryOperator.Equals:
                builder.Append("==");
                break;

            case BinaryOperator.Identical:
                builder.Append("===");
                break;

            case BinaryOperator.NotEqual:
                builder.Append("!=");
                break;

            case BinaryOperator.NotIdentical:
                builder.Append("!==");
                break;

            case BinaryOperator.GreaterThan:
                builder.Append(">");
                break;

            case BinaryOperator.GreaterThanOrEqualTo:
                builder.Append(">=");
                break;

            case BinaryOperator.LessThan:
                builder.Append("<");
                break;

            case BinaryOperator.LessThanOrEqualTo:
                builder.Append("<=");
                break;

            case BinaryOperator.LogicalAnd:
                builder.Append("&&");
                break;

            case BinaryOperator.LogicalOr:
                builder.Append("||");
                break;

            case BinaryOperator.InstanceOf:
                builder.Append(" instanceof ");
                break;

            case BinaryOperator.In:
                builder.Append(" in ");
                break;

            case BinaryOperator.MultipleEvaluation:
                builder.Append(",");
                break;

            default:
                throw new InvalidOperationException("What is this?");
            }

            operandRight.AppendScript(builder, options, allowReservedWords);
        }
        /// <summary>
        /// Appends the script to represent this object to the StringBuilder.
        /// </summary>
        /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
        /// <param name="options">The options to use when appending JavaScript</param>
        /// <param name="allowReservedWords"></param>
        protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            if (OperandLeft == null)
            {
                throw new InvalidOperationException();
            }

            if (OperandRight == null)
            {
                throw new InvalidOperationException();
            }

            _operandLeft.AppendScript(builder, options, allowReservedWords);
            builder.Append("[");
            _operandRight.AppendScript(builder, options, allowReservedWords);
            builder.Append("]");
        }
예제 #23
0
        /// <summary>
        /// Produces the Javascript and appends it to the StringBuilder passed in the builder argument.
        /// </summary>
        /// <param name="builder">The StringBuilder instance to append the Javascript to.</param>
        /// <param name="options">Specifies options to use while producing Javascript.</param>
        public void AppendScript(StringBuilder builder, ScriptOptions options)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            if (_value != null)
            {
                builder.Append("case ");
                _value.AppendScript(builder, options, false);
                builder.Append(":");
            }
            else
            {
                builder.Append("default:");
            }

            if (_statements != null)
            {
                foreach (Statement statement in _statements.WithConvertedNulls())
                {
                    statement.AppendScript(builder, options, false);
                    statement.AppendRequiredTerminator(builder);
                }
            }
        }
        /// <summary>
        /// Appends the script to represent this object to the StringBuilder.
        /// </summary>
        /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
        /// <param name="options">The options to use when appending JavaScript</param>
        /// <param name="allowReservedWords"></param>
        protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            if (_operandLeft == null)
            {
                throw new InvalidOperationException();
            }

            if (_operandRight == null)
            {
                throw new InvalidOperationException();
            }

            Expression operandLeft = _operandLeft;
            Expression operandRight = _operandRight;

            if (operandLeft.PrecedenceLevel.RequiresGrouping(PrecedenceLevel, Association.LeftToRight))
            {
                operandLeft = JS.Group(operandLeft);
            }

            operandLeft.AppendScript(builder, options, allowReservedWords);

            builder.Append(".");

            operandRight.AppendScript(builder, options, allowReservedWords);
        }
예제 #25
0
 /// <summary>
 /// Appends the script to represent this object to the StringBuilder.
 /// </summary>
 /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
 /// <param name="options">The options to use when appending JavaScript</param>
 /// <param name="allowReservedWords">Indicate to the statement/expression that the use of reserved words is allowed.</param>
 internal protected abstract void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords);
예제 #26
0
        /// <summary>
        /// Appends the script to represent this object to the StringBuilder.
        /// </summary>
        /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
        /// <param name="options">The options to use when appending JavaScript</param>
        /// <param name="allowReservedWords"></param>
        protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            builder.Append("function");

            if (_name != null)
            {
                builder.Append(" ");
                _name.AppendScript(builder, options, allowReservedWords);
            }

            builder.Append("(");

            bool isFirst = true;

            foreach (IdentifierExpression item in _parameters)
            {
                if (isFirst)
                {
                    isFirst = false;
                }
                else
                {
                    builder.Append(",");
                }

                item.AppendScript(builder, options, allowReservedWords);
            }

            builder.Append(")");

            (_body ?? new CompoundStatement()).AppendScript(builder, options, allowReservedWords);
        }
        /// <summary>
        /// Appends the script to represent this object to the StringBuilder.
        /// </summary>
        /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
        /// <param name="options">The options to use when appending JavaScript</param>
        /// <param name="allowReservedWords"></param>
        protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            if (Condition == null)
            {
                throw new InvalidOperationException("The Condition property cannot be null.");
            }

            if (Then == null)
            {
                throw new InvalidOperationException("The Then property cannot be null.");
            }

            if (Else == null)
            {
                throw new InvalidOperationException("The Else property cannot be null.");
            }

            // TODO: Check if we need to support Precedence.
            Condition.AppendScript(builder, options, allowReservedWords);
            builder.Append("?");
            Then.AppendScript(builder, options, allowReservedWords);
            builder.Append(":");
            Else.AppendScript(builder, options, allowReservedWords);
        }
        protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            Expression operandLeft = _operandLeft ?? new NullExpression();
            Expression operandRight = _operandRight ?? new NullExpression();

            if (operandLeft.PrecedenceLevel.RequiresGrouping(PrecedenceLevel, Association.LeftToRight))
            {
                operandLeft = JS.Group(operandLeft);
            }

            if (operandRight.PrecedenceLevel.RequiresGrouping(PrecedenceLevel, Association.RightToLeft))
            {
                operandRight = JS.Group(operandRight);
            }

            operandLeft.AppendScript(builder, options, allowReservedWords);

            switch (_operator)
            {
                case BinaryOperator.Assign:
                    builder.Append("=");
                    break;
                case BinaryOperator.Add:
                    builder.Append("+");
                    break;
                case BinaryOperator.AddAndAssign:
                    builder.Append("+=");
                    break;
                case BinaryOperator.Subtract:
                    builder.Append("-");
                    break;
                case BinaryOperator.SubtractAndAssign:
                    builder.Append("-=");
                    break;
                case BinaryOperator.Multiply:
                    builder.Append("*");
                    break;
                case BinaryOperator.MultiplyAndAssign:
                    builder.Append("*=");
                    break;
                case BinaryOperator.Divide:
                    builder.Append("/");
                    break;
                case BinaryOperator.DivideAndAssign:
                    builder.Append("/=");
                    break;
                case BinaryOperator.Remain:
                    builder.Append("%");
                    break;
                case BinaryOperator.RemainAndAssign:
                    builder.Append("%=");
                    break;
                case BinaryOperator.BitwiseAnd:
                    builder.Append("&");
                    break;
                case BinaryOperator.BitwiseAndAndAssign:
                    builder.Append("&=");
                    break;
                case BinaryOperator.BitwiseOr:
                    builder.Append("|");
                    break;
                case BinaryOperator.BitwiseOrAndAssign:
                    builder.Append("|=");
                    break;
                case BinaryOperator.BitwiseXor:
                    builder.Append("^");
                    break;
                case BinaryOperator.BitwiseXorAndAssign:
                    builder.Append("^=");
                    break;
                case BinaryOperator.ShiftLeft:
                    builder.Append("<<");
                    break;
                case BinaryOperator.ShiftLeftAndAssign:
                    builder.Append("<<=");
                    break;
                case BinaryOperator.ShiftRight:
                    builder.Append(">>");
                    break;
                case BinaryOperator.ShiftRightAndAssign:
                    builder.Append(">>=");
                    break;
                case BinaryOperator.Equals:
                    builder.Append("==");
                    break;
                case BinaryOperator.Identical:
                    builder.Append("===");
                    break;
                case BinaryOperator.NotEqual:
                    builder.Append("!=");
                    break;
                case BinaryOperator.NotIdentical:
                    builder.Append("!==");
                    break;
                case BinaryOperator.GreaterThan:
                    builder.Append(">");
                    break;
                case BinaryOperator.GreaterThanOrEqualTo:
                    builder.Append(">=");
                    break;
                case BinaryOperator.LessThan:
                    builder.Append("<");
                    break;
                case BinaryOperator.LessThanOrEqualTo:
                    builder.Append("<=");
                    break;
                case BinaryOperator.LogicalAnd:
                    builder.Append("&&");
                    break;
                case BinaryOperator.LogicalOr:
                    builder.Append("||");
                    break;
                case BinaryOperator.InstanceOf:
                    builder.Append(" instanceof ");
                    break;
                case BinaryOperator.In:
                    builder.Append(" in ");
                    break;
                case BinaryOperator.MultipleEvaluation:
                    builder.Append(",");
                    break;
                default:
                    throw new InvalidOperationException("What is this?");
            }

            operandRight.AppendScript(builder, options, allowReservedWords);
        }
 /// <summary>
 /// Appends the script to represent this object to the StringBuilder.
 /// </summary>
 /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
 /// <param name="options">The options to use when appending JavaScript</param>
 /// <param name="allowReservedWords"></param>
 internal protected override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
 {
 }
        /// <summary>
        /// Appends the script to represent this object to the StringBuilder.
        /// </summary>
        /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
        /// <param name="options">The options to use when appending JavaScript</param>
        /// <param name="allowReservedWords"></param>
        protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            if (_tryBlock == null)
            {
                throw new InvalidOperationException();
            }

            builder.Append("try");
            _tryBlock.AppendScript(builder, options, allowReservedWords);

            if (CatchBlock != null)
            {
                if (CatchVariable == null)
                {
                    throw new InvalidOperationException();
                }

                builder.Append("catch(");
                CatchVariable.AppendScript(builder, options, allowReservedWords);
                builder.Append(")");
                CatchBlock.AppendScript(builder, options, allowReservedWords);
            }

            if (FinallyBlock != null)
            {
                builder.Append("finally");
                FinallyBlock.AppendScript(builder, options, allowReservedWords);
            }
        }
        /// <summary>
        /// Appends the script to represent this object to the StringBuilder.
        /// </summary>
        /// <param name="builder">The StringBuilder to which the Javascript is appended.</param>
        /// <param name="options">The options to use when appending JavaScript</param>
        /// <param name="allowReservedWords"></param>
        protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            bool noLeftSide = false;
            bool noRightSide = false;

            switch (_operator)
            {
                case UnaryOperator.Number:
                    builder.Append("+");
                    break;

                case UnaryOperator.Negative:
                    builder.Append("-");
                    break;

                case UnaryOperator.BitwiseNot:
                    builder.Append("~");
                    break;

                case UnaryOperator.LogicalNot:
                    builder.Append("!");
                    break;

                case UnaryOperator.PreIncrement:
                    builder.Append("++");
                    break;

                case UnaryOperator.PreDecrement:
                    builder.Append("--");
                    break;

                case UnaryOperator.TypeOf:
                    builder.Append("typeof ");
                    break;

                case UnaryOperator.New:
                    builder.Append("new ");
                    break;

                case UnaryOperator.Delete:
                    builder.Append("delete ");
                    break;

                case UnaryOperator.Group:
                    builder.Append("(");
                    break;

                default:
                    noLeftSide = true;
                    break;

            }

            Expression operand = _operand ?? new NullExpression();
            operand.AppendScript(builder, options, allowReservedWords);

            switch (_operator)
            {
                case UnaryOperator.PostIncrement:
                    builder.Append("++");
                    break;

                case UnaryOperator.PostDecrement:
                    builder.Append("--");
                    break;

                case UnaryOperator.Group:
                    builder.Append(")");
                    break;

                default:
                    noRightSide = true;
                    break;
            }

            if (noLeftSide && noRightSide)
            {
                throw new InvalidOperationException("This operator yielded no result.");
            }
        }