Exemple #1
0
        protected internal static JintExpression Build(Engine engine, Expression expression)
        {
            switch (expression.Type)
            {
            case Nodes.AssignmentExpression: return(JintAssignmentExpression.Build(engine, (AssignmentExpression)expression));

            case Nodes.ArrayExpression: return(new JintArrayExpression(engine, (ArrayExpression)expression));

            case Nodes.ArrowFunctionExpression: return(new JintArrowFunctionExpression(engine, (IFunction)expression));

            case Nodes.BinaryExpression: return(JintBinaryExpression.Build(engine, (BinaryExpression)expression));

            case Nodes.CallExpression: return(new JintCallExpression(engine, (CallExpression)expression));

            case Nodes.ConditionalExpression: return(new JintConditionalExpression(engine, (ConditionalExpression)expression));

            case Nodes.FunctionExpression: return(new JintFunctionExpression(engine, (IFunction)expression));

            case Nodes.Identifier: return(new JintIdentifierExpression(engine, (Identifier)expression));

            case Nodes.Literal: return(JintLiteralExpression.Build(engine, (Literal)expression));

            case Nodes.LogicalExpression:
                switch (((BinaryExpression)expression).Operator)
                {
                case BinaryOperator.LogicalAnd: return(new JintLogicalAndExpression(engine, (BinaryExpression)expression));

                case BinaryOperator.LogicalOr: return(new JintLogicalOrExpression(engine, (BinaryExpression)expression));

                default: return(ExceptionHelper.ThrowArgumentOutOfRangeException <JintExpression>());
                }

            case Nodes.MemberExpression: return(new JintMemberExpression(engine, (MemberExpression)expression));

            case Nodes.NewExpression: return(new JintNewExpression(engine, (NewExpression)expression));

            case Nodes.ObjectExpression: return(new JintObjectExpression(engine, (ObjectExpression)expression));

            case Nodes.SequenceExpression: return(new JintSequenceExpression(engine, (SequenceExpression)expression));

            case Nodes.ThisExpression: return(new JintThisExpression(engine, (ThisExpression)expression));

            case Nodes.UpdateExpression: return(new JintUpdateExpression(engine, (UpdateExpression)expression));

            case Nodes.UnaryExpression: return(JintUnaryExpression.Build(engine, (UnaryExpression)expression));

            case Nodes.SpreadElement: return(new JintSpreadExpression(engine, (SpreadElement)expression));

            case Nodes.TemplateLiteral: return(new JintTemplateLiteralExpression(engine, (TemplateLiteral)expression));

            case Nodes.TaggedTemplateExpression: return(new JintTaggedTemplateExpression(engine, (TaggedTemplateExpression)expression));

            default:
                return(ExceptionHelper.ThrowArgumentOutOfRangeException <JintExpression>(nameof(expression), $"unsupported expression type '{expression.Type}'"));
            }
        }
 protected internal static JintExpression Build(Engine engine, Expression expression)
 {
     return(expression.Type switch
     {
         Nodes.AssignmentExpression => JintAssignmentExpression.Build(engine, (AssignmentExpression)expression),
         Nodes.ArrayExpression => new JintArrayExpression(engine, (ArrayExpression)expression),
         Nodes.ArrowFunctionExpression => new JintArrowFunctionExpression(engine, (IFunction)expression),
         Nodes.BinaryExpression => JintBinaryExpression.Build(engine, (BinaryExpression)expression),
         Nodes.CallExpression => new JintCallExpression(engine, (CallExpression)expression),
         Nodes.ConditionalExpression => new JintConditionalExpression(engine, (ConditionalExpression)expression),
         Nodes.FunctionExpression => new JintFunctionExpression(engine, (IFunction)expression),
         Nodes.Identifier => new JintIdentifierExpression(engine, (Identifier)expression),
         Nodes.Literal => JintLiteralExpression.Build(engine, (Literal)expression),
         Nodes.LogicalExpression => ((BinaryExpression)expression).Operator switch
         {
             BinaryOperator.LogicalAnd => new JintLogicalAndExpression(engine, (BinaryExpression)expression),
             BinaryOperator.LogicalOr => new JintLogicalOrExpression(engine, (BinaryExpression)expression),
             _ => ExceptionHelper.ThrowArgumentOutOfRangeException <JintExpression>()
         },