Skip to content

Commit 118d47f

Browse files
authored
fix js space (#132)
1 parent 6de6283 commit 118d47f

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

src/cs/Bootsharp.Publish.Test/Pack/BindingTest.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,27 @@ public void DifferentSpacesWithSameRootAssignedUnderSameObject ()
169169
""");
170170
}
171171

172+
[Fact]
173+
public void DifferentSpacesStartingEquallyAreNotAssignedToSameObject ()
174+
{
175+
AddAssembly(
176+
WithClass("Foo", "[JSInvokable] public static void Method () { }"),
177+
WithClass("FooBar.Baz", "[JSInvokable] public static void Method () { }")
178+
);
179+
Execute();
180+
Contains(
181+
"""
182+
export const Foo = {
183+
method: () => getExports().Foo_MockClass.Method()
184+
};
185+
export const FooBar = {
186+
Baz: {
187+
method: () => getExports().FooBar_Baz_MockClass.Method()
188+
}
189+
};
190+
""");
191+
}
192+
172193
[Fact]
173194
public void BindingsFromMultipleSpacesAssignedToRespectiveObjects ()
174195
{

src/cs/Bootsharp.Publish/Common/NamespaceBuilder/NamespaceBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public string Build (Type type)
2525
return space;
2626
}
2727

28-
private IEnumerable<CustomAttributeData> CollectAttributes (System.Reflection.Assembly assembly)
28+
private IEnumerable<CustomAttributeData> CollectAttributes (Assembly assembly)
2929
{
3030
return assembly.CustomAttributes.Where(a => a.AttributeType.Name == attributeName);
3131
}

src/cs/Bootsharp.Publish/Pack/BindingGenerator/BindingGenerator.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ private bool ShouldCloseNamespace ()
6969

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

136+
private string GetRoot (Binding binding)
137+
{
138+
var firstDotIdx = binding.Namespace.IndexOf('.');
139+
if (firstDotIdx < 0) return binding.Namespace;
140+
return binding.Namespace[..firstDotIdx];
141+
}
142+
135143
private string Pad (int level) => new(' ', level * 4);
136144
private string Comma () => builder[^1] == '{' ? "" : ",";
137145
private bool ShouldWait (MethodMeta method) =>

src/cs/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>0.1.1</Version>
3+
<Version>0.1.2</Version>
44
<Authors>Elringus</Authors>
55
<PackageTags>javascript typescript ts js wasm node deno bun interop codegen</PackageTags>
66
<PackageProjectUrl>https://bootsharp.com</PackageProjectUrl>

0 commit comments

Comments
 (0)