piu_core 0.412.1

A modern JavaScript/TypeScript runtime built with V8, Rust, and Tokio
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
// Copyright 2018-2026 the Deno authors. MIT license.

use std::borrow::Cow;

use indexmap::IndexMap;
use wasm_dep_analyzer::WasmDeps;

use super::ModuleMap;
use crate::ModuleSourceCode;
use crate::modules::ModuleConcreteError;
use crate::modules::ModuleError;
use crate::modules::ModuleId;
use crate::modules::ModuleName;
use crate::modules::ModuleReference;
use crate::modules::ModuleSource;
use crate::modules::ModuleType;
use crate::modules::module_map_data::ModuleSourceKey;

impl ModuleMap {
  pub(crate) fn new_wasm_module_source(
    &self,
    scope: &mut v8::PinScope,
    module_reference: &ModuleReference,
    mut loaded_source: ModuleSource,
  ) -> Result<ModuleSource, ModuleError> {
    if let Some(module_url_found) = loaded_source.cheap_copy_module_url_found()
    {
      self.data.borrow_mut().alias(
        loaded_source.cheap_copy_module_url_specified(),
        &loaded_source.module_type.clone().into(),
        module_url_found,
      );
    }
    let reference_key = ModuleSourceKey::from_reference(module_reference);
    if self.data.borrow().sources.contains_key(&reference_key) {
      return Ok(loaded_source);
    }
    let loaded_key = ModuleSourceKey::from_loaded_source(&mut loaded_source);
    if let Some(source) = self.data.borrow().sources.get(&loaded_key).cloned() {
      self.data.borrow_mut().sources.insert(reference_key, source);
      return Ok(loaded_source);
    }

    let ModuleSourceCode::Bytes(code) = &loaded_source.code else {
      return Err(ModuleError::Concrete(ModuleConcreteError::WasmNotBytes));
    };
    let Some(wasm_module) =
      v8::WasmModuleObject::compile(scope, code.as_bytes())
    else {
      return Err(
        ModuleConcreteError::WasmCompile(loaded_key.name.to_string()).into(),
      );
    };
    let wasm_module_object: v8::Local<v8::Object> = wasm_module.into();
    let source = v8::Global::new(scope, wasm_module_object);
    {
      let mut data = self.data.borrow_mut();
      data.sources.insert(reference_key, source.clone());
      data.sources.insert(loaded_key, source);
    }
    Ok(loaded_source)
  }

  pub(crate) fn new_wasm_module(
    &self,
    scope: &mut v8::PinScope,
    name: ModuleName,
    source: ModuleSourceCode,
    is_dynamic_import: bool,
  ) -> Result<ModuleId, ModuleError> {
    let bytes = source.as_bytes();
    let wasm_module_analysis = WasmDeps::parse(
      bytes,
      wasm_dep_analyzer::ParseOptions { skip_types: true },
    )
    .map_err(ModuleConcreteError::WasmParse)?;

    let js_wasm_module_source =
      render_js_wasm_module(name.as_str(), wasm_module_analysis);

    self.new_module_from_js_source(
      scope,
      false,
      ModuleType::Wasm,
      name,
      js_wasm_module_source.into(),
      is_dynamic_import,
      None,
    )
  }
}

/// Helper injected into the synthetic module for `.wasm` files that have global
/// exports. Per the Wasm ESM integration, a global export is unwrapped to its
/// underlying JS value (e.g. an `i32` global exports the number directly)
/// instead of being exposed as a `WebAssembly.Global` object, matching Node.js.
/// Reading `.value` throws for `v128` globals, so we fall back to the
/// `WebAssembly.Global` object in that case. The value is read once at
/// instantiation (a snapshot), so a later mutation of a mutable global is not
/// reflected in the export, which also matches Node. Wasm modules importing
/// the global are not affected by the snapshot: they link against the
/// original `WebAssembly.Global` via `import.meta.wasmInstances`.
const WASM_GLOBAL_UNWRAP_HELPER: &str = "const unwrapWasmGlobal = (g) => { try { return g.value; } catch { return g; } };\n";

