Skip to content

Commit

Permalink
Merge pull request #99 from nenoNaninu/support_partial_class
Browse files Browse the repository at this point in the history
Support partial class
  • Loading branch information
nenoNaninu committed Jun 26, 2023
2 parents 61eb658 + 2587404 commit ab18d7f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Tapper/RoslynExtensions.TypeCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public static INamedTypeSymbol[] GetSourceTypes(this Compilation compilation, bo
return false;
})
.Distinct<INamedTypeSymbol>(SymbolEqualityComparer.Default)
.ToArray();

return TargetTypes;
Expand Down
12 changes: 12 additions & 0 deletions tests/Tapper.Test.SourceTypes/PartialClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Tapper.Test.SourceTypes;

[TranspilationSource]
public partial class PartialClass
{
public int Value1 { get; set; }
}

public partial class PartialClass
{
public int Value2 { get; set; }
}
5 changes: 5 additions & 0 deletions tests/Tapper.Tests/CompilationSingleton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ static CompilationSingleton()
File.ReadAllText("../../../../Tapper.Test.SourceTypes/MessagePackAttributes.cs"),
options);

var partialClassSyntax = CSharpSyntaxTree.ParseText(
File.ReadAllText("../../../../Tapper.Test.SourceTypes/PartialClass.cs"),
options);

var compilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)
.WithNullableContextOptions(NullableContextOptions.Enable);

Expand All @@ -82,6 +86,7 @@ static CompilationSingleton()
inheritanceSyntax,
attributeAnnotatedSyntax,
messagePackAttributesSyntax,
partialClassSyntax
},
references: references,
options: compilationOptions);
Expand Down
56 changes: 56 additions & 0 deletions tests/Tapper.Tests/PartialClassTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Tapper.Test.SourceTypes;
using Xunit;
using Xunit.Abstractions;

namespace Tapper.Tests;

public class PartialClassTest
{
private readonly ITestOutputHelper _output;

public PartialClassTest(ITestOutputHelper output)
{
_output = output;
}

[Fact]
public void Test()
{
var compilation = CompilationSingleton.Compilation;

var options = new TranspilationOptions(
compilation,
SerializerOption.Json,
NamingStyle.CamelCase,
EnumStyle.Value,
NewLineOption.Lf,
2,
false,
true
);

var codeGenerator = new TypeScriptCodeGenerator(compilation, options);

var type = typeof(PartialClass);
var typeSymbol = compilation.GetTypeByMetadataName(type.FullName!)!;

var writer = new CodeWriter();

codeGenerator.AddType(typeSymbol, ref writer);

var code = writer.ToString();
var gt = @"/** Transpiled from Tapper.Test.SourceTypes.PartialClass */
export type PartialClass = {
/** Transpiled from int */
value1: number;
/** Transpiled from int */
value2: number;
}
";

_output.WriteLine(code);
_output.WriteLine(gt);

Assert.Equal(gt, code, ignoreLineEndingDifferences: true);
}
}

0 comments on commit ab18d7f

Please sign in to comment.