Skip to content

Commit

Permalink
fix(tokenState): setTokensFromVariables description comparison (#3158)
Browse files Browse the repository at this point in the history
* fix(tokenState): setTokensFromVariables description comparison

* chore(tokenState): add changeset
  • Loading branch information
mrtnvh authored Oct 13, 2024
1 parent 7be0b29 commit 4fd3f9b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-fishes-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tokens-studio/figma-plugin": patch
---

fix(tokenState): setTokensFromVariables description comparison
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,17 @@ export const tokenState = createModel<RootModel>()({
const newTokens: StyleToCreateToken[] = [];
const existingTokens: StyleToCreateToken[] = [];
const updatedTokens: StyleToCreateToken[] = [];

// Iterate over received styles and check if they existed before or need updating
Object.values(receivedStyles).forEach((values) => {
values.forEach((token) => {
const oldValue = state.tokens[state.activeTokenSet].find((t) => t.name === token.name);

if (oldValue) {
if (isEqual(oldValue.value, token.value)) {
if (
oldValue.description === token.description
|| (typeof token.description === 'undefined' && oldValue.description === '')
) {
const normalizedOldValueDescription = oldValue.description ?? '';
const normalizedTokenDescription = token.description ?? '';
if (isEqual(normalizedOldValueDescription, normalizedTokenDescription)) {
existingTokens.push(token);
} else {
updatedTokens.push({
Expand Down Expand Up @@ -389,7 +389,9 @@ export const tokenState = createModel<RootModel>()({
const oldValue = state.tokens[token.parent].find((t) => t.name === token.name);
// If the token already exists
if (oldValue) {
if (isEqual(oldValue.value, token.value) && isEqual(oldValue.description, token.description)) {
const normalizedOldValueDescription = oldValue.description ?? '';
const normalizedTokenDescription = token.description ?? '';
if (isEqual(oldValue.value, token.value) && isEqual(normalizedOldValueDescription, normalizedTokenDescription)) {
existingTokens.push(token);
} else {
const updatedToken = { ...token };
Expand Down

0 comments on commit 4fd3f9b

Please sign in to comment.