Skip to content

Commit 19f4530

Browse files
fix: do not add always add fontStyle for fontWeights (#300)
1 parent 3a044ed commit 19f4530

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

.changeset/giant-bears-drum.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tokens-studio/sd-transforms': patch
3+
---
4+
5+
Fix alwaysAddFontStyle option to not apply to tokens of type fontWeight(s), only meant for typography tokens.

src/preprocessors/add-font-styles.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ function recurse(
8080
} else if (tokenType === 'fontWeight') {
8181
const tokenFontWeightsValue = tokenValue as SingleFontWeightsToken['value'];
8282
const fontWeight = resolveFontWeight(`${tokenFontWeightsValue}`, refCopy, usesDtcg);
83-
const { weight, style } = splitWeightStyle(fontWeight, alwaysAddFontStyle);
83+
// alwaysAddFontStyle should only apply to typography tokens, so we pass `false` here
84+
const { weight, style } = splitWeightStyle(fontWeight, false);
8485

8586
if (style) {
8687
// since tokenFontWeightsValue is a primitive (string), we have to permutate the change directly

test/spec/preprocessors/add-font-styles.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,27 @@ describe('add font style', () => {
179179
});
180180
});
181181

182+
it(`does not affect fontWeight tokens with alwaysAddFontStyle option`, () => {
183+
expect(
184+
addFontStyles(
185+
// @ts-expect-error fontWeight (singular vs plural) doesn't exist on the type
186+
// but we assume it's already preprocessed and aligned here
187+
{
188+
foo: {
189+
value: 'Bold',
190+
type: 'fontWeight',
191+
},
192+
} as DeepKeyTokenMap<false>,
193+
{ alwaysAddFontStyle: true },
194+
),
195+
).to.eql({
196+
foo: {
197+
value: 'Bold',
198+
type: 'fontWeight',
199+
},
200+
});
201+
});
202+
182203
it(`allows always adding a default fontStyle for DTCG formatted tokens`, () => {
183204
expect(
184205
addFontStyles(

0 commit comments

Comments
 (0)