コード例 #1
0
 public void ExpressionNodeTypeIsNotParenthesizedInsideConditional()
 {
     AssertCorrect(JsExpression.Conditional(
                       JsExpression.Unary(ExpressionNodeType.Negate, JsExpression.Number(1)),
                       JsExpression.Unary(ExpressionNodeType.Negate, JsExpression.Number(2)),
                       JsExpression.Unary(ExpressionNodeType.Negate, JsExpression.Number(3))
                       ),
                   "(-1 ? -2 : -3)");
 }
コード例 #2
0
 public void ExpressionNodeTypeIsNotParenthesizedWhenUsedAsBinaryArgument()
 {
     AssertCorrect(JsExpression.Binary(ExpressionNodeType.Multiply,
                                       JsExpression.Unary(ExpressionNodeType.Negate,
                                                          JsExpression.Identifier("X")
                                                          ),
                                       JsExpression.Number(1)
                                       ),
                   "-X * 1");
 }
コード例 #3
0
 public void IncrementIsParenthesizedWhenBeingUsedAsInvocationTarget()
 {
     AssertCorrect(JsExpression.Invocation(
                       JsExpression.Unary(ExpressionNodeType.PostfixPlusPlus,
                                          JsExpression.Identifier("X")
                                          ),
                       new[] { JsExpression.Number(1) }
                       ),
                   "(X++)(1)");
 }
コード例 #4
0
 public void IncrementIsParenthesizedWhenUsedAsInvocationMethod()
 {
     AssertCorrect(JsExpression.Invocation(
                       JsExpression.Unary(ExpressionNodeType.PostfixMinusMinus,
                                          JsExpression.Identifier("x")
                                          ),
                       new JsExpression[0]
                       ),
                   "(x--)()");
 }
コード例 #5
0
        public void UnaryOperatorsAreCorrectlyOutput()
        {
            var operators = new Dictionary <ExpressionNodeType, string> {
                { ExpressionNodeType.TypeOf, "typeof({0})" },
                { ExpressionNodeType.LogicalNot, "!{0}" },
                { ExpressionNodeType.Negate, "-{0}" },
                { ExpressionNodeType.Positive, "+{0}" },
                { ExpressionNodeType.PrefixPlusPlus, "++{0}" },
                { ExpressionNodeType.PrefixMinusMinus, "--{0}" },
                { ExpressionNodeType.PostfixPlusPlus, "{0}++" },
                { ExpressionNodeType.PostfixMinusMinus, "{0}--" },
                { ExpressionNodeType.Delete, "delete {0}" },
                { ExpressionNodeType.Void, "void({0})" },
                { ExpressionNodeType.BitwiseNot, "~{0}" },
            };

            for (var oper = ExpressionNodeType.UnaryFirst; oper <= ExpressionNodeType.UnaryLast; oper++)
            {
                Assert.That(operators.ContainsKey(oper), string.Format("Unexpected operator {0}", oper));
                var expr = JsExpression.Unary(oper, JsExpression.Identifier("a"));
                AssertCorrect(expr, string.Format(operators[oper], "a"));
            }
        }
コード例 #6
0
 public void ASpaceIsInsertedBetweenBinaryAndUnaryPlusAndMinusToAvoidParseAsIncrementOrDecrement()
 {
     AssertCorrect(JsExpression.Binary(ExpressionNodeType.Add, JsExpression.Identifier("a"), JsExpression.Unary(ExpressionNodeType.Positive, JsExpression.Identifier("b"))), "a+ +b");
     AssertCorrect(JsExpression.Binary(ExpressionNodeType.Subtract, JsExpression.Identifier("a"), JsExpression.Unary(ExpressionNodeType.Negate, JsExpression.Identifier("b"))), "a- -b");
     AssertCorrect(JsExpression.Binary(ExpressionNodeType.Subtract, JsExpression.Identifier("a"), JsExpression.Unary(ExpressionNodeType.Positive, JsExpression.Identifier("b"))), "a-+b");
     AssertCorrect(JsExpression.Binary(ExpressionNodeType.Add, JsExpression.Identifier("a"), JsExpression.Unary(ExpressionNodeType.Negate, JsExpression.Identifier("b"))), "a+-b");
 }
コード例 #7
0
        public virtual JsExpression VisitUnaryExpression(JsUnaryExpression expression, TData data)
        {
            var operand = VisitExpression(expression.Operand, data);

            return(ReferenceEquals(operand, expression.Operand) ? expression : JsExpression.Unary(expression.NodeType, operand));
        }