MCPcopy Index your code
hub / github.com/webpack/css-loader / parseNode

Function parseNode

src/plugins/postcss-import-parser.js:44–194  ·  view source on GitHub ↗
(atRule, key, options)

Source from the content-addressed store, hash-verified

42}
43
44function parseNode(atRule, key, options) {
45 // Convert only top-level @import
46 if (atRule.parent.type !== "root") {
47 return;
48 }
49
50 const isIgnored = isIgnoredAfterName(atRule) || isIgnoredPrevNode(atRule);
51
52 // Nodes do not exists - `@import url('http://') :root {}`
53 if (atRule.nodes) {
54 const error = new Error(
55 "It looks like you didn't end your @import statement correctly. Child nodes are attached to it.",
56 );
57
58 error.node = atRule;
59
60 throw error;
61 }
62
63 const rawParams =
64 atRule.raws &&
65 atRule.raws[key] &&
66 typeof atRule.raws[key].raw !== "undefined"
67 ? atRule.raws[key].raw
68 : atRule[key];
69 const { nodes: paramsNodes } = valueParser(rawParams);
70
71 // No nodes - `@import ;`
72 // Invalid type - `@import foo-bar;`
73 if (
74 paramsNodes.length === 0 ||
75 (paramsNodes[0].type !== "string" && paramsNodes[0].type !== "function")
76 ) {
77 const error = new Error(`Unable to find uri in "${atRule.toString()}"`);
78
79 error.node = atRule;
80
81 throw error;
82 }
83
84 let isStringValue;
85 let url;
86
87 if (paramsNodes[0].type === "string") {
88 isStringValue = true;
89 url = paramsNodes[0].value;
90 } else {
91 // Invalid function - `@import nourl(test.css);`
92 if (paramsNodes[0].value.toLowerCase() !== "url") {
93 const error = new Error(`Unable to find uri in "${atRule.toString()}"`);
94
95 error.node = atRule;
96
97 throw error;
98 }
99
100 isStringValue =
101 paramsNodes[0].nodes.length !== 0 &&

Callers 1

importFunction · 0.85

Calls 4

normalizeUrlFunction · 0.90
isURLRequestableFunction · 0.90
isIgnoredAfterNameFunction · 0.85
isIgnoredPrevNodeFunction · 0.85

Tested by

no test coverage detected