MCPcopy
hub / github.com/webpack/webpack / handler

Method handler

lib/APIPlugin.js:215–382  ·  lib/APIPlugin.js::APIPlugin.handler
(parser)

Source from the content-addressed store, hash-verified

213 * @param {JavascriptParser} parser the parser
214 */
215 const handler = (parser) => {
216 parser.hooks.preDeclarator.tap(PLUGIN_NAME, (declarator) => {
217 if (
218 parser.scope.topLevelScope === true &&
219 declarator.id.type === class="st">"Identifier" &&
220 declarator.id.name === class="st">"module"
221 ) {
222 /** @type {BuildInfo} */
223 (parser.state.module.buildInfo).moduleArgument =
224 class="st">"__webpack_module__";
225 }
226 });
227
228 parser.hooks.preStatement.tap(PLUGIN_NAME, (statement) => {
229 if (parser.scope.topLevelScope === true) {
230 if (
231 statement.type === class="st">"FunctionDeclaration" &&
232 statement.id &&
233 statement.id.name === class="st">"module"
234 ) {
235 /** @type {BuildInfo} */
236 (parser.state.module.buildInfo).moduleArgument =
237 class="st">"__webpack_module__";
238 } else if (
239 statement.type === class="st">"ClassDeclaration" &&
240 statement.id &&
241 statement.id.name === class="st">"module"
242 ) {
243 /** @type {BuildInfo} */
244 (parser.state.module.buildInfo).moduleArgument =
245 class="st">"__webpack_module__";
246 }
247 }
248 });
249
250 for (const key of Object.keys(REPLACEMENTS)) {
251 const info = REPLACEMENTS[key];
252 parser.hooks.expression.for(key).tap(PLUGIN_NAME, (expression) => {
253 const dep = toConstantDependency(parser, info.expr, info.req);
254
255 if (key === class="st">"__non_webpack_require__" && moduleOutput) {
256 if (nodeTarget) {
257 /** @type {JavascriptModuleBuildInfo} */
258 (parser.state.module.buildInfo).needCreateRequire = true;
259 } else {
260 const warning = new WebpackError(
261 `${PLUGIN_NAME}\n__non_webpack_require__ is only allowed in target node`
262 );
263 warning.loc = /** @type {DependencyLocation} */ (
264 expression.loc
265 );
266 warning.module = parser.state.module;
267 compilation.warnings.push(warning);
268 }
269 }
270
271 return dep(expression);
272 });

Callers 3

handleErrorMethod · 0.45
_doneMethod · 0.45
watchMethod · 0.45

Calls 8

tapMethod · 0.80
setRangeMethod · 0.80
setNullMethod · 0.80
setStringMethod · 0.80
keysMethod · 0.65
depFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected