MCPcopy
hub / github.com/webpack/webpack / processRequireItem

Function processRequireItem

lib/dependencies/CommonJsImportsParserPlugin.js:175–203  ·  view source on GitHub ↗
(expr, param)

Source from the content-addressed store, hash-verified

173 * @returns {boolean | void} true when handled
174 */
175 const processRequireItem = (expr, param) => {
176 if (param.isString()) {
177 let referencedExports = getRequireReferencedExportsFromDestructuring(
178 parser,
179 expr
180 );
181 const binding =
182 requireBindingData &&
183 requireBindingData.get(/** @type {CallExpression} */ (expr));
184 if (binding && !referencedExports) {
185 // `const NAME = require(LITERAL)` — let later member-access walks
186 // on `NAME` populate the dependency's referenced exports.
187 referencedExports = binding.referencedExports;
188 }
189 const dep = new CommonJsRequireDependency(
190 /** @type {string} */ (param.string),
191 /** @type {Range} */ (param.range),
192 getContext(),
193 referencedExports,
194 /** @type {Range} */ (expr.range)
195 );
196 if (binding) binding.dep = dep;
197 dep.loc = /** @type {DependencyLocation} */ (expr.loc);
198 dep.optional = Boolean(parser.scope.inTry);
199 parser.state.current.addDependency(dep);
200 getHarmonyImportGuard().attachDependencyGuards(parser, dep);
201 return true;
202 }
203 };
204 /**
205 * Process require context.
206 * @param {CallExpression | NewExpression} expr expression

Callers 1

createRequireCallHandlerFunction · 0.85

Calls 4

isStringMethod · 0.80
addDependencyMethod · 0.65
getMethod · 0.45

Tested by

no test coverage detected