/// Whether a Wasm export is a global. The export kind is read directly from the
/// export section, so this is reliable even though we parse the module with
/// `skip_types: true` and never resolve the global's value type.
fn is_wasm_global_export(export_type: &wasm_dep_analyzer::ExportType) -> bool {
  matches!(export_type, wasm_dep_analyzer::ExportType::Global(_))
}

/// Whether a Wasm import is a global. Like [`is_wasm_global_export`], the import
/// kind is read directly from the import section, independent of the global's
/// value type.
fn is_wasm_global_import(import_type: &wasm_dep_analyzer::ImportType) -> bool {
  matches!(import_type, wasm_dep_analyzer::ImportType::Global(_))
}

/// Values that [`StringBuilder::append`] knows how to write.
trait AppendToString {
  fn append_to(self, out: &mut String);
}

impl AppendToString for &str {
  fn append_to(self, out: &mut String) {
    out.push_str(self);
  }
}

impl AppendToString for &String {
  fn append_to(self, out: &mut String) {
    out.push_str(self);
  }
}

impl AppendToString for &Cow<'_, str> {
  fn append_to(self, out: &mut String) {
    out.push_str(self);
  }
}

impl AppendToString for char {
  fn append_to(self, out: &mut String) {
    out.push(self);
  }
}

impl AppendToString for usize {
  fn append_to(self, out: &mut String) {
    // Cold path (module rendering), so the temporary allocation is fine.
    out.push_str(&self.to_string());
  }
}

/// Append-only string builder over a preallocated [`String`].
///
/// Just enough of an API to render the synthetic Wasm wrapper module below
/// without depending on a proc-macro string-building crate.
struct StringBuilder(String);

impl StringBuilder {
  fn with_capacity(capacity: usize) -> Self {
    Self(String::with_capacity(capacity))
  }

  fn append(&mut self, value: impl AppendToString) {
    value.append_to(&mut self.0);
  }

  fn build(self) -> String {
    self.0
  }
}

