Skip to content

Commit

Permalink
fix: sizeRem regression in v4.3.1 to transform px to rem (#1436)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenbroekema authored Jan 21, 2025
1 parent 6fc68b4 commit 7d60069
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 421 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-ligers-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'style-dictionary': patch
---

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).
11 changes: 11 additions & 0 deletions __tests__/common/transforms.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,17 @@ describe('common', () => {
it('should throw an error if prop value is Nan', () => {
expect(() => transforms[sizeDp].transform({ value: 'a' }, {}, {})).to.throw();
});

it('should not change the unit to rem if the value already has a unit', () => {
const value = transforms[sizeRem].transform(
{
value: '5px',
},
{},
{},
);
expect(value).to.equal('5px');
});
});

describe(sizeFlutterRemToDouble, () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/common/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ export default {
transform: function (token, _, options) {
const nonParsed = options.usesDtcg ? token.$value : token.value;
// if the dimension already has a unit (non-digit / . period character)
if (`${nonParsed}`.match(/^[^0-9.-]+$/)) {
if (`${nonParsed}`.match(/[^0-9.-]+$/)) {
return nonParsed;
}
const parsedVal = parseFloat(nonParsed);
Expand Down
Loading

0 comments on commit 7d60069

Please sign in to comment.