source: frontend/node_modules/webpack/lib/wasm-sync/WebAssemblyUtils.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[9af201e]1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const Template = require("../Template");
9const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
10
11/** @typedef {import("../Module")} Module */
12/** @typedef {import("../ModuleGraph")} ModuleGraph */
13
14/**
15 * Defines the used wasm dependency type used by this module.
16 * @typedef {object} UsedWasmDependency
17 * @property {WebAssemblyImportDependency} dependency the dependency
18 * @property {string} name the export name
19 * @property {string} module the module name
20 */
21
22const MANGLED_MODULE = "a";
23
24/**
25 * Gets used dependencies.
26 * @param {ModuleGraph} moduleGraph the module graph
27 * @param {Module} module the module
28 * @param {boolean | undefined} mangle mangle module and export names
29 * @returns {UsedWasmDependency[]} used dependencies and (mangled) name
30 */
31const getUsedDependencies = (moduleGraph, module, mangle) => {
32 /** @type {UsedWasmDependency[]} */
33 const array = [];
34 let importIndex = 0;
35 for (const dep of module.dependencies) {
36 if (dep instanceof WebAssemblyImportDependency) {
37 if (
38 dep.description.type === "GlobalType" ||
39 moduleGraph.getModule(dep) === null
40 ) {
41 continue;
42 }
43
44 const exportName = dep.name;
45 // TODO add the following 3 lines when removing of ModuleExport is possible
46 // const importedModule = moduleGraph.getModule(dep);
47 // const usedName = importedModule && moduleGraph.getExportsInfo(importedModule).getUsedName(exportName, runtime);
48 // if (usedName !== false) {
49 if (mangle) {
50 array.push({
51 dependency: dep,
52 name: Template.numberToIdentifier(importIndex++),
53 module: MANGLED_MODULE
54 });
55 } else {
56 array.push({
57 dependency: dep,
58 name: exportName,
59 module: dep.request
60 });
61 }
62 }
63 }
64 return array;
65};
66
67module.exports.MANGLED_MODULE = MANGLED_MODULE;
68module.exports.getUsedDependencies = getUsedDependencies;
Note: See TracBrowser for help on using the repository browser.