| | |
| | | |
| | | class FlagDependencyUsagePlugin { |
| | | /** |
| | | * Creates an instance of FlagDependencyUsagePlugin. |
| | | * @param {boolean} global do a global analysis instead of per runtime |
| | | */ |
| | | constructor(global) { |
| | | /** @type {boolean} */ |
| | | this.global = global; |
| | | } |
| | | |
| | | /** |
| | | * Apply the plugin |
| | | * Applies the plugin by registering its hooks on the compiler. |
| | | * @param {Compiler} compiler the compiler instance |
| | | * @returns {void} |
| | | */ |
| | |
| | | const queue = new TupleQueue(); |
| | | |
| | | /** |
| | | * Process referenced module. |
| | | * @param {Module} module module to process |
| | | * @param {ReferencedExports} usedExports list of used exports |
| | | * @param {RuntimeSpec} runtime part of which runtime |
| | |
| | | return; |
| | | } |
| | | for (const usedExportInfo of usedExports) { |
| | | /** @type {string[]} */ |
| | | let usedExport; |
| | | let canMangle = true; |
| | | if (Array.isArray(usedExportInfo)) { |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Processes the provided module. |
| | | * @param {DependenciesBlock} module the module |
| | | * @param {RuntimeSpec} runtime part of which runtime |
| | | * @param {boolean} forceSideEffects always apply side effects |
| | | * @returns {void} |
| | | */ |
| | | const processModule = (module, runtime, forceSideEffects) => { |
| | | /** @type {Map<Module, ReferencedExports | Map<string, string[] | ReferencedExport>>} */ |
| | | /** @typedef {Map<string, string[] | ReferencedExport>} ExportMaps */ |
| | | /** @type {Map<Module, ReferencedExports | ExportMaps>} */ |
| | | const map = new Map(); |
| | | |
| | | /** @type {ArrayQueue<DependenciesBlock>} */ |
| | |
| | | const block = queue.dequeue(); |
| | | if (block === undefined) break; |
| | | for (const b of block.blocks) { |
| | | if ( |
| | | !this.global && |
| | | b.groupOptions && |
| | | b.groupOptions.entryOptions |
| | | ) { |
| | | if (b.groupOptions && b.groupOptions.entryOptions) { |
| | | processModule( |
| | | b, |
| | | b.groupOptions.entryOptions.runtime || undefined, |
| | | this.global |
| | | ? undefined |
| | | : b.groupOptions.entryOptions.runtime || undefined, |
| | | true |
| | | ); |
| | | } else { |
| | |
| | | ) { |
| | | continue; |
| | | } else { |
| | | /** @type {undefined | ExportMaps} */ |
| | | let exportsMap; |
| | | if (Array.isArray(oldReferencedExports)) { |
| | | exportsMap = new Map(); |
| | |
| | | logger.time("trace exports usage in graph"); |
| | | |
| | | /** |
| | | * Process entry dependency. |
| | | * @param {Dependency} dep dependency |
| | | * @param {RuntimeSpec} runtime runtime |
| | | */ |