Skip to content

Commit

Permalink
chore(tokens): allow numbers as keys in tokens
Browse files Browse the repository at this point in the history
The change ensures we're correctly transforming the dot notation to access
object properties when numbers are used as keys:
'foundations.borderRadius.50' is incorrect JavaScript;
'foundations.borderRadius["50"]' is valid JavaScript.
  • Loading branch information
RobinCsl authored and sarkaaa committed Jul 16, 2024
1 parent c4e0e68 commit 2ea85da
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,17 @@ const typescriptFactory = (allProperties: Dictionary["allProperties"], complete

return createObjectProperty(name, `boxShadow(${boxShadowValue})`);
}
return createObjectProperty(name, plainValue);

/**
* This ensures tokens like 'foundations.borderRadius.50'
* will be correctly written as 'foundations.borderRadius["50"]'
* and be correct JavaScript code.
*/
const val =
typeof plainValue === "string"
? plainValue.replace(/(\w+)\.(\d+)(?=\.|$)/g, '$1["$2"]')
: plainValue;
return createObjectProperty(name, val);
});

const plainTokens = createValue(tokens, "javascript");
Expand Down

0 comments on commit 2ea85da

Please sign in to comment.