MCPcopy
hub / github.com/webpack/webpack / parseRequireCall

Function parseRequireCall

lib/dependencies/CommonJsExportsParserPlugin.js:153–181  ·  view source on GitHub ↗
(parser, expr)

Source from the content-addressed store, hash-verified

151 * @returns {{ argument: BasicEvaluatedExpression, ids: ExportInfoName[] } | undefined} parsed call
152 */
153const parseRequireCall = (parser, expr) => {
154 /** @type {ExportInfoName[]} */
155 const ids = [];
156 while (expr.type === "MemberExpression") {
157 if (expr.object.type === "Super") return;
158 if (!expr.property) return;
159 const prop = expr.property;
160 if (expr.computed) {
161 if (prop.type !== "Literal") return;
162 ids.push(`${prop.value}`);
163 } else {
164 if (prop.type !== "Identifier") return;
165 ids.push(prop.name);
166 }
167 expr = expr.object;
168 }
169 if (expr.type !== "CallExpression" || expr.arguments.length !== 1) return;
170 const callee = expr.callee;
171 if (
172 callee.type !== "Identifier" ||
173 parser.getVariableInfo(callee.name) !== "require"
174 ) {
175 return;
176 }
177 const arg = expr.arguments[0];
178 if (arg.type === "SpreadElement") return;
179 const argValue = parser.evaluateExpression(arg);
180 return { argument: argValue, ids: ids.reverse() };
181};
182
183/**
184 * Checks if a value is an AST node.

Callers 2

handleAssignExportMethod · 0.85
applyMethod · 0.85

Calls 3

getVariableInfoMethod · 0.80
evaluateExpressionMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected