Skip to content

Commit 97e7d26

Browse files
author
teunverhaert
committed
fix: avoid checkAndEvaluateMatch returning NaN
1 parent 54aedc6 commit 97e7d26

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

.changeset/serious-islands-approve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tokens-studio/sd-transforms': patch
3+
---
4+
5+
avoid checkAndEvaluateMath returning NaN

src/checkAndEvaluateMath.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function parseAndReduce(expr: string, fractionDigits = defaultFractionDigits): s
135135
// Attempt to reduce the math expression
136136
const reduced = reduceExpression(calcParsed);
137137
// E.g. if type is Length, like 4 * 7rem would be 28rem
138-
if (reduced) {
138+
if (reduced && !isNaN(reduced.value)) {
139139
result = reduced.value;
140140
}
141141
}

test/spec/checkAndEvaluateMath.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,4 +272,8 @@ describe('check and evaluate math', () => {
272272
).to.eql(['0px 4px 12px #000000', '0px 8px 18px #0000008C']);
273273
});
274274
});
275+
276+
it('does not transform hex values containing E', () => {
277+
expect(checkAndEvaluateMath({ value: 'E6', type: 'other' })).to.equal('E6');
278+
});
275279
});

0 commit comments

Comments
 (0)