Repository navigation
Conversation
…t decimals evaluateSimpleExpression let the left operand of * and / take a '-', so 200-2*-20 became 200 followed by 40 (20040). Numbers like .5 or .25 were not matched at all. The expression is now split into numbers and operators first; a sign is only part of a number where a number is expected. Percentages also accept leading-dot values (.5%). Fixes f5#1000
|
CLA Assistant Lite bot ✅ All required contributors have signed the F5 CLA for this PR. Thank you! |
|
I have hereby read the F5 CLA and agree to its terms |
|
Thanks for tackling this. I confirmed that this PR passes all six examples from #1000. I found three cases to address before merging:
I opened draft #1002 with an implementation that resolves percentages and parenthesized values numerically, plus regression tests. |
|
Thanks for checking it so closely. You're right on all three, and #1002 handles them more cleanly than my string-replace approach (numeric percentages, no re-parse, and the One small thing I noticed while trying #1002: division by zero still comes back as |
What & why
Fixes #1000
parseUnitgave wrong numbers for somecalc()expressions (used byAnnotationssince #624):calc(100% - 2 * (10px - 30px))(200)calc(10px - 2 * -3)calc(20 - 4 / -2)calc(.5 * 100%)(200)calc(100% * .25)(200)calc(.5% + 10px)(200)Cause: in
evaluateSimpleExpressionthe left operand of*//could take a-, so in200-2*-20the subtraction sign was eaten into-2*-20 = 40, and40was glued onto200. The number regex also missed leading-dot decimals like.5.Change (only
packages/ts/src/utils/misc.ts):evaluateSimpleExpressionnow splits the expression into numbers and operators first. A+/-is read as a sign only where a number is expected (at the start or right after an operator). Then*//are applied, then+/-, left to right. Malformed input still throws, soparseUnitstill warns and returns 0..5%).Checklist
eslint)packages/ts:pnpm build)packages/ts/src/utils/misc.spec.ts: the two new cases fail onmainand pass now;packages/tsvitest 152 pass.pnpm cmds-report(only core TS code changed, no wrappers or docs).