Skip to content

Support ES6 modules and browsers (in one line). #47

@7ombie

Description

@7ombie

WABT can be useful in the browser, but there's no way to import it there.

Adding the following line to the very end of the wabt.js file (available from the CDNs) makes it importable (as a standard ES6 module):

export default WabtModule;

The API can then be imported using any name you like (Wabt in this example):

import Wabt from "path/to/wabt.js";
const wabt = await Wabt();
const module = wabt.readWasm(someBinary, {});

Note: If your browser lacks support for top-level await, you'd need to wrap that code in an async-function.

IIUC, Node has provided "experimental support" for ES6 modules for some years, so the parser shouldn't choke on the export statement.

Unless I'm missing something, it seems like it'd be a simple change (and this has been requested a few times, in one form or another). Thanks for considering it, either way.

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