fn render_js_wasm_module(specifier: &str, wasm_deps: WasmDeps) -> String {
  struct NamedImport {
    escaped_name: String,
    is_global: bool,
  }

  struct ImportInfo {
    key_escaped: String,
    named_imports: Vec<NamedImport>,
    has_global_import: bool,
  }

  fn aggregate_wasm_module_imports<'a>(
    imports: &'a [wasm_dep_analyzer::Import],
  ) -> IndexMap<&'a str, ImportInfo> {
    let mut imports_map = IndexMap::with_capacity(imports.len());

    for import in imports {
      let entry =
        imports_map
          .entry(import.module)
          .or_insert_with(|| ImportInfo {
            key_escaped: import.module.escape_default().to_string(),
            named_imports: Vec::new(),
            has_global_import: false,
          });
      let is_global = is_wasm_global_import(&import.import_type);
      entry.has_global_import |= is_global;
      entry.named_imports.push(NamedImport {
        escaped_name: import.name.escape_default().to_string(),
        is_global,
      });
    }

    imports_map
  }

  let aggregated_imports = aggregate_wasm_module_imports(&wasm_deps.imports);
  let exports = wasm_deps
    .exports
    .iter()
    .map(|e| {
      let escaped_name = if e.name == "default" {
        Cow::Borrowed(e.name)
      } else {
        Cow::Owned(e.name.escape_default().to_string())
      };
      (escaped_name, is_wasm_global_export(&e.export_type))
    })
    .collect::<Vec<_>>();
  let has_global_export = exports.iter().any(|(_, is_global)| *is_global);

  // Rough starting capacity; the builder grows as needed.
  let mut builder = StringBuilder::with_capacity(
    256 + 128 * (aggregated_imports.len() + exports.len()),
  );
  {
    let builder = &mut builder;
    builder.append("import source wasmMod from \"");
    builder.append(specifier);
    builder.append("\";\n");

    // A module with global exports registers its instance exports under its
    // own namespace in `import.meta.wasmInstances`, so that an importing Wasm
    // module can link against the original `WebAssembly.Global` objects.
    if has_global_export {
      builder.append("import * as selfNs from \"");
      builder.append(specifier);
      builder.append("\";\n");
    }

    if !aggregated_imports.is_empty() {
      for (i, (_, import_info)) in aggregated_imports.iter().enumerate() {
        if import_info.has_global_import {
          builder.append("import * as import_ns_");
          builder.append(i);
          builder.append(" from \"");
          builder.append(&import_info.key_escaped);
          builder.append("\";\n");
        }
        builder.append("import { ");
        for (name_index, named_import) in
          import_info.named_imports.iter().enumerate()
        {
          if name_index > 0 {
            builder.append(", ");
          }
          builder.append('"');
          builder.append(&named_import.escaped_name);
          builder.append("\" as import_");
          builder.append(i);
          builder.append('_');
          builder.append(name_index);
        }
        builder.append(" } from \"");
        builder.append(&import_info.key_escaped);
        builder.append("\";\n");
      }

      // For global-typed imports, prefer the original `WebAssembly.Global`
      // from the dependency's instance when the dependency is itself a Wasm
      // module, so that mutable globals stay direct references between Wasm
      // modules. The JS binding only carries the unwrapped snapshot value.
      //
      // Limitation: for a circular Wasm<->Wasm mutable-global import the
      // dependency may not be evaluated yet when this `.get()` runs, so it
      // returns `undefined` and we fall back to the snapshot number, which
      // fails instantiation with a `LinkError`. Node.js has the same gap.
      for (i, (_, import_info)) in aggregated_imports.iter().enumerate() {
        if import_info.has_global_import {
          builder.append("const wasmExports_");
          builder.append(i);
          builder.append(" = import.meta.wasmInstances.get(import_ns_");
          builder.append(i);
          builder.append(");\n");
        }
      }

      builder.append("const importsObject = {\n");

      for (i, (_, import_info)) in aggregated_imports.iter().enumerate() {
        builder.append("  \"");
        builder.append(&import_info.key_escaped);
        builder.append("\": {\n");

        for (name_index, named_import) in
          import_info.named_imports.iter().enumerate()
        {
          builder.append("    \"");
          builder.append(&named_import.escaped_name);
          builder.append("\": ");
          if named_import.is_global {
            builder.append("wasmExports_");
            builder.append(i);
            builder.append(" === undefined ? import_");
            builder.append(i);
            builder.append('_');
            builder.append(name_index);
            builder.append(" : wasmExports_");
            builder.append(i);
            builder.append("[\"");
            builder.append(&named_import.escaped_name);
            builder.append("\"]");
          } else {
            builder.append("import_");
            builder.append(i);
            builder.append('_');
            builder.append(name_index);
          }
          builder.append(",\n");
        }

        builder.append("  },\n");
      }

      builder.append("};\n");

      builder.append("const modInstance = new import.meta.WasmInstance(wasmMod, importsObject);\n");
    } else {
      builder
        .append("const modInstance = new import.meta.WasmInstance(wasmMod);\n");
    }

    if has_global_export {
      // The generated source assumes `import.meta.wasmInstances` is present
      // whenever a module uses globals. The map shares `import.meta.WasmInstance`'s
      // lifecycle: both are absent only when WebAssembly is unavailable or during
      // snapshotting, where the `new import.meta.WasmInstance(...)` call above
      // would already have thrown. So if we reach here, the map exists.
      builder.append(
        "import.meta.wasmInstances.set(selfNs, modInstance.exports);\n",
      );
      builder.append(WASM_GLOBAL_UNWRAP_HELPER);
    }

    for (idx, (escaped_name, is_global)) in exports.iter().enumerate() {
      if escaped_name == "default" {
        builder.append("export default ");
        if *is_global {
          builder.append("unwrapWasmGlobal(modInstance.exports.");
          builder.append(escaped_name);
          builder.append(")");
        } else {
          builder.append("modInstance.exports.");
          builder.append(escaped_name);
        }
        builder.append(";\n");
      } else {
        builder.append("const export");
        builder.append(idx);
        builder.append(" = ");
        if *is_global {
          builder.append("unwrapWasmGlobal(modInstance.exports[\"");
          builder.append(escaped_name);
          builder.append("\"])");
        } else {
          builder.append("modInstance.exports[\"");
          builder.append(escaped_name);
          builder.append("\"]");
        }
        builder.append(";\nexport { export");
        builder.append(idx);
        builder.append(" as \"");
        builder.append(escaped_name);
        builder.append("\" };\n");
      }
    }
  }
  builder.build()
}

