1+ /* eslint-disable eslintComments/no-use */ 
2+ /* eslint-disable camelcase */ 
13/* 
24 * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 
35 * 
1012 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions 
1113 * and limitations under the License. 
1214 */ 
15+ import  type  { Dictionary ,  FormattingOptions ,  OutputReferences ,  TransformedToken }  from  'style-dictionary/types' 
1316import  { getReferences ,  usesReferences }  from  'style-dictionary/utils' 
1417
1518/** 
@@ -39,7 +42,7 @@ const defaultFormatting = {
3942 * @param  {Formatting } options 
4043 * @returns  {string } 
4144 */ 
42- export  function  addComment ( to_ret_token ,  comment ,  options )  { 
45+ export  function  addComment ( to_ret_token :  string ,  comment :  string ,  options :  FormattingOptions )  { 
4346  const  { commentStyle,  indentation}  =  options 
4447  let  { commentPosition}  =  options 
4548
@@ -124,9 +127,17 @@ export default function createPropertyFormatterWithRef({
124127  formatting =  { } , 
125128  themeable =  false , 
126129  usesDtcg =  false , 
130+ } : { 
131+   outputReferences ?: OutputReferences 
132+   outputReferenceFallbacks ?: boolean 
133+   dictionary : Dictionary 
134+   format ?: string 
135+   formatting ?: FormattingOptions 
136+   themeable ?: boolean 
137+   usesDtcg ?: boolean 
127138} )  { 
128139  /** @type  {Formatting } */ 
129-   const  formatDefaults  =  { } 
140+   const  formatDefaults :  FormattingOptions  =  { } 
130141  switch  ( format )  { 
131142    case  'css' :
132143      formatDefaults . prefix  =  '--' 
@@ -141,7 +152,7 @@ export default function createPropertyFormatterWithRef({
141152  } 
142153  const  { prefix,  commentStyle,  indentation,  separator,  suffix}  =  mergedOptions 
143154  const  { tokens,  unfilteredTokens}  =  dictionary 
144-   return  function  ( token )  { 
155+   return  function  ( token :  TransformedToken )  { 
145156    let  to_ret_token  =  `${ indentation } ${ prefix } ${ token . name } ${ separator }   ` 
146157    let  value  =  usesDtcg  ? token . $value  : token . value 
147158    const  originalValue  =  usesDtcg  ? token . original . $value  : token . original . value 
@@ -192,31 +203,16 @@ export default function createPropertyFormatterWithRef({
192203            } ) 
193204            . join ( ' ' ) 
194205        } 
195-         // if (token.attributes.referenceMap) { 
196-         //   // console.log(token) 
197-         //   // console.log('original is object', token.attributes || '') 
198-         //   value = token.attributes.referenceMap 
199-         //   // console.log('referenceMap', token.attributes.referenceMap) 
200-         //   for (const [key, val] of Object.entries(originalValue)) { 
201-         //     const regex = new RegExp(`\\[${key}\\]`) 
202-         //     value = value.replace(regex, val) 
203-         //   } 
204-         // } 
205206      } 
206-       // console.log('originalValue:', originalValue, JSON.stringify(originalIsObject)) 
207-       // if (ref.$type === 'border') { 
208-       //   console.log('BORDER:', ref.original) 
209-       // } 
210-       // console.log('refs: ', refs) 
211- 
207+       /* eslint-disable-next-line github/array-foreach */ 
212208      refs . forEach ( ref  =>  { 
213209        // value should be a string that contains the resolved reference 
214210        // because Style Dictionary resolved this in the resolution step. 
215211        // Here we are undoing that by replacing the value with 
216212        // the reference's name 
217213        if  ( Object . hasOwn ( ref ,  `${ usesDtcg  ? '$'  : '' }  value` )  &&  Object . hasOwn ( ref ,  'name' ) )  { 
218214          const  refVal  =  usesDtcg  ? ref . $value  : ref . value 
219-           const  replaceFunc  =  function   ( )  { 
215+           const  replaceFunc  =  ( )   =>  { 
220216            if  ( format  ===  'css' )  { 
221217              if  ( outputReferenceFallbacks )  { 
222218                return  `var(${ prefix } ${ ref . name }  , ${ refVal }  )` 
@@ -248,7 +244,7 @@ export default function createPropertyFormatterWithRef({
248244
249245    const  comment  =  token . $description  ??  token . comment 
250246    if  ( comment  &&  commentStyle  !==  'none' )  { 
251-       to_ret_token  =  addComment ( to_ret_token ,  comment ,  mergedOptions ) 
247+       to_ret_token  =  addComment ( to_ret_token ,  comment ,  mergedOptions   as   FormattingOptions ) 
252248    } 
253249    // console.log('to_ret_token', to_ret_token) 
254250    return  to_ret_token 
0 commit comments