1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const makeSerializable = require("../util/makeSerializable");
|
9 | const UnsupportedWebAssemblyFeatureError = require("../wasm-sync/UnsupportedWebAssemblyFeatureError");
|
10 | const ModuleDependency = require("./ModuleDependency");
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | class WebAssemblyImportDependency extends ModuleDependency {
|
19 | |
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | constructor(request, name, description, onlyDirectImport) {
|
26 | super(request);
|
27 |
|
28 | this.name = name;
|
29 |
|
30 | this.description = description;
|
31 |
|
32 | this.onlyDirectImport = onlyDirectImport;
|
33 | }
|
34 |
|
35 | get type() {
|
36 | return "wasm import";
|
37 | }
|
38 |
|
39 | get category() {
|
40 | return "wasm";
|
41 | }
|
42 |
|
43 | |
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | getReferencedExports(moduleGraph, runtime) {
|
50 | return [[this.name]];
|
51 | }
|
52 |
|
53 | |
54 |
|
55 |
|
56 |
|
57 |
|
58 | getErrors(moduleGraph) {
|
59 | const module = moduleGraph.getModule(this);
|
60 |
|
61 | if (
|
62 | this.onlyDirectImport &&
|
63 | module &&
|
64 | !module.type.startsWith("webassembly")
|
65 | ) {
|
66 | return [
|
67 | new UnsupportedWebAssemblyFeatureError(
|
68 | `Import "${this.name}" from "${this.request}" with ${this.onlyDirectImport} can only be used for direct wasm to wasm dependencies`
|
69 | )
|
70 | ];
|
71 | }
|
72 | }
|
73 |
|
74 | serialize(context) {
|
75 | const { write } = context;
|
76 |
|
77 | write(this.name);
|
78 | write(this.description);
|
79 | write(this.onlyDirectImport);
|
80 |
|
81 | super.serialize(context);
|
82 | }
|
83 |
|
84 | deserialize(context) {
|
85 | const { read } = context;
|
86 |
|
87 | this.name = read();
|
88 | this.description = read();
|
89 | this.onlyDirectImport = read();
|
90 |
|
91 | super.deserialize(context);
|
92 | }
|
93 | }
|
94 |
|
95 | makeSerializable(
|
96 | WebAssemblyImportDependency,
|
97 | "webpack/lib/dependencies/WebAssemblyImportDependency"
|
98 | );
|
99 |
|
100 | module.exports = WebAssemblyImportDependency;
|