From 7d5bc7c11cac7cfab8c1873b1697e748765b8a24 Mon Sep 17 00:00:00 2001 From: Jonatas da Silva Teixeira Date: Tue, 26 Sep 2023 03:22:46 -0300 Subject: [PATCH] fix: solves the duplicate variable name error --- styles-to-variables/code.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/styles-to-variables/code.js b/styles-to-variables/code.js index ce691fb..25400fe 100644 --- a/styles-to-variables/code.js +++ b/styles-to-variables/code.js @@ -9,6 +9,22 @@ function createTokens(tokenData) { if (tokenData.length <= 0) { figma.notify("No convertible styles found. :("); return; + } else { + const tokens = tokenData.map(item => item.tokens); + const tokenCount = {}; + + tokenData.forEach(item => { + const {tokens} = item; + if (tokens.length === 1) { + const token = tokens[0]; + if (tokenCount[token] === undefined) { + tokenCount[token] = 1; + } else { + tokenCount[token]++; + tokens[0] = `${token}${tokenCount[token]}`; + } + } + }); } const collection = figma.variables.createVariableCollection(`Style Tokens`); let aliasCollection;