示例#1
0
        private UstExprs.Expression VisitTemplateLiteral(TemplateLiteral templateLiteral)
        {
            var elems = new Collections.List <INode>(templateLiteral.Expressions.Count + templateLiteral.Quasis.Count);

            elems.AddRange(templateLiteral.Expressions);
            elems.AddRange(templateLiteral.Quasis);

            elems.Sort(NodeLocationComparer.Instance);

            UstExprs.Expression result = null;

            for (int i = 0; i < elems.Count; i++)
            {
                UstExprs.Expression expr;

                if (elems[i] is Expression expression)
                {
                    expr = VisitExpression(expression);
                }
                else
                {
                    expr = VisitTemplateElement((TemplateElement)elems[i]);
                }

                var opLiteral = new UstLiterals.BinaryOperatorLiteral(UstTokens.BinaryOperator.Plus,
                                                                      TextSpan.FromBounds(expr.TextSpan.End, expr.TextSpan.End));

                result = result == null
                    ? expr
                    : new UstExprs.BinaryOperatorExpression(result, opLiteral, expr, result.TextSpan.Union(expr.TextSpan));
            }

            return(result);
        }
示例#2
0
        private UstExprs.ArrayCreationExpression VisitArrayExpression(ArrayExpression arrayExpression)
        {
            var inits = new Collections.List <UstExprs.Expression>(arrayExpression.Elements.Count);

            foreach (ArrayExpressionElement element in arrayExpression.Elements)
            {
                UstExprs.Expression expr = null;

                if (element is SpreadElement spreadElement)
                {
                    Logger.LogDebug("Spread elements are not supported for now"); // TODO
                }
                else if (element is Expression expression)
                {
                    expr = VisitExpression(expression);
                }
                else if (element != null)
                {
                    Logger.LogDebug($"{element.GetType().Name} are not supported for now"); // TODO
                }

                inits.Add(expr);
            }

            return(new UstExprs.ArrayCreationExpression(null, null, inits, GetTextSpan(arrayExpression)));
        }
        private UstStmts.ForStatement VisitForStatement(ForStatement forStatement)
        {
            var initList = new Collections.List <UstStmts.Statement>(1);

            if (forStatement.Init != null)
            {
                initList.Add(Visit(forStatement.Init).ToStatementIfRequired());
            }

            UstExprs.Expression condition = forStatement.Test != null
                ? VisitExpression(forStatement.Test)
                : null;

            var iteratorList = new Collections.List <UstExprs.Expression>(1);

            if (forStatement.Update != null)
            {
                iteratorList.Add(VisitExpression(forStatement.Update));
            }

            var body = VisitStatement(forStatement.Body);

            return(new UstStmts.ForStatement(initList, condition, iteratorList, body, GetTextSpan(forStatement)));
        }