( parser, expressionName, fn, property, warning )
| 165 | * @returns {void} |
| 166 | */ |
| 167 | const setCachedModuleConstant = ( |
| 168 | parser, |
| 169 | expressionName, |
| 170 | fn, |
| 171 | property, |
| 172 | warning |
| 173 | ) => { |
| 174 | parser.hooks.expression |
| 175 | .for(expressionName) |
| 176 | .tap(PLUGIN_NAME, (expr) => { |
| 177 | const dep = new CachedConstDependency( |
| 178 | JSON.stringify(fn(parser.state.module)), |
| 179 | /** @type {Range} */ |
| 180 | (expr.range), |
| 181 | `__webpack_${property}__` |
| 182 | ); |
| 183 | dep.loc = /** @type {DependencyLocation} */ (expr.loc); |
| 184 | parser.state.module.addPresentationalDependency(dep); |
| 185 | |
| 186 | if (warning) { |
| 187 | parser.state.module.addWarning( |
| 188 | new NodeStuffInWebError(dep.loc, expressionName, warning) |
| 189 | ); |
| 190 | } |
| 191 | |
| 192 | return true; |
| 193 | }); |
| 194 | |
| 195 | if ( |
| 196 | expressionName === IMPORT_META_FILENAME || |
| 197 | expressionName === IMPORT_META_DIRNAME |
| 198 | ) { |
| 199 | hooks.propertyInDestructuring.tap(PLUGIN_NAME, (usingProperty) => { |
| 200 | if (property === usingProperty.id) { |
| 201 | if (warning) { |
| 202 | parser.state.module.addWarning( |
| 203 | new NodeStuffInWebError( |
| 204 | usingProperty.loc, |
| 205 | expressionName, |
| 206 | warning |
| 207 | ) |
| 208 | ); |
| 209 | } |
| 210 | |
| 211 | return `${property}: ${JSON.stringify( |
| 212 | fn(parser.state.module) |
| 213 | )},`; |
| 214 | } |
| 215 | }); |
| 216 | } |
| 217 | }; |
| 218 | |
| 219 | /** |
| 220 | * Updates constant using the provided parser. |
nothing calls this directly
no test coverage detected