Default imports
Motivation
It would be nice if there was a syntax for doing default import of modules. Many npm modules are distributed with the only export being the default export.
Proposed Solution
#[wasm_bindgen(module = "pi")]
extern "C" {
#[wasm_bindgen(default_symbol)]
pi: f64;
}
Alternatives
There may be another way to import a library such as pi, but I am new to wasm-bindgen and couldn't find anything in the docs that provides instructions.
I believe this should work with js_name = default, does that work for you?
Sorry, what would that look like syntactically? I tried this but it led to a syntax error:
#[wasm_bindgen(module = "pi")]
extern "C" {
#[wasm_bindgen(js_name = "default")]
pi: f64;
}
Have you tried using static pi: f64 perhaps?
Same problem here, also when trying to import a class (via type).
Okay, got this working for a class by adding js_class:
#[wasm_bindgen(module = "/mymodule.esm.js")]
extern "C" {
type MyClass;
#[wasm_bindgen(constructor, js_class = "default")]
fn new() -> MyClass;
}
The workaround now seems to be broken in 0.2.100 by https://github.com/rustwasm/wasm-bindgen/pull/4329#issuecomment-2672840111