Skip to content

Commit 1e08568

Browse files
authored
Merge pull request #39 from canhorn/feature/update_readmes
Updated Readme Files
2 parents 3eeb319 + 1231b44 commit 1e08568

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ The interop project can be found in the [canhorn/EventHorizon.Blazor.Interop](ht
2828
* [TypeScript](https://www.typescriptlang.org/)
2929
* [NodeJS](https://nodejs.org/)
3030

31+
## TypeScript Parser
32+
33+
The generation relies heavily on the TypeScript Abstract Syntax Tree and so the code includes ways to parse the source files into a AST representation for easier generation.
34+
35+
The code has two supported parser types, .NET and NodeJS, to do realtime parsing of code. Using a .NET library it's able to do very quick parsing, but since it has not been maintained it can not handle complex or modern TypeScript syntax.
36+
But with the NodeJS TypeScript parser it can handle modern more complex TypeScript syntax, but with the trade off of in speed.
37+
38+
> Having NodeJS installed is required to use the NodeJS TypeScript parser. (This is required when using the parser with the Tool)
39+
3140
## Supported API's Generated
3241

3342
Below is a list of API that will be generated.

Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/Identifiers/InterfaceResponseTypeIdentifierTests.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ namespace EventHorizon.Blazor.TypeScript.Interop.Generator.Tests.Identifiers
22
{
33
using System.Collections.Generic;
44
using System.IO;
5+
using System.Threading.Tasks;
6+
using EventHorizon.Blazor.TypeScript.Interop.Generator.AstParser.Api;
7+
using EventHorizon.Blazor.TypeScript.Interop.Generator.AstParser.Model.Types;
58
using EventHorizon.Blazor.TypeScript.Interop.Generator.AstParser.NodeImpl;
69
using EventHorizon.Blazor.TypeScript.Interop.Generator.AstParser.SdcdImpl;
710
using EventHorizon.Blazor.TypeScript.Interop.Generator.Identifiers;
811
using EventHorizon.Blazor.TypeScript.Interop.Generator.Model.Statements;
912
using FluentAssertions;
13+
using Moq;
1014
using Xunit;
1115

1216
public class InterfaceResponseTypeIdentifierTests
@@ -365,5 +369,66 @@ bool expected
365369
actual.Should()
366370
.Be(expected);
367371
}
372+
373+
[Theory]
374+
[Trait("Category", "EdgeCase")]
375+
[InlineData(SyntaxKind.ClassDeclaration, false)]
376+
[InlineData(SyntaxKind.InterfaceDeclaration, true)]
377+
public void ShouldValidateAgainstCacheWhenDeclarationTypeIsUsed(
378+
string declarationType,
379+
bool found
380+
)
381+
{
382+
// Given
383+
var expected = 1;
384+
var identifierString = "identifier-string";
385+
var mockNode = new NodeMock
386+
{
387+
IdentifierStr = identifierString,
388+
};
389+
390+
var astMock = new Mock<AbstractSyntaxTree>();
391+
var rootNodeMock = new Mock<Node>();
392+
393+
astMock.Setup(
394+
mock => mock.RootNode
395+
).Returns(
396+
rootNodeMock.Object
397+
);
398+
399+
rootNodeMock.Setup(
400+
mock => mock.OfKind(
401+
declarationType
402+
)
403+
).Returns(
404+
new List<Node>
405+
{
406+
mockNode
407+
}
408+
);
409+
410+
// When
411+
var alias = new InterfaceResponseTypeIdentifierCached();
412+
var actual = alias.Identify(
413+
identifierString,
414+
astMock.Object
415+
);
416+
actual.Should().Be(found);
417+
418+
actual = alias.Identify(
419+
identifierString,
420+
astMock.Object
421+
);
422+
423+
// Then
424+
actual.Should().Be(found);
425+
426+
rootNodeMock.Verify(
427+
mock => mock.OfKind(
428+
declarationType
429+
),
430+
Times.Exactly(expected)
431+
);
432+
}
368433
}
369434
}

Tool/EventHorizon.Blazor.TypeScript.Interop.Tool/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ Identifier | Details | Required/Default
1919
-a, --project-assembly &lt;project-assembly&gt; | The project name of the Assembly that will be generated | Default: "Generated.WASM"
2020
-l, --project-generation-location &lt;project-generation-location&gt; | The directory where the Generated Project assembly will be saved | Default: "_generated"
2121
-f, --force | This will force generation, by deleting --project-generation-location | Default: (False)
22+
-p, --parser | The type of TypeScript parser to use, Supported values: ("dotnet","nodejs") | Default: ("dotnet")
23+
24+
## Parsers
25+
26+
The tool supports two types of parsers, one using the embedded .NET parser and one using NodeJS the TypeScript Complier.
27+
28+
These both have trade offs:
29+
30+
Type | Details
31+
--- | ---
32+
dotnet | Has no external dependencies, and on average 3x faster than the nodejs parser. A con is that it does not support modern TypeScript syntax, but should coverage 90% of use-cases.
33+
nodejs | Requires NodeJS to function, supports modern TypeScript syntax. A con is that it is very slow relative to the dotnet parser.
2234

2335
## Usage
2436

0 commit comments

Comments
 (0)