#[test]
fn test_render_js_wasm_module() {
  let deps = WasmDeps {
    imports: vec![],
    exports: vec![],
  };
  let rendered = render_js_wasm_module("./foo.wasm", deps);
  pretty_assertions::assert_eq!(
    rendered,
    r#"import source wasmMod from "./foo.wasm";
const modInstance = new import.meta.WasmInstance(wasmMod);
"#,
  );

  let deps = WasmDeps {
    imports: vec![
      wasm_dep_analyzer::Import {
        name: "foo",
        module: "./import.js",
        import_type: wasm_dep_analyzer::ImportType::Tag(
          wasm_dep_analyzer::TagType {
            kind: 1,
            type_index: 1,
          },
        ),
      },
      wasm_dep_analyzer::Import {
        name: "bar",
        module: "./import.js",
        import_type: wasm_dep_analyzer::ImportType::Function(1),
      },
      wasm_dep_analyzer::Import {
        name: "fizz",
        module: "./import.js",
        import_type: wasm_dep_analyzer::ImportType::Function(2),
      },
      wasm_dep_analyzer::Import {
        name: "buzz",
        module: "./buzz.js",
        import_type: wasm_dep_analyzer::ImportType::Function(3),
      },
    ],
    exports: vec![
      wasm_dep_analyzer::Export {
        name: "export1",
        index: 0,
        export_type: wasm_dep_analyzer::ExportType::Function(Ok(
          wasm_dep_analyzer::FunctionSignature {
            params: vec![],
            returns: vec![],
          },
        )),
      },
      wasm_dep_analyzer::Export {
        name: "export2",
        index: 1,
        export_type: wasm_dep_analyzer::ExportType::Table,
      },
      wasm_dep_analyzer::Export {
        name: "export3",
        index: 2,
        export_type: wasm_dep_analyzer::ExportType::Memory,
      },
      wasm_dep_analyzer::Export {
        name: "export4",
        index: 3,
        export_type: wasm_dep_analyzer::ExportType::Global(Ok(
          wasm_dep_analyzer::GlobalType {
            value_type: wasm_dep_analyzer::ValueType::F32,
            mutability: false,
          },
        )),
      },
      wasm_dep_analyzer::Export {
        name: "export5",
        index: 4,
        export_type: wasm_dep_analyzer::ExportType::Tag,
      },
      wasm_dep_analyzer::Export {
        name: "export6",
        index: 5,
        export_type: wasm_dep_analyzer::ExportType::Unknown,
      },
      wasm_dep_analyzer::Export {
        name: "default",
        index: 6,
        export_type: wasm_dep_analyzer::ExportType::Function(Ok(
          wasm_dep_analyzer::FunctionSignature {
            params: vec![],
            returns: vec![],
          },
        )),
      },
    ],
  };
  let rendered = render_js_wasm_module("./foo.wasm", deps);
  pretty_assertions::assert_eq!(
    rendered,
    r#"import source wasmMod from "./foo.wasm";
import * as selfNs from "./foo.wasm";
import { "foo" as import_0_0, "bar" as import_0_1, "fizz" as import_0_2 } from "./import.js";
import { "buzz" as import_1_0 } from "./buzz.js";
const importsObject = {
  "./import.js": {
    "foo": import_0_0,
    "bar": import_0_1,
    "fizz": import_0_2,
  },
  "./buzz.js": {
    "buzz": import_1_0,
  },
};
const modInstance = new import.meta.WasmInstance(wasmMod, importsObject);
import.meta.wasmInstances.set(selfNs, modInstance.exports);
const unwrapWasmGlobal = (g) => { try { return g.value; } catch { return g; } };
const export0 = modInstance.exports["export1"];
export { export0 as "export1" };
const export1 = modInstance.exports["export2"];
export { export1 as "export2" };
const export2 = modInstance.exports["export3"];
export { export2 as "export3" };
const export3 = unwrapWasmGlobal(modInstance.exports["export4"]);
export { export3 as "export4" };
const export4 = modInstance.exports["export5"];
export { export4 as "export5" };
const export5 = modInstance.exports["export6"];
export { export5 as "export6" };
export default modInstance.exports.default;
"#,
  );

  let deps = WasmDeps {
    imports: vec![wasm_dep_analyzer::Import {
      name: "\n",
      module: "\n",
      import_type: wasm_dep_analyzer::ImportType::Function(1),
    }],
    exports: vec![wasm_dep_analyzer::Export {
      name: "\n",
      index: 0,
      export_type: wasm_dep_analyzer::ExportType::Function(Ok(
        wasm_dep_analyzer::FunctionSignature {
          params: vec![],
          returns: vec![],
        },
      )),
    }],
  };
  let rendered = render_js_wasm_module("./bar.wasm", deps);
  pretty_assertions::assert_eq!(
    rendered,
    r#"import source wasmMod from "./bar.wasm";
import { "\n" as import_0_0 } from "\n";
const importsObject = {
  "\n": {
    "\n": import_0_0,
  },
};
const modInstance = new import.meta.WasmInstance(wasmMod, importsObject);
const export0 = modInstance.exports["\n"];
export { export0 as "\n" };
"#,
  );
}

