[79a0317] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | Author Tobias Koppers @sokra
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | "use strict";
|
---|
| 7 |
|
---|
| 8 | const Template = require("../Template");
|
---|
| 9 | const 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 |
|
---|
| 21 | const 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 | */
|
---|
| 29 | const 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 |
|
---|
| 65 | module.exports.getUsedDependencies = getUsedDependencies;
|
---|
| 66 | module.exports.MANGLED_MODULE = MANGLED_MODULE;
|
---|