Skip to content

Commit

Permalink
fix: avoid checkAndEvaluateMatch returning NaN (#337)
Browse files Browse the repository at this point in the history
Co-authored-by: teunverhaert <[email protected]>
  • Loading branch information
teunverhaert and teunverhaert authored Jan 16, 2025
1 parent 54aedc6 commit ab40f11
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/serious-islands-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tokens-studio/sd-transforms': patch
---

avoid checkAndEvaluateMath returning NaN
2 changes: 1 addition & 1 deletion src/checkAndEvaluateMath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function parseAndReduce(expr: string, fractionDigits = defaultFractionDigits): s
// Attempt to reduce the math expression
const reduced = reduceExpression(calcParsed);
// E.g. if type is Length, like 4 * 7rem would be 28rem
if (reduced) {
if (reduced && !isNaN(reduced.value)) {
result = reduced.value;
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/spec/checkAndEvaluateMath.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,8 @@ describe('check and evaluate math', () => {
).to.eql(['0px 4px 12px #000000', '0px 8px 18px #0000008C']);
});
});

it('does not transform hex values containing E', () => {
expect(checkAndEvaluateMath({ value: 'E6', type: 'other' })).to.equal('E6');
});
});

0 comments on commit ab40f11

Please sign in to comment.