* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}
(compiler)
| 138 | * @returns {void} |
| 139 | */ |
| 140 | apply(compiler) { |
| 141 | let cache = globToRegexpCache.get(compiler.root); |
| 142 | if (cache === undefined) { |
| 143 | cache = new Map(); |
| 144 | globToRegexpCache.set(compiler.root, cache); |
| 145 | } |
| 146 | compiler.hooks.compilation.tap( |
| 147 | PLUGIN_NAME, |
| 148 | (compilation, { normalModuleFactory }) => { |
| 149 | const moduleGraph = compilation.moduleGraph; |
| 150 | normalModuleFactory.hooks.module.tap(PLUGIN_NAME, (module, data) => { |
| 151 | const resolveData = data.resourceResolveData; |
| 152 | if ( |
| 153 | resolveData && |
| 154 | resolveData.descriptionFileData && |
| 155 | resolveData.relativePath |
| 156 | ) { |
| 157 | const sideEffects = resolveData.descriptionFileData.sideEffects; |
| 158 | if (sideEffects !== undefined) { |
| 159 | if (module.factoryMeta === undefined) { |
| 160 | module.factoryMeta = {}; |
| 161 | } |
| 162 | const hasSideEffects = SideEffectsFlagPlugin.moduleHasSideEffects( |
| 163 | resolveData.relativePath, |
| 164 | /** @type {SideEffectsFlagValue} */ (sideEffects), |
| 165 | /** @type {CacheItem} */ (cache) |
| 166 | ); |
| 167 | module.factoryMeta.sideEffectFree = !hasSideEffects; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | return module; |
| 172 | }); |
| 173 | normalModuleFactory.hooks.module.tap(PLUGIN_NAME, (module, data) => { |
| 174 | const settings = data.settings; |
| 175 | if (typeof settings.sideEffects === "boolean") { |
| 176 | if (module.factoryMeta === undefined) { |
| 177 | module.factoryMeta = {}; |
| 178 | } |
| 179 | module.factoryMeta.sideEffectFree = !settings.sideEffects; |
| 180 | } |
| 181 | return module; |
| 182 | }); |
| 183 | if (this._analyseSource) { |
| 184 | /** |
| 185 | * Processes the provided parser. |
| 186 | * @param {JavascriptParser} parser the parser |
| 187 | * @returns {void} |
| 188 | */ |
| 189 | const applySideEffectsStmtHandler = (parser) => { |
| 190 | /** @type {undefined | Statement | ModuleDeclaration | MaybeNamedFunctionDeclaration | MaybeNamedClassDeclaration} */ |
| 191 | let sideEffectsStatement; |
| 192 | parser.hooks.program.tap(PLUGIN_NAME, () => { |
| 193 | sideEffectsStatement = undefined; |
| 194 | }); |
| 195 | parser.hooks.statement.tap( |
| 196 | { name: PLUGIN_NAME, stage: -100 }, |
| 197 | (statement) => { |
nothing calls this directly
no test coverage detected