#[test]
fn test_render_js_wasm_module_global_unwrap() {
  fn global(
    value_type: wasm_dep_analyzer::ValueType,
    mutability: bool,
  ) -> wasm_dep_analyzer::ExportType {
    wasm_dep_analyzer::ExportType::Global(Ok(wasm_dep_analyzer::GlobalType {
      value_type,
      mutability,
    }))
  }

  let deps = WasmDeps {
    imports: vec![],
    exports: vec![
      // immutable numeric global -> unwrapped to its value at runtime
      wasm_dep_analyzer::Export {
        name: "answer",
        index: 0,
        export_type: global(wasm_dep_analyzer::ValueType::I32, false),
      },
      // mutable numeric global -> still unwrapped (snapshot at instantiation)
      wasm_dep_analyzer::Export {
        name: "counter",
        index: 1,
        export_type: global(wasm_dep_analyzer::ValueType::I64, true),
      },
      // unresolved value type (e.g. v128 / reference type) is still a global
      // by kind, so it is wrapped; the helper falls back to the
      // WebAssembly.Global object if reading `.value` throws (v128).
      wasm_dep_analyzer::Export {
        name: "vec",
        index: 2,
        export_type: global(wasm_dep_analyzer::ValueType::Unknown, false),
      },
      // global whose value type failed to parse -> still wrapped by kind
      wasm_dep_analyzer::Export {
        name: "broken",
        index: 3,
        export_type: wasm_dep_analyzer::ExportType::Global(Err(
          wasm_dep_analyzer::ParseError::UnresolvedExportType,
        )),
      },
      // non-global export is left untouched
      wasm_dep_analyzer::Export {
        name: "fn_export",
        index: 4,
        export_type: wasm_dep_analyzer::ExportType::Function(Ok(
          wasm_dep_analyzer::FunctionSignature {
            params: vec![],
            returns: vec![],
          },
        )),
      },
      // default export that is a global -> unwrapped
      wasm_dep_analyzer::Export {
        name: "default",
        index: 5,
        export_type: global(wasm_dep_analyzer::ValueType::F64, false),
      },
    ],
  };
  let rendered = render_js_wasm_module("./globals.wasm", deps);
  pretty_assertions::assert_eq!(
    rendered,
    r#"import source wasmMod from "./globals.wasm";
import * as selfNs from "./globals.wasm";
const modInstance = new import.meta.WasmInstance(wasmMod);
import.meta.wasmInstances.set(selfNs, modInstance.exports);
const unwrapWasmGlobal = (g) => { try { return g.value; } catch { return g; } };
const export0 = unwrapWasmGlobal(modInstance.exports["answer"]);
export { export0 as "answer" };
const export1 = unwrapWasmGlobal(modInstance.exports["counter"]);
export { export1 as "counter" };
const export2 = unwrapWasmGlobal(modInstance.exports["vec"]);
export { export2 as "vec" };
const export3 = unwrapWasmGlobal(modInstance.exports["broken"]);
export { export3 as "broken" };
const export4 = modInstance.exports["fn_export"];
export { export4 as "fn_export" };
export default unwrapWasmGlobal(modInstance.exports.default);
"#,
  );
}

