diff --git a/src/Tapper/RoslynExtensions.TypeCollector.cs b/src/Tapper/RoslynExtensions.TypeCollector.cs index fe78f4f..a923165 100644 --- a/src/Tapper/RoslynExtensions.TypeCollector.cs +++ b/src/Tapper/RoslynExtensions.TypeCollector.cs @@ -87,6 +87,7 @@ public static INamedTypeSymbol[] GetSourceTypes(this Compilation compilation, bo return false; }) + .Distinct(SymbolEqualityComparer.Default) .ToArray(); return TargetTypes; diff --git a/tests/Tapper.Test.SourceTypes/PartialClass.cs b/tests/Tapper.Test.SourceTypes/PartialClass.cs new file mode 100644 index 0000000..0537f00 --- /dev/null +++ b/tests/Tapper.Test.SourceTypes/PartialClass.cs @@ -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; } +} diff --git a/tests/Tapper.Tests/CompilationSingleton.cs b/tests/Tapper.Tests/CompilationSingleton.cs index c8d7bc0..908c538 100644 --- a/tests/Tapper.Tests/CompilationSingleton.cs +++ b/tests/Tapper.Tests/CompilationSingleton.cs @@ -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); @@ -82,6 +86,7 @@ static CompilationSingleton() inheritanceSyntax, attributeAnnotatedSyntax, messagePackAttributesSyntax, + partialClassSyntax }, references: references, options: compilationOptions); diff --git a/tests/Tapper.Tests/PartialClassTest.cs b/tests/Tapper.Tests/PartialClassTest.cs new file mode 100644 index 0000000..d141a1e --- /dev/null +++ b/tests/Tapper.Tests/PartialClassTest.cs @@ -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); + } +}