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

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[79a0317]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 * @typedef {object} UsedWasmDependency
16 * @property {WebAssemblyImportDependency} dependency the dependency
17 * @property {string} name the export name
18 * @property {string} module the module name
19 */
20
21const MANGLED_MODULE = "a";
22
23/**
24 * @param {ModuleGraph} moduleGraph the module graph
25 * @param {Module} module the module
26 * @param {boolean | undefined} mangle mangle module and export names
27 * @returns {UsedWasmDependency[]} used dependencies and (mangled) name
28 */
29const getUsedDependencies = (moduleGraph, module, mangle) => {
30 /** @type {UsedWasmDependency[]} */
31 const array = [];
32 let importIndex = 0;
33 for (const dep of module.dependencies) {
34 if (dep instanceof WebAssemblyImportDependency) {
35 if (
36 dep.description.type === "GlobalType" ||
37 moduleGraph.getModule(dep) === null
38 ) {
39 continue;
40 }
41
42 const exportName = dep.name;
43 // TODO add the following 3 lines when removing of ModuleExport is possible
44 // const importedModule = moduleGraph.getModule(dep);
45 // const usedName = importedModule && moduleGraph.getExportsInfo(importedModule).getUsedName(exportName, runtime);
46 // if (usedName !== false) {
47 if (mangle) {
48 array.push({
49 dependency: dep,
50 name: Template.numberToIdentifier(importIndex++),
51 module: MANGLED_MODULE
52 });
53 } else {
54 array.push({
55 dependency: dep,
56 name: exportName,
57 module: dep.request
58 });
59 }
60 }
61 }
62 return array;
63};
64
65module.exports.getUsedDependencies = getUsedDependencies;
66module.exports.MANGLED_MODULE = MANGLED_MODULE;
Note: See TracBrowser for help on using the repository browser.