private LocalFunctionStatementSyntax CreateFunctionStatement(FunctionDeclaration node)
        {
            LocalFunctionStatementSyntax funStatement = SyntaxFactory.LocalFunctionStatement(node.Type.ToCsNode <TypeSyntax>(), node.Name.Text);

            funStatement = funStatement.AddModifiers(node.Modifiers.ToCsNodes <SyntaxToken>());
            funStatement = funStatement.AddParameterListParameters(node.Parameters.ToCsNodes <ParameterSyntax>());

            if (node.JsDoc.Count > 0)
            {
                funStatement = funStatement.WithLeadingTrivia(SyntaxFactory.Trivia(node.JsDoc[0].ToCsNode <DocumentationCommentTriviaSyntax>()));
            }
            if (node.TypeParameters.Count > 0)
            {
                funStatement = funStatement.AddTypeParameterListParameters(node.TypeParameters.ToCsNodes <TypeParameterSyntax>());
            }

            return(funStatement.WithBody(node.Body.ToCsNode <BlockSyntax>()));
        }
Ejemplo n.º 2
0
        private LocalFunctionStatementSyntax CreateLocalFunction(IAnonymousFunctionOperation operation,
                                                                 IVariableDeclaratorOperation variableDeclaratorOperation,
                                                                 ParameterListSyntax param, BlockSyntax block,
                                                                 ArrowExpressionClauseSyntax arrow)
        {
            string symbolName = variableDeclaratorOperation.Symbol.Name;
            LocalFunctionStatementSyntax localFunc = SyntaxFactory.LocalFunctionStatement(
                SyntaxFactory.TokenList(),
                CommonConversions.GetTypeSyntax(operation.Symbol.ReturnType),
                SyntaxFactory.Identifier(symbolName), null, param,
                SyntaxFactory.List <TypeParameterConstraintClauseSyntax>(), block, arrow,
                SyntaxFactory.Token(SyntaxKind.SemicolonToken));


            if (operation.Symbol.IsAsync)
            {
                localFunc = localFunc.AddModifiers(SyntaxFactory.Token(SyntaxKind.AsyncKeyword));
            }

            return(localFunc);
        }