Imagine this situation where the ref is not in the value but in another prop, even if the transform that handles darkening is transitive, it won't get the 0.5 but rather '{a}' and the darken transformation will fail.
I see two approaches to tackle this:
Transforms don't apply (and defer) if a sibling to the value prop has a ref, or if any nested prop in a sibling of value prop uses a ref e.g. darken.value. This is quite breaking as this means that regular transforms will stop applying when a completely unrelated piece of metadata sibling to the value prop contains references e.g. description: 'My description {foo.bar}'. So then in these cases people will be forced to make their transforms transitive if they run into this situation.
Transitive transforms -> transformer function is allowed to return undefined, which defers the transformation. The transform can do this when it notices that a metadata prop that is relevant to it, contains a ref, e.g.:
{
transformer: (token) => {
const darkenMod = token?.$extensions?.['bar.foo']?.darken;
if (darkenMod) {
if (usesReferences(darkenMod)) {
return undefined; // defer it until later, when the darkenMod prop does get resolved
}
if (typeof darkenMod === 'number') {
return darken(token.value, darkenMod);
}
}
return token.value;
}
}
I think the latter one makes the most sense, since only the transform can know for sure that it needs to defer the transform, Style-Dictionary doesn't know which metadata props are related to the transform and which aren't. However, I'm not 100% sure if undefined return value for transformer for transitive transforms as an API thing to defer the transformation is what makes the most sense, but it's the best I could come up with in the short term
related issue: https://github.com/tokens-studio/sd-transforms/issues/211 but simplified in this example below:
Imagine this situation where the ref is not in the value but in another prop, even if the transform that handles darkening is transitive, it won't get the
0.5
but rather'{a}'
and the darken transformation will fail.I see two approaches to tackle this:
darken.value
. This is quite breaking as this means that regular transforms will stop applying when a completely unrelated piece of metadata sibling to the value prop contains references e.g.description: 'My description {foo.bar}'
. So then in these cases people will be forced to make their transforms transitive if they run into this situation.transformer
function is allowed to returnundefined
, which defers the transformation. The transform can do this when it notices that a metadata prop that is relevant to it, contains a ref, e.g.:I think the latter one makes the most sense, since only the transform can know for sure that it needs to defer the transform, Style-Dictionary doesn't know which metadata props are related to the transform and which aren't. However, I'm not 100% sure if
undefined
return value for transformer for transitive transforms as an API thing to defer the transformation is what makes the most sense, but it's the best I could come up with in the short term