source: trip-planner-front/node_modules/webpack/lib/dependencies/WebAssemblyImportDependency.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const makeSerializable = require("../util/makeSerializable");
9const UnsupportedWebAssemblyFeatureError = require("../wasm-sync/UnsupportedWebAssemblyFeatureError");
10const ModuleDependency = require("./ModuleDependency");
11
12/** @typedef {import("@webassemblyjs/ast").ModuleImportDescription} ModuleImportDescription */
13/** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
14/** @typedef {import("../ModuleGraph")} ModuleGraph */
15/** @typedef {import("../WebpackError")} WebpackError */
16/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
17
18class WebAssemblyImportDependency extends ModuleDependency {
19 /**
20 * @param {string} request the request
21 * @param {string} name the imported name
22 * @param {ModuleImportDescription} description the WASM ast node
23 * @param {false | string} onlyDirectImport if only direct imports are allowed
24 */
25 constructor(request, name, description, onlyDirectImport) {
26 super(request);
27 /** @type {string} */
28 this.name = name;
29 /** @type {ModuleImportDescription} */
30 this.description = description;
31 /** @type {false | string} */
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 * Returns list of exports referenced by this dependency
45 * @param {ModuleGraph} moduleGraph module graph
46 * @param {RuntimeSpec} runtime the runtime for which the module is analysed
47 * @returns {(string[] | ReferencedExport)[]} referenced exports
48 */
49 getReferencedExports(moduleGraph, runtime) {
50 return [[this.name]];
51 }
52
53 /**
54 * Returns errors
55 * @param {ModuleGraph} moduleGraph module graph
56 * @returns {WebpackError[]} errors
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
95makeSerializable(
96 WebAssemblyImportDependency,
97 "webpack/lib/dependencies/WebAssemblyImportDependency"
98);
99
100module.exports = WebAssemblyImportDependency;
Note: See TracBrowser for help on using the repository browser.