mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 02:00:51 +00:00
Merge pull request #1424 from fitzgen/fix-imports
Don't put anything before ES module imports
This commit is contained in:
commit
aa0aff674c
@ -354,7 +354,8 @@ impl<'a> Context<'a> {
|
||||
| OutputMode::Node {
|
||||
experimental_modules: true,
|
||||
} => {
|
||||
js.push_str(&format!("import * as wasm from './{}_bg';\n", module_name));
|
||||
self.imports
|
||||
.push_str(&format!("import * as wasm from './{}_bg';\n", module_name));
|
||||
if needs_manual_start {
|
||||
self.footer.push_str("wasm.__wbindgen_start();\n");
|
||||
}
|
||||
@ -365,7 +366,7 @@ impl<'a> Context<'a> {
|
||||
// expose the same initialization function as `--target no-modules`
|
||||
// as the default export of the module.
|
||||
OutputMode::Web => {
|
||||
js.push_str("const __exports = {};\n");
|
||||
self.imports_post.push_str("const __exports = {};\n");
|
||||
self.imports_post.push_str("let wasm;\n");
|
||||
init = self.gen_init(&module_name, needs_manual_start);
|
||||
self.footer.push_str("export default init;\n");
|
||||
@ -377,6 +378,10 @@ impl<'a> Context<'a> {
|
||||
ts.push_str(&init_ts);
|
||||
|
||||
// Emit all the JS for importing all our functionality
|
||||
assert!(
|
||||
!self.config.mode.uses_es_modules() || js.is_empty(),
|
||||
"ES modules require imports to be at the start of the file"
|
||||
);
|
||||
js.push_str(&self.imports);
|
||||
js.push_str("\n");
|
||||
js.push_str(&self.imports_post);
|
||||
|
@ -42,6 +42,19 @@ enum OutputMode {
|
||||
Node { experimental_modules: bool },
|
||||
}
|
||||
|
||||
impl OutputMode {
|
||||
fn uses_es_modules(&self) -> bool {
|
||||
match self {
|
||||
OutputMode::Bundler { .. }
|
||||
| OutputMode::Web
|
||||
| OutputMode::Node {
|
||||
experimental_modules: true,
|
||||
} => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum Input {
|
||||
Path(PathBuf),
|
||||
Module(Module, String),
|
||||
|
Loading…
x
Reference in New Issue
Block a user