123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- "use strict";
- const makeSerializable = require("../util/makeSerializable");
- const UnsupportedWebAssemblyFeatureError = require("../wasm-sync/UnsupportedWebAssemblyFeatureError");
- const ModuleDependency = require("./ModuleDependency");
- class WebAssemblyImportDependency extends ModuleDependency {
-
- constructor(request, name, description, onlyDirectImport) {
- super(request);
-
- this.name = name;
-
- this.description = description;
-
- this.onlyDirectImport = onlyDirectImport;
- }
- get type() {
- return "wasm import";
- }
- get category() {
- return "wasm";
- }
-
- getReferencedExports(moduleGraph, runtime) {
- return [[this.name]];
- }
-
- getErrors(moduleGraph) {
- const module = moduleGraph.getModule(this);
- if (
- this.onlyDirectImport &&
- module &&
- !module.type.startsWith("webassembly")
- ) {
- return [
- new UnsupportedWebAssemblyFeatureError(
- `Import "${this.name}" from "${this.request}" with ${this.onlyDirectImport} can only be used for direct wasm to wasm dependencies`
- )
- ];
- }
- }
-
- serialize(context) {
- const { write } = context;
- write(this.name);
- write(this.description);
- write(this.onlyDirectImport);
- super.serialize(context);
- }
-
- deserialize(context) {
- const { read } = context;
- this.name = read();
- this.description = read();
- this.onlyDirectImport = read();
- super.deserialize(context);
- }
- }
- makeSerializable(
- WebAssemblyImportDependency,
- "webpack/lib/dependencies/WebAssemblyImportDependency"
- );
- module.exports = WebAssemblyImportDependency;
|