Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid checkAndEvaluateMatch returning NaN #337

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});
});
Loading