Skip to content

Commit 7d60069

Browse files
fix: sizeRem regression in v4.3.1 to transform px to rem (#1436)
1 parent 6fc68b4 commit 7d60069

File tree

4 files changed

+212
-421
lines changed

4 files changed

+212
-421
lines changed

.changeset/clean-ligers-listen.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'style-dictionary': patch
3+
---
4+
5+
Hotfix for `'size/rem'` => `sizeRem` transform to not change values with `'px'` units to `'rem'`. Regression was added in `v4.3.1` (commit sha 1684a8e).

__tests__/common/transforms.test.js

+11
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,17 @@ describe('common', () => {
10231023
it('should throw an error if prop value is Nan', () => {
10241024
expect(() => transforms[sizeDp].transform({ value: 'a' }, {}, {})).to.throw();
10251025
});
1026+
1027+
it('should not change the unit to rem if the value already has a unit', () => {
1028+
const value = transforms[sizeRem].transform(
1029+
{
1030+
value: '5px',
1031+
},
1032+
{},
1033+
{},
1034+
);
1035+
expect(value).to.equal('5px');
1036+
});
10261037
});
10271038

10281039
describe(sizeFlutterRemToDouble, () => {

lib/common/transforms.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ export default {
829829
transform: function (token, _, options) {
830830
const nonParsed = options.usesDtcg ? token.$value : token.value;
831831
// if the dimension already has a unit (non-digit / . period character)
832-
if (`${nonParsed}`.match(/^[^0-9.-]+$/)) {
832+
if (`${nonParsed}`.match(/[^0-9.-]+$/)) {
833833
return nonParsed;
834834
}
835835
const parsedVal = parseFloat(nonParsed);

0 commit comments

Comments
 (0)