MCPcopy
hub / github.com/webpack/webpack / handleImportAtRule

Method handleImportAtRule

lib/css/CssParser.js:2616–2813  ·  view source on GitHub ↗
(at, topLevel)

Source from the content-addressed store, hash-verified

2614 * @param {boolean} topLevel whether the rule is at the stylesheet top level
2615 */
2616 const handleImportAtRule = (at, topLevel) => {
2617 if (!this.options.import) return;
2618 if (!topLevel || !allowImport) {
2619 this._emitWarning(
2620 state,
2621 "Any '@import' rules must precede all other rules",
2622 locConverter,
2623 A.start(at),
2624 A.nameEnd(at)
2625 );
2626 return;
2627 }
2628 const importStart = A.start(at);
2629 const importNameEnd = A.nameEnd(at);
2630 // We only accept `;`-terminated @import; block / EOF / `}` ends are silent bails.
2631 if (source.charCodeAt(A.end(at)) !== CC_SEMICOLON) return;
2632
2633 // Walk the prelude in spec order (URL → layer? → supports? → media query); anything else joins the media query.
2634 const { urlNode, layerNode, supportsNode } = parseImportPrelude(
2635 A.prelude(at)
2636 );
2637
2638 const semi = A.end(at) + 1; // position past `;`
2639
2640 if (!urlNode || (A.type(urlNode) === NodeType.Ident && !isModules)) {
2641 this._emitWarning(
2642 state,
2643 `Expected URL in '${input.slice(importStart, semi)}'`,
2644 locConverter,
2645 importStart,
2646 semi
2647 );
2648 // A malformed `@import` still emits orphan url() deps from its prelude — flag it so the value visitors enable url().
2649 currentUrlRecovery = true;
2650 return;
2651 }
2652
2653 /** @type {string} */
2654 let url;
2655 if (A.type(urlNode) === NodeType.Ident) {
2656 // URL given as identifier — resolve via CSS Modules `@value`.
2657 const identName = A.value(urlNode);
2658 const def = icssDefinitions.get(identName);
2659 if (!def) {
2660 this._emitWarning(
2661 state,
2662 `Unknown '@value' identifier '${identName}' in '${input.slice(
2663 importStart,
2664 semi
2665 )}'`,
2666 locConverter,
2667 importStart,
2668 semi
2669 );
2670 // Drop the whole at-rule so the unresolved identifier isn't substituted into the output.
2671 const dep = new ConstDependency("", [importStart, semi]);
2672 module.addPresentationalDependency(dep);
2673 return;

Callers

nothing calls this directly

Calls 14

_emitWarningMethod · 0.95
parseImportPreludeFunction · 0.85
normalizeUrlFunction · 0.85
skipWhiteLineFunction · 0.85
nextNonWhitespaceFunction · 0.85
sliceMethod · 0.80
addDependencyMethod · 0.65
typeMethod · 0.45
valueMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected