// TODO: maybe introduce the new ForOfStatement node
        private UstStmts.ForeachStatement VisitForOfStatement(ForOfStatement forOfStatement)
        {
            UstTokens.IdToken name = null;
            var left = Visit(forOfStatement.Left);

            if (left is UstTokens.IdToken token)
            {
                name = token;
            }
            else if (left is UstStmts.ExpressionStatement exprStmt &&
                     exprStmt.Expression is UstExprs.VariableDeclarationExpression varDecl &&
                     varDecl.Variables.Count > 0 &&
                     varDecl.Variables[0].Left is UstTokens.IdToken idToken)
            {
                name = idToken;
            }
            var inExpression = VisitExpression(forOfStatement.Right);
            var body         = VisitStatement(forOfStatement.Body);

            return(new UstStmts.ForeachStatement(null, name, inExpression, body, GetTextSpan(forOfStatement)));
        }
Example #2
0
        private Collections.List <ParameterDeclaration> VisitParameters(Esprima.Ast.List <INode> parameters)
        {
            var result = new Collections.List <ParameterDeclaration>(parameters.Count);

            foreach (INode param in parameters)
            {
                UstTokens.IdToken name;
                if (param is Identifier identifier)
                {
                    name = VisitIdentifier(identifier);
                }
                else
                {
                    // TODO: extend parameter declaration
                    name = new UstTokens.IdToken("", GetTextSpan(param));
                }
                result.Add(new ParameterDeclaration(null, null, name, name.TextSpan));
            }

            return(result);
        }