Skip to content

Commit

Permalink
#2329 handle variables with image-set in name
Browse files Browse the repository at this point in the history
  • Loading branch information
onigoetz committed May 13, 2024
1 parent 3e17bcf commit a9cf210
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
8 changes: 8 additions & 0 deletions package-forks/postcss-image-set-polyfill/__tests__/test.js
Expand Up @@ -17,6 +17,14 @@ test("don't break simple background-image property", async (t) => {
return runTest(t, input, input);
});

test("ignore variables with image-set in name", async (t) => {
const input = `a {
background-image: var(--ag-icon-image-settings, var(--ag-icon-image));
}`;

return runTest(t, input, input);
});

test("don't break simple background property", async (t) => {
const input = `a {
background: url(my-img-print.png) top left no-repeat red;
Expand Down
16 changes: 10 additions & 6 deletions package-forks/postcss-image-set-polyfill/index.js
Expand Up @@ -8,8 +8,10 @@ const DPI_RATIO = {
dpi: 1
};

const IMAGE_SET_FN = /image-set\s*\(/;

// convert all sizes to dpi for sorting
const convertSize = (size, decl) => {
function convertSize(size, decl) {
if (!size) {
return DPI_RATIO.x;
}
Expand All @@ -26,11 +28,13 @@ const convertSize = (size, decl) => {
}

throw decl.error("Incorrect size value", { word: m && m[2] });
};
}

const stringify = chunk => valueParser.stringify(chunk);
function stringify(chunk) {
return valueParser.stringify(chunk);
}

const parseValue = (value, decl) => {
function parseValue(value, decl) {
const valueChunks = valueParser(value).nodes;

const imageSetChunks = valueChunks.shift().nodes;
Expand All @@ -55,7 +59,7 @@ const parseValue = (value, decl) => {
},
suffix
};
};
}

function getValues(decl, list) {
const commaSeparatedValues = list.comma(decl.value);
Expand All @@ -64,7 +68,7 @@ function getValues(decl, list) {
const parsedValues = commaSeparatedValues.map(value => {
const result = {};

if (value.indexOf("image-set") === -1) {
if (!IMAGE_SET_FN.test(value)) {
result.default = value;
return result;
}
Expand Down

0 comments on commit a9cf210

Please sign in to comment.