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

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

Closed
CADBIMDeveloper opened this issue Jan 4, 2024 · 1 comment · Fixed by #132
Closed

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

CADBIMDeveloper opened this issue Jan 4, 2024 · 1 comment · Fixed by #132
Labels
bug Something isn't working

Comments

@CADBIMDeveloper
Copy link
Contributor

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!

@elringus
Copy link
Owner

elringus commented Jan 4, 2024

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

@elringus elringus added the bug Something isn't working label Jan 4, 2024
@elringus elringus mentioned this issue Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants