Skip to content

Commit

Permalink
fix nullable gen (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
elringus authored May 14, 2023
1 parent b6b2d46 commit 5030cb0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DotNet/DotNetJS/DotNetJS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<AssemblyTitle>DotNetJS</AssemblyTitle>
<Title>DotNetJS</Title>
<PackageId>DotNetJS</PackageId>
<Version>0.23.3</Version>
<Version>0.23.4</Version>
<Authors>Elringus</Authors>
<PackageDescription>Consume C# in JavaScript with comfort: single-file UMD library, auto-generated 2-way bindings and type definitions.</PackageDescription>
<Description>Consume C# in JavaScript with comfort: single-file UMD library, auto-generated 2-way bindings and type definitions.</Description>
Expand Down
4 changes: 4 additions & 0 deletions DotNet/Generator.Test/ExportTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ public static class ExportTest
namespace Bindings;
public readonly record struct Item();
public interface IFoo
{
void Foo (string? foo);
ValueTask Bar ();
Item? Baz ();
Task<string> Nya ();
string[] Far (int[] far);
}
Expand All @@ -38,6 +41,7 @@ public JSFoo (global::Bindings.IFoo handler)
[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::Bindings.Item? Baz () => handler.Baz();
[JSInvokable] public static global::System.Threading.Tasks.Task<global::System.String> Nya () => handler.Nya();
[JSInvokable] public static global::System.String[] Far (global::System.Int32[] far) => handler.Far(far);
}
Expand Down
10 changes: 8 additions & 2 deletions DotNet/Generator/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ public static string BuildFullName (ITypeSymbol type)
if (type.SpecialType == SpecialType.System_Void) return "void";
if (type is IArrayTypeSymbol arrayType) return $"{BuildFullName(arrayType.ElementType)}[]";
var nullable = type.NullableAnnotation == NullableAnnotation.Annotated ? "?" : "";
var name = IsGeneric(type, out var args) ? $"{type.Name}<{string.Join(", ", args.Select(BuildFullName))}>" : type.Name;
return $"global::{ResolveNamespace(type)}.{name}{nullable}";
if (IsGeneric(type, out var args)) return BuildGeneric(type, args) + nullable;
return $"global::{ResolveNamespace(type)}.{type.Name}{nullable}";

static string BuildGeneric (ITypeSymbol type, ImmutableArray<ITypeSymbol> args)
{
if (type.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T) return BuildFullName(args[0]);
return $"global::{ResolveNamespace(type)}.{type.Name}<{string.Join(", ", args.Select(BuildFullName))}>";
}
}

public static string BuildInvoke (IMethodSymbol method, string methodName, Compilation compilation)
Expand Down

0 comments on commit 5030cb0

Please sign in to comment.