diff --git a/DotNet/Bootsharp.Builder.Test/ExportTest.cs b/DotNet/Bootsharp.Builder.Test/ExportTest.cs index ba80e400..00eb889f 100644 --- a/DotNet/Bootsharp.Builder.Test/ExportTest.cs +++ b/DotNet/Bootsharp.Builder.Test/ExportTest.cs @@ -5,23 +5,52 @@ public class ExportTest : PrepareBootsharpTest protected override string TestedContent => GeneratedExports; [Fact] - public void WhenNothingInspected () + public void WhenNothingInspectedNothingIsGenerated () { Execute(); - Contains( - """ + Assert.Empty(TestedContent); + } - """); + [Fact] + public void WhenNoInvokablesNothingIsGenerated () + { + AddAssembly(With("[JSFunction] public static void Foo () {}")); + Execute(); + Assert.Empty(TestedContent); } [Fact] - public void WhenNoCrawledExports () + public void ExportsInvokable () { - AddAssembly(With("[JSInvokable] public static void Foo () { }")); + AddAssembly(With( + """ + namespace Space; + + public record Info(string Foo); + + public class Foo + { + [JSInvokable] public static void Void () {} + [JSInvokable] public static global::Space.Info? WithArgs (string a, global::System.Int32[] b) => default; + [JSInvokable] public static global::System.Threading.Tasks.Task Async () => default; + [JSInvokable] public static Task AsyncWithArgs (Info i) => default; + } + """, false)); Execute(); Contains( """ + using System.Runtime.InteropServices.JavaScript; + using static Bootsharp.Serializer; + + namespace Bootsharp; + public partial class InteropExports_Space_Foo + { + [JSExport] internal static void Void () => global::Space.Foo.Void(); + [JSExport] internal static global::System.String? WithArgs (global::System.String a, global::System.Int32[] b) => Serialize(global::Space.Foo.WithArgs(a, b)); + [JSExport] internal static global::System.Threading.Tasks.Task Async () => global::Space.Foo.Async(); + [JSExport] internal static async global::System.Threading.Tasks.Task AsyncWithArgs (global::System.String i) => Serialize(await global::Space.Foo.AsyncWithArgs(Deserialize(i))); + } """); } } diff --git a/DotNet/Bootsharp.Builder.Test/ImportTest.cs b/DotNet/Bootsharp.Builder.Test/ImportTest.cs index c110f4f0..cacad49c 100644 --- a/DotNet/Bootsharp.Builder.Test/ImportTest.cs +++ b/DotNet/Bootsharp.Builder.Test/ImportTest.cs @@ -17,7 +17,7 @@ public void WhenNothingInspected () [Fact] public void WhenNoCrawledImports () { - AddAssembly(With("[JSFunction] public static void Foo () { }")); + AddAssembly(With("[JSInvokable] public static void Foo () { }")); Execute(); Contains( """ diff --git a/DotNet/Bootsharp.Builder/ExportGenerator/ExportGenerator.cs b/DotNet/Bootsharp.Builder/ExportGenerator/ExportGenerator.cs index 89d396e4..9b069c7a 100644 --- a/DotNet/Bootsharp.Builder/ExportGenerator/ExportGenerator.cs +++ b/DotNet/Bootsharp.Builder/ExportGenerator/ExportGenerator.cs @@ -2,8 +2,8 @@ namespace Bootsharp.Builder; internal sealed class ExportGenerator { - public string Generate (AssemblyInspector inspector) + public static string Generate (AssemblyInspector inspector) { - return ""; + return new ExportTemplate().Build(); } } diff --git a/DotNet/Bootsharp.Builder/ExportGenerator/ExportTemplate.cs b/DotNet/Bootsharp.Builder/ExportGenerator/ExportTemplate.cs index cbb541ef..2275553d 100644 --- a/DotNet/Bootsharp.Builder/ExportGenerator/ExportTemplate.cs +++ b/DotNet/Bootsharp.Builder/ExportGenerator/ExportTemplate.cs @@ -3,5 +3,15 @@ namespace Bootsharp.Builder; internal sealed class ExportTemplate() { public string Build () => - $$""" """; + $$""" + using System.Runtime.InteropServices.JavaScript; + using static Bootsharp.Serializer; + + namespace Bootsharp; + + public static partial class InteropExports + { + + } + """; } diff --git a/DotNet/Bootsharp.Generator.Test/Emitters/ExportTest.cs b/DotNet/Bootsharp.Generator.Test/Emitters/ExportTest.cs index 7363592a..8dc43720 100644 --- a/DotNet/Bootsharp.Generator.Test/Emitters/ExportTest.cs +++ b/DotNet/Bootsharp.Generator.Test/Emitters/ExportTest.cs @@ -15,7 +15,7 @@ public static class ExportTest public interface IFoo { void Foo (string? foo); - ValueTask Bar (); + Task Bar (); Item? Baz (); Task Nya (); string[] Far (int[] far); @@ -38,7 +38,7 @@ public JSFoo (global::IFoo handler) internal static void RegisterDynamicDependencies () { } [JSInvokable] public static void Foo (global::System.String? foo) => handler.Foo(foo); - [JSInvokable] public static global::System.Threading.Tasks.ValueTask Bar () => handler.Bar(); + [JSInvokable] public static global::System.Threading.Tasks.Task Bar () => handler.Bar(); [JSInvokable] public static global::Item? Baz () => handler.Baz(); [JSInvokable] public static global::System.Threading.Tasks.Task Nya () => handler.Nya(); [JSInvokable] public static global::System.String[] Far (global::System.Int32[] far) => handler.Far(far);