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

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

Open
7ombie opened this issue Jun 18, 2024 · 0 comments
Open

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

7ombie opened this issue Jun 18, 2024 · 0 comments

Comments

@7ombie
Copy link

7ombie commented Jun 18, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant