@@ -8,11 +8,11 @@ import { usesReferences, resolveReferences } from 'style-dictionary/utils';
8
8
import { fontWeightReg , fontStyles } from '../transformFontWeight.js' ;
9
9
import { TransformOptions } from '../TransformOptions.js' ;
10
10
11
- function resolveFontWeight ( fontWeight : string , copy : DeepKeyTokenMap < false > ) {
11
+ function resolveFontWeight ( fontWeight : string , copy : DeepKeyTokenMap < false > , usesDtcg : boolean ) {
12
12
let resolved = fontWeight ;
13
13
if ( usesReferences ( fontWeight ) ) {
14
14
try {
15
- resolved = `${ resolveReferences ( fontWeight , copy ) } ` ;
15
+ resolved = `${ resolveReferences ( fontWeight , copy , { usesDtcg } ) } ` ;
16
16
} catch ( e ) {
17
17
// dont throw fatal, see: https://github.com/tokens-studio/sd-transforms/issues/217
18
18
// we throw once we only support SD v4, for v3 we need to be more permissive
@@ -56,17 +56,21 @@ function recurse(
56
56
57
57
if ( isToken ) {
58
58
const token = potentiallyToken as SingleToken < false > ;
59
- const usesDTCG = Object . hasOwn ( token , '$value' ) ;
59
+ const usesDtcg = Object . hasOwn ( token , '$value' ) ;
60
60
const { value, $value, type, $type } = token ;
61
- const tokenType = ( usesDTCG ? $type : type ) as string ;
62
- const tokenValue = ( usesDTCG ? $value : value ) as
61
+ const tokenType = ( usesDtcg ? $type : type ) as string ;
62
+ const tokenValue = ( usesDtcg ? $value : value ) as
63
63
| ( TokenTypographyValue & { fontStyle : string } )
64
64
| SingleFontWeightsToken [ 'value' ] ;
65
65
66
66
if ( tokenType === 'typography' ) {
67
67
const tokenTypographyValue = tokenValue as TokenTypographyValue & { fontStyle : string } ;
68
68
if ( tokenTypographyValue . fontWeight === undefined ) return ;
69
- const fontWeight = resolveFontWeight ( `${ tokenTypographyValue . fontWeight } ` , refCopy ) ;
69
+ const fontWeight = resolveFontWeight (
70
+ `${ tokenTypographyValue . fontWeight } ` ,
71
+ refCopy ,
72
+ usesDtcg ,
73
+ ) ;
70
74
const { weight, style } = splitWeightStyle ( fontWeight , alwaysAddFontStyle ) ;
71
75
72
76
tokenTypographyValue . fontWeight = weight ;
@@ -75,16 +79,16 @@ function recurse(
75
79
}
76
80
} else if ( tokenType === 'fontWeight' ) {
77
81
const tokenFontWeightsValue = tokenValue as SingleFontWeightsToken [ 'value' ] ;
78
- const fontWeight = resolveFontWeight ( `${ tokenFontWeightsValue } ` , refCopy ) ;
82
+ const fontWeight = resolveFontWeight ( `${ tokenFontWeightsValue } ` , refCopy , usesDtcg ) ;
79
83
const { weight, style } = splitWeightStyle ( fontWeight , alwaysAddFontStyle ) ;
80
84
81
85
// since tokenFontWeightsValue is a primitive (string), we have to permutate the change directly
82
- token [ `${ usesDTCG ? '$' : '' } value` ] = weight ;
86
+ token [ `${ usesDtcg ? '$' : '' } value` ] = weight ;
83
87
if ( style ) {
84
88
( slice as DeepKeyTokenMap < false > ) [ `fontStyle` ] = {
85
89
...token ,
86
- [ `${ usesDTCG ? '$' : '' } type` ] : 'fontStyle' ,
87
- [ `${ usesDTCG ? '$' : '' } value` ] : style ,
90
+ [ `${ usesDtcg ? '$' : '' } type` ] : 'fontStyle' ,
91
+ [ `${ usesDtcg ? '$' : '' } value` ] : style ,
88
92
} ;
89
93
}
90
94
}
0 commit comments