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: expand on platform level to adjust path prop #1231

Merged
merged 1 commit into from
Jun 4, 2024
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/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