1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 |
|
7 | const UnsupportedWebAssemblyFeatureError = require("./UnsupportedWebAssemblyFeatureError");
|
8 |
|
9 | class WasmFinalizeExportsPlugin {
|
10 | apply(compiler) {
|
11 | compiler.hooks.compilation.tap("WasmFinalizeExportsPlugin", compilation => {
|
12 | compilation.hooks.finishModules.tap(
|
13 | "WasmFinalizeExportsPlugin",
|
14 | modules => {
|
15 | for (const module of modules) {
|
16 |
|
17 | if (module.type.startsWith("webassembly") === true) {
|
18 | const jsIncompatibleExports =
|
19 | module.buildMeta.jsIncompatibleExports;
|
20 |
|
21 | if (jsIncompatibleExports === undefined) {
|
22 | continue;
|
23 | }
|
24 |
|
25 | for (const reason of module.reasons) {
|
26 |
|
27 | if (reason.module.type.startsWith("webassembly") === false) {
|
28 | const ref = compilation.getDependencyReference(
|
29 | reason.module,
|
30 | reason.dependency
|
31 | );
|
32 |
|
33 | if (!ref) continue;
|
34 |
|
35 | const importedNames = ref.importedNames;
|
36 |
|
37 | if (Array.isArray(importedNames)) {
|
38 | importedNames.forEach(name => {
|
39 |
|
40 | if (
|
41 | Object.prototype.hasOwnProperty.call(
|
42 | jsIncompatibleExports,
|
43 | name
|
44 | )
|
45 | ) {
|
46 |
|
47 |
|
48 | const error = new UnsupportedWebAssemblyFeatureError(
|
49 | `Export "${name}" with ${
|
50 | jsIncompatibleExports[name]
|
51 | } can only be used for direct wasm to wasm dependencies`
|
52 | );
|
53 | error.module = module;
|
54 | error.origin = reason.module;
|
55 | error.originLoc = reason.dependency.loc;
|
56 | error.dependencies = [reason.dependency];
|
57 | compilation.errors.push(error);
|
58 | }
|
59 | });
|
60 | }
|
61 | }
|
62 | }
|
63 | }
|
64 | }
|
65 | }
|
66 | );
|
67 | });
|
68 | }
|
69 | }
|
70 |
|
71 | module.exports = WasmFinalizeExportsPlugin;
|