Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sizeRem regression in v4.3.1 to transform px to rem #1436

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading