Skip to content

Commit f3091af

Browse files
committed
Add more cases handling to auto-rem
1 parent 437b1f7 commit f3091af

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

src/auto-rem.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ module.exports = () => {
1111
return;
1212
}
1313

14+
if (decl.prop === 'content') {
15+
return;
16+
}
17+
1418
decl.value = rem(decl.value);
1519
},
1620
};

src/converters.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,19 @@ function createConverter(units: string, { shouldScale = false, transformUnitLess
1818
}
1919

2020
if (typeof value === 'string') {
21-
if (value.startsWith('calc(') || value.startsWith('clamp(') || value.includes('rgba(')) {
21+
if (
22+
value.startsWith('calc(') ||
23+
value.startsWith('clamp(') ||
24+
value.includes('rgba(') ||
25+
value.includes('var(') ||
26+
value.includes('min(') ||
27+
value.includes('max(') ||
28+
value.includes('url(') ||
29+
value.includes('linear-gradient(') ||
30+
value.includes('radial-gradient(') ||
31+
value.includes('repeating-linear-gradient(') ||
32+
value.includes('repeating-radial-gradient(')
33+
) {
2234
return value;
2335
}
2436

src/tests/__snapshots__/auto-rem.test.ts.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`auto-rem does not transform content property 1`] = `
4+
"
5+
.demo::before {
6+
content: '10px';
7+
}
8+
"
9+
`;
10+
311
exports[`auto-rem does not transform strings with rgba 1`] = `
412
"
513
.demo {
@@ -10,6 +18,13 @@ exports[`auto-rem does not transform strings with rgba 1`] = `
1018
"
1119
`;
1220

21+
exports[`auto-rem does not transform url values 1`] = `
22+
"
23+
.demo {
24+
background: url('https://example.com/10px.png');
25+
}"
26+
`;
27+
1328
exports[`auto-rem does not transform values without units 1`] = `
1429
"
1530
.demo {

src/tests/auto-rem.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ const unitLessInput = `
4747
}
4848
`;
4949

50+
const contentInput = `
51+
.demo::before {
52+
content: '10px';
53+
}
54+
`;
55+
56+
const urlInput = `
57+
.demo {
58+
background: url('https://example.com/10px.png');
59+
}`;
60+
5061
describe('auto-rem', () => {
5162
it('it transforms px to rem values correctly', async () => {
5263
const res = await testTransform(baseInput, { autoRem: true });
@@ -77,4 +88,14 @@ describe('auto-rem', () => {
7788
const res = await testTransform(unitLessInput, { autoRem: true });
7889
expect(res.css).toMatchSnapshot();
7990
});
91+
92+
it('does not transform content property', async () => {
93+
const res = await testTransform(contentInput, { autoRem: true });
94+
expect(res.css).toMatchSnapshot();
95+
});
96+
97+
it('does not transform url values', async () => {
98+
const res = await testTransform(urlInput, { autoRem: true });
99+
expect(res.css).toMatchSnapshot();
100+
});
80101
});

0 commit comments

Comments
 (0)