File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -354,7 +354,8 @@ impl<'a> Context<'a> {
354
354
| OutputMode :: Node {
355
355
experimental_modules : true ,
356
356
} => {
357
- js. push_str ( & format ! ( "import * as wasm from './{}_bg';\n " , module_name) ) ;
357
+ self . imports
358
+ . push_str ( & format ! ( "import * as wasm from './{}_bg';\n " , module_name) ) ;
358
359
if needs_manual_start {
359
360
self . footer . push_str ( "wasm.__wbindgen_start();\n " ) ;
360
361
}
@@ -365,7 +366,7 @@ impl<'a> Context<'a> {
365
366
// expose the same initialization function as `--target no-modules`
366
367
// as the default export of the module.
367
368
OutputMode :: Web => {
368
- js . push_str ( "const __exports = {};\n " ) ;
369
+ self . imports_post . push_str ( "const __exports = {};\n " ) ;
369
370
self . imports_post . push_str ( "let wasm;\n " ) ;
370
371
init = self . gen_init ( & module_name, needs_manual_start) ;
371
372
self . footer . push_str ( "export default init;\n " ) ;
@@ -377,6 +378,10 @@ impl<'a> Context<'a> {
377
378
ts. push_str ( & init_ts) ;
378
379
379
380
// Emit all the JS for importing all our functionality
381
+ assert ! (
382
+ !self . config. mode. uses_es_modules( ) || js. is_empty( ) ,
383
+ "ES modules require imports to be at the start of the file"
384
+ ) ;
380
385
js. push_str ( & self . imports ) ;
381
386
js. push_str ( "\n " ) ;
382
387
js. push_str ( & self . imports_post ) ;
Original file line number Diff line number Diff line change @@ -42,6 +42,19 @@ enum OutputMode {
42
42
Node { experimental_modules : bool } ,
43
43
}
44
44
45
+ impl OutputMode {
46
+ fn uses_es_modules ( & self ) -> bool {
47
+ match self {
48
+ OutputMode :: Bundler { .. }
49
+ | OutputMode :: Web
50
+ | OutputMode :: Node {
51
+ experimental_modules : true ,
52
+ } => true ,
53
+ _ => false ,
54
+ }
55
+ }
56
+ }
57
+
45
58
enum Input {
46
59
Path ( PathBuf ) ,
47
60
Module ( Module , String ) ,
You can’t perform that action at this time.
0 commit comments