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 js space #132

Merged
merged 3 commits into from
Jan 5, 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
21 changes: 21 additions & 0 deletions src/cs/Bootsharp.Publish.Test/Pack/BindingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,27 @@ public void DifferentSpacesWithSameRootAssignedUnderSameObject ()
""");
}

[Fact]
public void DifferentSpacesStartingEquallyAreNotAssignedToSameObject ()
{
AddAssembly(
WithClass("Foo", "[JSInvokable] public static void Method () { }"),
WithClass("FooBar.Baz", "[JSInvokable] public static void Method () { }")
);
Execute();
Contains(
"""
export const Foo = {
method: () => getExports().Foo_MockClass.Method()
};
export const FooBar = {
Baz: {
method: () => getExports().FooBar_Baz_MockClass.Method()
}
};
""");
}

[Fact]
public void BindingsFromMultipleSpacesAssignedToRespectiveObjects ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public string Build (Type type)
return space;
}

private IEnumerable<CustomAttributeData> CollectAttributes (System.Reflection.Assembly assembly)
private IEnumerable<CustomAttributeData> CollectAttributes (Assembly assembly)
{
return assembly.CustomAttributes.Where(a => a.AttributeType.Name == attributeName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ private bool ShouldCloseNamespace ()

private void CloseNamespace ()
{
var target = nextBinding is null ? 0 : nextBinding.Namespace.Count(c => c == '.');
var target = (nextBinding is null || GetRoot(nextBinding) != GetRoot(binding)) ? 0
: nextBinding.Namespace.Count(c => c == '.');
for (; level >= target; level--)
if (level == 0) builder.Append("\n};");
else builder.Append($"\n{Pad(level)}}}");
Expand Down Expand Up @@ -132,6 +133,13 @@ private void EmitEnum (Type @enum)
builder.Append($"{Comma()}\n{Pad(level + 1)}{@enum.Name}: {{ {fields} }}");
}

private string GetRoot (Binding binding)
{
var firstDotIdx = binding.Namespace.IndexOf('.');
if (firstDotIdx < 0) return binding.Namespace;
return binding.Namespace[..firstDotIdx];
}

private string Pad (int level) => new(' ', level * 4);
private string Comma () => builder[^1] == '{' ? "" : ",";
private bool ShouldWait (MethodMeta method) =>
Expand Down
2 changes: 1 addition & 1 deletion src/cs/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>0.1.1</Version>
<Version>0.1.2</Version>
<Authors>Elringus</Authors>
<PackageTags>javascript typescript ts js wasm node deno bun interop codegen</PackageTags>
<PackageProjectUrl>https://bootsharp.com</PackageProjectUrl>
Expand Down
Loading