elringus / bootsharp

Compile C# solution into single-file ES module with auto-generated JavaScript bindings and type definitions

Home Page:https://bootsharp.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Malformed bindings.g.js due to improper namespaces names handling

CADBIMDeveloper opened this issue · comments

Hi @elringus ,

Bootsharp makes malformed bindings.g.js file in some cases when the first namespace name is a part of the second namespace name and parseAst.js fails with a message like Expected ',' got 'export'.

I manged to reproduce this issue with the following toy example:

namespace BootSharpBackendCore.Input;

public enum Foo
{
    Value1 = 0,

    Value2 = 1
}
using BootSharpBackendCore.Input;

namespace BootSharpBackendCore.Output;

public record Bar(Foo Foo);
namespace BootSharpBackendCore;

public static class Facade
{
    public static IReadOnlyList<Bar> Test(Foo foo) => new[] { new Bar(foo) };
}

and a project with JSInvokable:

using Bootsharp;
using BootSharpBackendCore;
using BootSharpBackendCore.Input;
using BootSharpBackendCore.Output;

namespace BootSharpBackend;

public static partial class Program
{
    public static void Main()
    {

    }
    [JSInvokable]
    public static IReadOnlyList<Bar> Test(Foo foo) => Facade.Test(foo);
}

dotnet publish command will fail, but some of artifacts will remain, so, the bin\Release\net8.0\browser-wasm\AppBundle\_framework\bindings.g.js file will have something like that:

import { exports } from "./exports";
import { Event } from "./event";
function getExports () { if (exports == null) throw Error("Boot the runtime before invoking C# APIs."); return exports; }
function serialize(obj) { return JSON.stringify(obj); }
function deserialize(json) { const result = JSON.parse(json); if (result === null) return undefined; return result; }

export const BootSharpBackend = {
    test: (foo) => deserialize(getExports().BootSharpBackend_Program.Test(serialize(foo)))
export const BootSharpBackendCore = {
    Input: {
        Foo: { "0": "Value1", "1": "Value2", "Value1": 0, "Value2": 1 }
    }
};

Thank you!

Thanks for the notice! I'm currently in the process of migrating from source gen to interceptors; will look into this once done.