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

Method handler

lib/DefinePlugin.js:430–850  ·  lib/DefinePlugin.js::DefinePlugin.handler
(parser)

Source from the content-addressed store, hash-verified

428 * @returns {void}
429 */
430 const handler = (parser) => {
431 /** @type {Set<string>} */
432 const hooked = new Set();
433 const mainValue =
434 /** @type {ValueCacheVersion} */
435 (compilation.valueCacheVersions.get(VALUE_DEP_MAIN));
436 parser.hooks.program.tap(PLUGIN_NAME, () => {
437 const buildInfo = /** @type {NormalModuleBuildInfo} */ (
438 parser.state.module.buildInfo
439 );
440 if (!buildInfo.valueDependencies) {
441 buildInfo.valueDependencies = new Map();
442 }
443 buildInfo.valueDependencies.set(VALUE_DEP_MAIN, mainValue);
444 });
445
446 /**
447 * Adds value dependency.
448 * @param {string} key key
449 */
450 const addValueDependency = (key) => {
451 const buildInfo =
452 /** @type {NormalModuleBuildInfo} */
453 (parser.state.module.buildInfo);
454 /** @type {NonNullable<NormalModuleBuildInfo[class="st">"valueDependencies"]>} */
455 (buildInfo.valueDependencies).set(
456 VALUE_DEP_PREFIX + key,
457 /** @type {ValueCacheVersion} */
458 (compilation.valueCacheVersions.get(VALUE_DEP_PREFIX + key))
459 );
460 };
461
462 /**
463 * With value dependency.
464 * @template T
465 * @param {string} key key
466 * @param {(expression: Expression) => T} fn fn
467 * @returns {(expression: Expression) => T} result
468 */
469 const withValueDependency =
470 (key, fn) =>
471 (...args) => {
472 addValueDependency(key);
473 return fn(...args);
474 };
475
476 /**
477 * Processes the provided definition.
478 * @param {Definitions} definitions Definitions map
479 * @param {string} prefix Prefix string
480 * @returns {void}
481 */
482 const walkDefinitions = (definitions, prefix) => {
483 for (const key of Object.keys(definitions)) {
484 const code = definitions[key];
485 if (isObjectDefinition(code)) {
486 walkDefinitions(
487 /** @type {Definitions} */ (code),

Callers

nothing calls this directly

Calls 3

tapMethod · 0.80
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected