示例#1
0
        private UstExprs.UnaryOperatorExpression VisitUnaryExpression(UnaryExpression unaryExpression)
        {
            UstTokens.UnaryOperator op = UstTokens.UnaryOperator.None;

            switch (unaryExpression.Operator)
            {
            case UnaryOperator.Plus:
                op = UstTokens.UnaryOperator.Plus;
                break;

            case UnaryOperator.Minus:
                op = UstTokens.UnaryOperator.Minus;
                break;

            case UnaryOperator.BitwiseNot:
                op = UstTokens.UnaryOperator.BitwiseNot;
                break;

            case UnaryOperator.Delete:
                op = UstTokens.UnaryOperator.Delete;
                break;

            case UnaryOperator.Void:
                op = UstTokens.UnaryOperator.Void;
                break;

            case UnaryOperator.TypeOf:
                op = UstTokens.UnaryOperator.TypeOf;
                break;

            case UnaryOperator.Increment:
                op = unaryExpression.Prefix ? UstTokens.UnaryOperator.Increment : UstTokens.UnaryOperator.PostIncrement;
                break;

            case UnaryOperator.Decrement:
                op = unaryExpression.Prefix ? UstTokens.UnaryOperator.Decrement : UstTokens.UnaryOperator.PostDecrement;
                break;
            }

            // TODO: literal text span in Esprima library
            var opLiteral  = new UstLiterals.UnaryOperatorLiteral(op, default);
            var expression = VisitExpression(unaryExpression.Argument);

            return(new UstExprs.UnaryOperatorExpression(opLiteral, expression, GetTextSpan(unaryExpression)));
        }
示例#2
0
        private UstExprs.BinaryOperatorExpression VisitBinaryExpression(BinaryExpression binaryExpression)
        {
            UstTokens.BinaryOperator op = UstTokens.BinaryOperator.None;

            switch (binaryExpression.Operator)
            {
            case BinaryOperator.Plus:
                op = UstTokens.BinaryOperator.Plus;
                break;

            case BinaryOperator.Minus:
                op = UstTokens.BinaryOperator.Minus;
                break;

            case BinaryOperator.Times:
                op = UstTokens.BinaryOperator.Multiply;
                break;

            case BinaryOperator.Divide:
                op = UstTokens.BinaryOperator.Divide;
                break;

            case BinaryOperator.Modulo:
                op = UstTokens.BinaryOperator.Mod;
                break;

            case BinaryOperator.Equal:
                op = UstTokens.BinaryOperator.Equal;
                break;

            case BinaryOperator.NotEqual:
                op = UstTokens.BinaryOperator.NotEqual;
                break;

            case BinaryOperator.Greater:
                op = UstTokens.BinaryOperator.Greater;
                break;

            case BinaryOperator.GreaterOrEqual:
                op = UstTokens.BinaryOperator.GreaterOrEqual;
                break;

            case BinaryOperator.Less:
                op = UstTokens.BinaryOperator.Less;
                break;

            case BinaryOperator.LessOrEqual:
                op = UstTokens.BinaryOperator.LessOrEqual;
                break;

            case BinaryOperator.StrictlyEqual:
                op = UstTokens.BinaryOperator.StrictEqual;
                break;

            case BinaryOperator.StricltyNotEqual:
                op = UstTokens.BinaryOperator.StrictNotEqual;
                break;

            case BinaryOperator.BitwiseAnd:
                op = UstTokens.BinaryOperator.BitwiseAnd;
                break;

            case BinaryOperator.BitwiseOr:
                op = UstTokens.BinaryOperator.BitwiseOr;
                break;

            case BinaryOperator.BitwiseXOr:
                op = UstTokens.BinaryOperator.BitwiseXor;
                break;

            case BinaryOperator.LeftShift:
                op = UstTokens.BinaryOperator.ShiftLeft;
                break;

            case BinaryOperator.RightShift:
                op = UstTokens.BinaryOperator.ShiftRight;
                break;

            case BinaryOperator.UnsignedRightShift:
                op = UstTokens.BinaryOperator.ShiftRight;     // TODO: maybe add specific JavaScript operator?
                break;

            case BinaryOperator.In:
                op = UstTokens.BinaryOperator.In;
                break;

            case BinaryOperator.InstanceOf:
                op = UstTokens.BinaryOperator.InstanceOf;
                break;

            case BinaryOperator.LogicalAnd:
                op = UstTokens.BinaryOperator.LogicalAnd;
                break;

            case BinaryOperator.LogicalOr:
                op = UstTokens.BinaryOperator.LogicalOr;
                break;
            }

            // TODO: literal text span in Esprima library
            var opLiteral = new UstLiterals.BinaryOperatorLiteral(op, default);
            var left      = VisitExpression(binaryExpression.Left);
            var right     = VisitExpression(binaryExpression.Right);

            return(new UstExprs.BinaryOperatorExpression(left, opLiteral, right, GetTextSpan(binaryExpression)));
        }