@@ -344,14 +344,18 @@ module.exports = {
344
344
* @returns Variable
345
345
*/
346
346
retrieveVariable ( variableId ) {
347
- return Object . values ( this . _jsonData . variables ) . find ( ( variable ) => {
348
- return variable . id === variableId ;
349
- } ) ;
347
+ const retrieved = Object . values ( this . _jsonData . variables ) . find (
348
+ ( variable ) => {
349
+ return variable . id === variableId ;
350
+ } ,
351
+ ) ;
352
+ return retrieved ;
350
353
}
351
354
} ,
352
355
353
356
FigmaVariable : class {
354
- static TIER_1_PREFIX = 'Render/' ;
357
+ static TIER_1_PREFIX = 'render/' ;
358
+ static VARIABLE_ALIAS = 'VARIABLE_ALIAS' ;
355
359
356
360
constructor ( json , mode , lookupDelegate ) {
357
361
// TODO: throw if any private members are invalid
@@ -415,8 +419,27 @@ module.exports = {
415
419
}
416
420
}
417
421
422
+ /**
423
+ * Determine whether a variable is marked as orphaned (e.g., deleted from the var.s but still used in a component)
424
+ * @returns {boolean }
425
+ */
426
+ isOrphaned ( ) {
427
+ return ! ! this . _figmaVariableData . deletedButReferenced ;
428
+ }
429
+
430
+ /**
431
+ * @static
432
+ *
433
+ * Returns whether the value of a given figma variable and mode is a reference or not
434
+ * @param {FigmaVariable } figmaVariable API JSON data representing a figma variable instance
435
+ * @param {string } mode the collection that the variable has a value in
436
+ * @returns {boolean } whether the value for the variable is a literal or references another figma variable
437
+ */
418
438
static isAliased ( figmaVariable , mode ) {
419
- return figmaVariable . valuesByMode [ mode ] ?. type === 'VARIABLE_ALIAS' ;
439
+ return (
440
+ figmaVariable . valuesByMode [ mode ] ?. type ===
441
+ module . exports . FigmaVariable . VARIABLE_ALIAS
442
+ ) ;
420
443
}
421
444
422
445
/**
@@ -499,55 +522,49 @@ module.exports = {
499
522
}
500
523
}
501
524
525
+ /**
526
+ * @property
527
+ * Unformatted (figma) name for the current figma variable
528
+ */
502
529
get name ( ) {
503
530
return this . _figmaVariableData . name ;
504
531
}
505
532
533
+ /**
534
+ * @property
535
+ * Resolved and parsed value for the given variable. Performs lookup if value is aliased, using delegate.
536
+ */
506
537
get value ( ) {
507
538
return this . parseResolvedValue ( this . getResovledValue ( ) ) ;
508
539
}
509
540
541
+ /**
542
+ * @property
543
+ * Resolved and parsed value reference (path) for the given variable. Performs lookup if value is aliased, using delegate.
544
+ */
510
545
get valueRef ( ) {
511
546
switch ( this . _figmaVariableData . resolvedType ) {
512
547
case 'COLOR' :
513
- // TODO: (in source) transparent exists as a tier 1 token but should not
514
- if ( this . getResovledName ( ) === 'Render/Transparent' ) {
515
- return 'transparent' ;
516
- }
548
+ // TODO-AH: BUG: we assume all lookups resolve to a tier 1 value
549
+ // the one that errors is b/c it doesn't eventually reference a tier 1 (icon/util/inverse-disabled)
550
+ // how to properly use .getTokenPath here?
517
551
return module . exports . FigmaVariable . isAliased (
518
552
this . _figmaVariableData ,
519
553
this . _mode ,
520
554
)
521
- ? `{${ this . _tokenNameToPath (
522
- this . getResovledName ( )
523
- . replace (
524
- module . exports . FigmaVariable . TIER_1_PREFIX ,
525
- 'eds.color.' ,
526
- )
527
- // TODO: (in source) remove duplicate color from structures
528
- . replace ( 'Neutral/Neutral' , 'Neutral' )
529
- . replace ( 'Red/Red' , 'Red' )
530
- . replace ( 'Orange/Orange' , 'Orange' )
531
- . replace ( 'Yellow/Yellow' , 'Yellow' )
532
- . replace ( 'Green/Green' , 'Green' )
533
- . replace ( 'Blue/Blue' , 'Blue' )
534
- . replace ( 'Purple/Purple' , 'Purple' )
535
- . replace ( 'Pink/Pink' , 'Pink' )
536
- // TODO: (in source) lower case the names of the tier 1 color tokens
537
- . toLowerCase ( ) ,
538
- ) } }`
555
+ ? `${ this . _tokenNameToPath (
556
+ this . getResovledName ( ) . replace (
557
+ module . exports . FigmaVariable . TIER_1_PREFIX ,
558
+ 'eds.color.' ,
559
+ ) ,
560
+ ) } `
539
561
: this . value ;
540
562
case 'FLOAT' :
541
563
return module . exports . FigmaVariable . isAliased (
542
564
this . _figmaVariableData ,
543
565
this . _mode ,
544
566
)
545
- ? `{${ this . _tokenNameToPath (
546
- 'eds.' +
547
- this . getResovledName ( )
548
- // TODO: (in source) lower case the names of the tier 1 color tokens
549
- . toLowerCase ( ) ,
550
- ) } }`
567
+ ? `${ this . _tokenNameToPath ( 'eds.' + this . getResovledName ( ) ) } `
551
568
: this . value ;
552
569
default :
553
570
throw new TypeError (
0 commit comments