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