Skip to content

Commit 9231684

Browse files
refactor: code
1 parent 27a19b5 commit 9231684

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/plugins/postcss-url-parser.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function getWebpackIgnoreCommentValue(index, nodes, inBetween) {
4848
return matched && matched[2] === "true";
4949
}
5050

51-
function shouldHandleURL(url, declaration, result, options) {
51+
function shouldHandleURL(url, declaration, result, isSupportDataURLInNewURL) {
5252
if (url.length === 0) {
5353
result.warn(`Unable to find uri in '${declaration.toString()}'`, {
5454
node: declaration,
@@ -57,7 +57,7 @@ function shouldHandleURL(url, declaration, result, options) {
5757
return false;
5858
}
5959

60-
if (isDataUrl(url) && options.isSupportDataURLInNewURL) {
60+
if (isDataUrl(url) && isSupportDataURLInNewURL) {
6161
try {
6262
decodeURIComponent(url);
6363
} catch (ignoreError) {
@@ -74,7 +74,7 @@ function shouldHandleURL(url, declaration, result, options) {
7474
return true;
7575
}
7676

77-
function parseDeclaration(declaration, key, result, options) {
77+
function parseDeclaration(declaration, key, result, isSupportDataURLInNewURL) {
7878
if (!needParseDeclaration.test(declaration[key])) {
7979
return;
8080
}
@@ -141,7 +141,9 @@ function parseDeclaration(declaration, key, result, options) {
141141
url = normalizeUrl(url, isStringValue);
142142

143143
// Do not traverse inside `url`
144-
if (!shouldHandleURL(url, declaration, result, options)) {
144+
if (
145+
!shouldHandleURL(url, declaration, result, isSupportDataURLInNewURL)
146+
) {
145147
// eslint-disable-next-line consistent-return
146148
return false;
147149
}
@@ -197,7 +199,9 @@ function parseDeclaration(declaration, key, result, options) {
197199
url = normalizeUrl(url, isStringValue);
198200

199201
// Do not traverse inside `url`
200-
if (!shouldHandleURL(url, declaration, result, options)) {
202+
if (
203+
!shouldHandleURL(url, declaration, result, isSupportDataURLInNewURL)
204+
) {
201205
// eslint-disable-next-line consistent-return
202206
return false;
203207
}
@@ -240,7 +244,9 @@ function parseDeclaration(declaration, key, result, options) {
240244
let url = normalizeUrl(value, true);
241245

242246
// Do not traverse inside `url`
243-
if (!shouldHandleURL(url, declaration, result, options)) {
247+
if (
248+
!shouldHandleURL(url, declaration, result, isSupportDataURLInNewURL)
249+
) {
244250
// eslint-disable-next-line consistent-return
245251
return false;
246252
}
@@ -282,11 +288,12 @@ const plugin = (options = {}) => {
282288

283289
return {
284290
Declaration(declaration) {
291+
const { isSupportDataURLInNewURL } = options;
285292
const parsedURL = parseDeclaration(
286293
declaration,
287294
"value",
288295
result,
289-
options
296+
isSupportDataURLInNewURL
290297
);
291298

292299
if (!parsedURL) {

0 commit comments

Comments
 (0)