diff --git a/.changeset/giant-bears-drum.md b/.changeset/giant-bears-drum.md new file mode 100644 index 0000000..a04da93 --- /dev/null +++ b/.changeset/giant-bears-drum.md @@ -0,0 +1,5 @@ +--- +'@tokens-studio/sd-transforms': patch +--- + +Fix alwaysAddFontStyle option to not apply to tokens of type fontWeight(s), only meant for typography tokens. diff --git a/src/preprocessors/add-font-styles.ts b/src/preprocessors/add-font-styles.ts index 84156d3..8f3419c 100644 --- a/src/preprocessors/add-font-styles.ts +++ b/src/preprocessors/add-font-styles.ts @@ -80,7 +80,8 @@ function recurse( } else if (tokenType === 'fontWeight') { const tokenFontWeightsValue = tokenValue as SingleFontWeightsToken['value']; const fontWeight = resolveFontWeight(`${tokenFontWeightsValue}`, refCopy, usesDtcg); - const { weight, style } = splitWeightStyle(fontWeight, alwaysAddFontStyle); + // alwaysAddFontStyle should only apply to typography tokens, so we pass `false` here + const { weight, style } = splitWeightStyle(fontWeight, false); if (style) { // since tokenFontWeightsValue is a primitive (string), we have to permutate the change directly diff --git a/test/spec/preprocessors/add-font-styles.spec.ts b/test/spec/preprocessors/add-font-styles.spec.ts index 8175f9e..f027e20 100644 --- a/test/spec/preprocessors/add-font-styles.spec.ts +++ b/test/spec/preprocessors/add-font-styles.spec.ts @@ -179,6 +179,27 @@ describe('add font style', () => { }); }); + it(`does not affect fontWeight tokens with alwaysAddFontStyle option`, () => { + expect( + addFontStyles( + // @ts-expect-error fontWeight (singular vs plural) doesn't exist on the type + // but we assume it's already preprocessed and aligned here + { + foo: { + value: 'Bold', + type: 'fontWeight', + }, + } as DeepKeyTokenMap, + { alwaysAddFontStyle: true }, + ), + ).to.eql({ + foo: { + value: 'Bold', + type: 'fontWeight', + }, + }); + }); + it(`allows always adding a default fontStyle for DTCG formatted tokens`, () => { expect( addFontStyles(