Open wzamites opened 1 year ago
I am seeing a similar thing with trying to match token.type = border
. When I use type: 'attribute'
or type: 'name'
I am able to see the matcher work.
const convertBorder = {
name: 'convertBorder',
type: 'value',
// type: 'attribute',
// type: 'name',
matcher: token => token.type === 'border',
transformer: token => {
console.log(token);
// return { color: token.value.color, size: token.value.width, style: token.value.style };
return token.value;
// if (token.type === 'border') {
// return { ...token.value, color: token.value.color, size: token.value.width, style: token.value.style };
// }
},
};
because the token is not matched the transformer function never runs. The strange thing is I have other transformers that are working perfectly
Here is my set up
token that is causing the issue
{
"global-outline-base": {
"value": {
"color": "{global-color-focus}",
"width": "3px",
"style": "solid"
},
"type": "border"
}
}
It does seem to be caused by the border color having a reference to anther token. If I update the value of color to a hex value this prob is resolved. Although, when pointing to a reference it is being resolved in the finial output
@wzamites I am able to work around this issue by using a type other than value. You can set the token value that you wish, and return the token.
example
const convertBorder = {
name: 'convertBorder',
type: 'attribute',
matcher: token => token.type === 'border',
transformer: token => {
token.value = { color: token.value.color, size: token.value.width, style: token.value.style };
return token;
},
};
@wzamites After a little more research on transformers looks like we just need to add the property transitive: true,
https://amzn.github.io/style-dictionary/#/transforms?id=transitive-transforms
I have this transform. Note the console.log and that it modifies the value of the token to the string
'hello'
:I can see in the result that the JS build files that it modifies a token to what would have been this:
Modifies to this. Note that both
borderWidth
andborder
now have the valuehello
:But it does not show up in the console log at all. And this transformation only takes place without a matcher function. If use this matcher function, the transformation to "hello" does not take place:
matcher: token => token.type === 'composition',
This also only seems to happen with tokens whose values are not explicitly strings. What am I doing wrong? How can I write a correct matcher that will catch this token? And how can I see it in the console.log output?