Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix generator bug with non-public nested types #374

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/NodeApi.Generator/ModuleGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,8 @@ private void ExportType(
$"{nameof(JSPropertyAttributes)}.{nameof(JSPropertyAttributes.Enumerable)}";

// Declare nested types first, so they can be exported as static properties of this type.
foreach (INamedTypeSymbol nestedType in type.GetTypeMembers())
foreach (INamedTypeSymbol nestedType in type.GetTypeMembers()
.Where((t) => t.DeclaredAccessibility == Accessibility.Public))
{
ExportType(ref s, nestedType, GetExportName(nestedType));
}
Expand Down
5 changes: 5 additions & 0 deletions test/TestCases/napi-dotnet/ComplexTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ public NestedClass(string value)

public string Value { get; set; }
}

// Non-public nested types should not be exported.
internal class PrivateNestedClass
{
}
}

[JSExport]
Expand Down
Loading