< Summary

Information
Class: Elsa.Expressions.JavaScript.TypeDefinitions.Services.TypeDefinitionDocumentRenderer
Assembly: Elsa.Expressions.JavaScript
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions.JavaScript/TypeDefinitions/Services/TypeDefinitionDocumentRenderer.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 29
Coverable lines: 29
Total lines: 65
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 22
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Render(...)0%4260%
Render(...)0%620%
RenderMethod(...)0%620%
Render(...)0%7280%
Render(...)0%620%
RenderEnumMember(...)100%210%
Render(...)100%210%
RenderParameter(...)0%620%
RenderParameters(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions.JavaScript/TypeDefinitions/Services/TypeDefinitionDocumentRenderer.cs

#LineLine coverage
 1using System.Text;
 2using Elsa.Expressions.JavaScript.TypeDefinitions.Contracts;
 3using Elsa.Expressions.JavaScript.TypeDefinitions.Models;
 4
 5namespace Elsa.Expressions.JavaScript.TypeDefinitions.Services;
 6
 7/// <inheritdoc />
 8public class TypeDefinitionDocumentRenderer : ITypeDefinitionDocumentRenderer
 9{
 10    /// <inheritdoc />
 11    public string Render(TypeDefinitionsDocument document)
 12    {
 013        var stringBuilder = new StringBuilder();
 14
 015        foreach (var functionDefinition in document.Functions)
 016            Render(functionDefinition, stringBuilder);
 17
 018        foreach (var typeDefinition in document.Types)
 019            Render(typeDefinition, stringBuilder);
 20
 021        foreach (var variableDefinition in document.Variables)
 022            Render(variableDefinition, stringBuilder);
 23
 024        return stringBuilder.ToString();
 25    }
 26
 27    private void Render(FunctionDefinition functionDefinition, StringBuilder output)
 28    {
 029        var returnType = functionDefinition.ReturnType != null ? $": {functionDefinition.ReturnType}" : "";
 030        output.AppendLine($"declare function {functionDefinition.Name}({RenderParameters(functionDefinition.Parameters)}
 031    }
 32
 33    private void RenderMethod(FunctionDefinition functionDefinition, StringBuilder output)
 34    {
 035        var returnType = functionDefinition.ReturnType != null ? $" => {functionDefinition.ReturnType}" : "";
 036        output.AppendLine($"{functionDefinition.Name}: ({RenderParameters(functionDefinition.Parameters)}){returnType};"
 037    }
 38
 39    private void Render(TypeDefinition typeDefinition, StringBuilder output)
 40    {
 041        output.AppendLine($"declare {typeDefinition.DeclarationKeyword} {typeDefinition.Name} {{");
 42
 043        if (typeDefinition.DeclarationKeyword == "enum")
 44        {
 045            foreach (var property in typeDefinition.Properties)
 046                RenderEnumMember(property, output);
 47        }
 48        else
 49        {
 050            foreach (var property in typeDefinition.Properties)
 051                Render(property, output);
 52        }
 53
 054        foreach (var method in typeDefinition.Methods)
 055            RenderMethod(method, output);
 56
 057        output.AppendLine("}");
 058    }
 59
 060    private void Render(PropertyDefinition property, StringBuilder output) => output.AppendLine($"{property.Name}{(prope
 061    private void RenderEnumMember(PropertyDefinition property, StringBuilder output) => output.AppendLine($"{property.Na
 062    private void Render(VariableDefinition variable, StringBuilder output) => output.AppendLine($"declare var {variable.
 063    string RenderParameter(ParameterDefinition parameter) => $"{parameter.Name}{(parameter.IsOptional ? "?" : "")}: {par
 064    string RenderParameters(IEnumerable<ParameterDefinition> parameters) => string.Join(", ", parameters.Select(RenderPa
 65}