Issue Summary:
The current implementation of the sortByReference function doesn't properly handle the DTCG token format, causing references in the output to be declared before their target. This occurs because the function assumes that token values can be accessed using the value attribute, which is not the case for the DTCG format, where the attribute is $value.
For example, this issue results in incorrect output like:
// Do not edit directly, this file was auto-generated.
$colors-primary: $colors-red;
$colors-red: #ff0000;
caused by:
// -- sortByReference.js
function sortByReference(dictionary)
function sorter(a, b) {
// [...]
// If token a uses a reference and token b doesn't, b might come before a
// read on..
if (a.original && dictionary.usesReference(a.original.value)) {
// Both a and b have references, we need to see if the reference each other
if (b.original && dictionary.usesReference(b.original.value)) {
const aRefs = dictionary.getReferences(a.original.value);
const bRefs = dictionary.getReferences(b.original.value);
// [...]
}
}
Description of changes:
This PR addresses the issue by modifying the sortByReference function to account for the usesDtcg options. It ensures that the correct token value is accessed based on the format (default or DTCG), preventing incorrect reference sorting.
Fixes https://github.com/amzn/style-dictionary/issues/1305
Issue Summary: The current implementation of the
sortByReference
function doesn't properly handle the DTCG token format, causing references in the output to be declared before their target. This occurs because the function assumes that token values can be accessed using thevalue
attribute, which is not the case for the DTCG format, where the attribute is$value
.For example, this issue results in incorrect output like:
caused by:
Description of changes: This PR addresses the issue by modifying the
sortByReference
function to account for theusesDtcg
options. It ensures that the correct token value is accessed based on the format (default or DTCG), preventing incorrect reference sorting.Additional Changes:
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.