-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add outputReferencesTransformed utility function (#1154)
- Loading branch information
1 parent
0b81a08
commit 2da5130
Showing
9 changed files
with
233 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'style-dictionary': minor | ||
--- | ||
|
||
Added `outputReferencesTransformed` utility function to pass into outputReferences option, which will not output references for values that have been transitively transformed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { resolveReferences } from './resolveReferences.js'; | ||
|
||
/** | ||
* @typedef {import('../../../types/DesignToken.d.ts').TransformedToken} TransformedToken | ||
* @typedef {import('../../../types/DesignToken.d.ts').Dictionary} Dictionary | ||
* | ||
* @param {TransformedToken} token | ||
* @param {{ dictionary: Dictionary, usesDtcg?: boolean }} dictionary | ||
* @returns | ||
*/ | ||
export function outputReferencesTransformed(token, { dictionary, usesDtcg }) { | ||
const originalValue = usesDtcg ? token.original.$value : token.original.value; | ||
const value = usesDtcg ? token.$value : token.value; | ||
|
||
// Check if the token's value is the same as if we were resolve references on the original value | ||
// This checks whether the token's value has been transformed e.g. transitive transforms. | ||
// If it has been, that means we should not be outputting refs because this would undo the work of those transforms. | ||
return value === resolveReferences(originalValue, dictionary.tokens, { usesDtcg }); | ||
} |