#[test]
fn test_render_js_wasm_module_global_import() {
  let deps = WasmDeps {
    imports: vec![
      // global-typed import -> linked against the original
      // `WebAssembly.Global` when the dependency is itself a Wasm module
      // (found in `import.meta.wasmInstances`), falling back to the JS
      // binding otherwise
      wasm_dep_analyzer::Import {
        name: "counter",
        module: "./dep.wasm",
        import_type: wasm_dep_analyzer::ImportType::Global(
          wasm_dep_analyzer::GlobalType {
            value_type: wasm_dep_analyzer::ValueType::I32,
            mutability: true,
          },
        ),
      },
      // non-global import from the same module is untouched
      wasm_dep_analyzer::Import {
        name: "bump",
        module: "./dep.wasm",
        import_type: wasm_dep_analyzer::ImportType::Function(0),
      },
      // module with no global imports gets no namespace import or lookup
      wasm_dep_analyzer::Import {
        name: "log",
        module: "./util.js",
        import_type: wasm_dep_analyzer::ImportType::Function(1),
      },
    ],
    exports: vec![wasm_dep_analyzer::Export {
      name: "read",
      index: 0,
      export_type: wasm_dep_analyzer::ExportType::Function(Ok(
        wasm_dep_analyzer::FunctionSignature {
          params: vec![],
          returns: vec![wasm_dep_analyzer::ValueType::I32],
        },
      )),
    }],
  };
  let rendered = render_js_wasm_module("./main.wasm", deps);
  pretty_assertions::assert_eq!(
    rendered,
    r#"import source wasmMod from "./main.wasm";
import * as import_ns_0 from "./dep.wasm";
import { "counter" as import_0_0, "bump" as import_0_1 } from "./dep.wasm";
import { "log" as import_1_0 } from "./util.js";
const wasmExports_0 = import.meta.wasmInstances.get(import_ns_0);
const importsObject = {
  "./dep.wasm": {
    "counter": wasmExports_0 === undefined ? import_0_0 : wasmExports_0["counter"],
    "bump": import_0_1,
  },
  "./util.js": {
    "log": import_1_0,
  },
};
const modInstance = new import.meta.WasmInstance(wasmMod, importsObject);
const export0 = modInstance.exports["read"];
export { export0 as "read" };
"#,
  );
}