MCPcopy
hub / github.com/webpack/webpack / processImportOrExport

Method processImportOrExport

lib/css/CssParser.js:1406–1474  ·  view source on GitHub ↗
(type, second, rule)

Source from the content-addressed store, hash-verified

1404 * @returns {number} position after parse
1405 */
1406 const processImportOrExport = (type, second, rule) => {
1407 /** @type {string | undefined} */
1408 let request;
1409 if (type === 0) {
1410 const parsed = parseIcssImportRequest(second, rule, source);
1411 if ("errorPos" in parsed) {
1412 const { errorPos } = parsed;
1413 this._emitWarning(
1414 state,
1415 `Unexpected '${source[errorPos]}' at ${errorPos} during parsing of ':import' (expected string)`,
1416 locConverter,
1417 errorPos,
1418 errorPos
1419 );
1420 return errorPos;
1421 }
1422 request = parsed.request;
1423 }
1424
1425 /**
1426 * Creates a dep from the provided name.
1427 * @param {string} name name
1428 * @param {string} value value
1429 * @param {number} start start of position
1430 * @param {number} end end of position
1431 */
1432 const createDep = (name, value, start, end) => {
1433 if (type === 0) {
1434 const dep = new CssIcssImportDependency(
1435 /** @type {string} */
1436 (request),
1437 [0, 0],
1438 /** @type {"local" | "global"} */
1439 (mode),
1440 value,
1441 name
1442 );
1443 setDepLoc(dep, start, end);
1444 module.addDependency(dep);
1445
1446 icssDefinitions.set(name, {
1447 importName: value,
1448 request: /** @type {string} */ (request)
1449 });
1450 } else if (type === 1) {
1451 const { line: sl, column: sc } = locConverter.get(start);
1452 const { line: el, column: ec } = locConverter.get(end);
1453 addCssExport(sl, sc, el, ec, name, getReexport(value));
1454 }
1455 };
1456
1457 // Body `{ name: value; … }` is parsed eagerly (§5.4.4) — emit a dep per declaration.
1458 const ruleDecls = A.declarations(rule);
1459 if (!ruleDecls || A.blockStart(rule) === -1) return A.end(second);
1460 for (const decl of ruleDecls) {
1461 const vals = A.children(decl);
1462 if (vals.length === 0) continue;
1463 const rawStart = A.start(vals[0]);

Callers

nothing calls this directly

Calls 4

_emitWarningMethod · 0.95
parseIcssImportRequestFunction · 0.85
skipWhiteLineFunction · 0.85
sliceMethod · 0.80

Tested by

no test coverage detected