Skip to content

Commit

Permalink
fix: add-font-style parser for null props
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenbroekema committed Sep 29, 2023
1 parent 6bb19c8 commit 3f37446
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/sour-numbers-arrive.md
@@ -0,0 +1,5 @@
---
'@tokens-studio/sd-transforms': patch
---

Fix for add-font-styles parser to deal with value props not being objects (e.g. null).
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/parsers/add-font-styles.ts
Expand Up @@ -13,6 +13,9 @@ function recurse(
) {
for (const key in slice) {
const token = slice[key];
if (typeof token !== 'object' || token === null) {
continue;
}
const { type, value } = token;
if (type === 'typography') {
if (typeof value !== 'object') {
Expand Down
22 changes: 22 additions & 0 deletions test/spec/parsers/add-font-styles.spec.ts
Expand Up @@ -133,4 +133,26 @@ describe('add font style', () => {
},
});
});

it('does not error on value property equaling null', () => {
expect(
addFontStyles({
foo: {
value: {
fontWeight: 'Bold',
type: null,
},
type: 'typography',
},
} as DeepKeyTokenMap<false>),
).to.eql({
foo: {
value: {
fontWeight: 'Bold',
type: null,
},
type: 'typography',
},
});
});
});

0 comments on commit 3f37446

Please sign in to comment.