Skip to content

Functions returning structs are not working in no-modules mode #190

Closed
@ngg

Description

@ngg

Smallest example that reproduces this bug:

#[wasm_bindgen]
pub struct S;

#[wasm_bindgen]
pub fn create_s() -> S {
    S
}

The generated JS file (with --no-modules) contains something like this:

__exports.create_s = function() {
    return S.__construct(wasm.create_s());
}

__exports.S = class S {
    // ...
}

When I call the create_s function it fails with ReferenceError: S is not defined.
If I modify the JS file either to call __exports.S.__construct or export the class as let S = null; __exports.S = S = class S { ... } then it works as supposed.

The second way seems like a really easy fix, I'll create a pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions