MCPcopy Create free account
hub / github.com/webpack/css-loader / parseDeclaration

Function parseDeclaration

src/plugins/postcss-url-parser.js:62–289  ·  view source on GitHub ↗
(declaration, key, result, options)

Source from the content-addressed store, hash-verified

60}
61
62function parseDeclaration(declaration, key, result, options) {
63 if (!needParseDeclaration.test(declaration[key])) {
64 return;
65 }
66
67 const parsed = valueParser(
68 declaration.raws && declaration.raws.value && declaration.raws.value.raw
69 ? declaration.raws.value.raw
70 : declaration[key],
71 );
72
73 let inBetween;
74
75 if (declaration.raws && declaration.raws.between) {
76 const lastCommentIndex = declaration.raws.between.lastIndexOf("/*");
77
78 const matched = declaration.raws.between
79 .slice(lastCommentIndex)
80 .match(WEBPACK_IGNORE_COMMENT_REGEXP);
81
82 if (matched) {
83 inBetween = matched[2] === "true";
84 }
85 }
86
87 let isIgnoreOnDeclaration = false;
88
89 const prevNode = declaration.prev();
90
91 if (prevNode && prevNode.type === "comment") {
92 const matched = prevNode.text.match(WEBPACK_IGNORE_COMMENT_REGEXP);
93
94 if (matched) {
95 isIgnoreOnDeclaration = matched[2] === "true";
96 }
97 }
98
99 let needIgnore;
100
101 const parsedURLs = [];
102
103 parsed.walk((valueNode, index, valueNodes) => {
104 if (valueNode.type !== "function") {
105 return;
106 }
107
108 if (isUrlFunc.test(valueNode.value)) {
109 needIgnore = getWebpackIgnoreCommentValue(index, valueNodes, inBetween);
110
111 if (
112 (isIgnoreOnDeclaration && typeof needIgnore === "undefined") ||
113 needIgnore
114 ) {
115 if (needIgnore) {
116 // eslint-disable-next-line no-undefined
117 needIgnore = undefined;
118 }
119

Callers 1

DeclarationFunction · 0.85

Calls 4

normalizeUrlFunction · 0.90
shouldHandleURLFunction · 0.85
getNodeFromUrlFuncFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…