Skip to content

Commit

Permalink
fix: expand on platform level to adjust path prop (#1231)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenbroekema authored Jun 4, 2024
1 parent 6560456 commit ba03ee9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-rings-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'style-dictionary': patch
---

Fix for expand utility on platform level to adjust the token's path property.
32 changes: 32 additions & 0 deletions __tests__/utils/expandObjectTokens.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,38 @@ describe('utils', () => {
expect(expanded).to.eql(borderOutput);
});

it('should adjust the path properties of the newly expanded tokens if path prop is already present (platform expand)', () => {
const expanded = expandToken(
{
type: 'border',
value: {
width: '2px',
style: 'solid',
color: '#000',
},
path: ['input', 'border'],
},
{ expand: true, usesDtcg: false },
);
expect(expanded).to.eql({
color: {
type: 'color',
value: '#000',
path: ['input', 'border', 'color'],
},
style: {
type: 'strokeStyle',
value: 'solid',
path: ['input', 'border', 'style'],
},
width: {
type: 'dimension',
value: '2px',
path: ['input', 'border', 'width'],
},
});
});

it('should handle DTCG spec tokens expansion', () => {
const expanded = expandToken(
{
Expand Down
5 changes: 5 additions & 0 deletions lib/utils/expandObjectTokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ export function expandToken(token, opts, platform) {
[`${uses$ ? '$' : ''}value`]: value,
[`${uses$ ? '$' : ''}type`]: getTypeFromMap(key, compositionType, typesMap),
};
if (Array.isArray(expandedTokenObjRef[key].path)) {
// if we're expanding on platform level, we already have a path property
// we will need to adjust this by adding the new keys of th expanded tokens to the path array
expandedTokenObjRef[key].path = [...expandedTokenObjRef[key].path, key];
}
});
});

Expand Down

0 comments on commit ba03ee9

Please sign in to comment.