Skip to content

Fix calc() arithmetic in parseUnit - #1002

Merged
lee00678 merged 1 commit into
f5:mainfrom
rokotyan:fix/parse-unit-calc
Dec 2, 2026
Merged

lee00678 merged 1 commit into
f5:mainfrom
rokotyan:fix/parse-unit-calc

Conversation

@rokotyan

@rokotyan rokotyan commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What & why

parseUnit('calc(100% - 2 * (10px - 30px))', 200) returns 20040 on main. It now returns 240. The parser reads signs in context, supports leading-dot decimals, and resolves percentages and parentheses without converting intermediate results to strings. LengthUnit now accepts calc() strings for typed annotation inputs.

Non-finite calc() results now warn and return 0, including when a percentage expression resolves the divisor to zero. Thanks to Bardrop for flagging this case. Review comment

Fixes #1000.

Checklist

  • Regression tests cover all six reported expressions, division by zero, zero products, small intermediate values, and percentage bases (pnpm test:ts, 167 passing)
  • Lint passes on changed files
  • Builds locally (pnpm build && pnpm build:dev)
  • Annotation positions, dimensions, and subject coordinates verified in Chromium and WebKit
  • All 26 commands pass (pnpm cmds-report)

Repository-wide pnpm lint reports import resolution and ESLint configuration errors in unchanged files.

Screenshots

Light and dark before-and-after captures are ready to attach. GitHub CLI requires upstream repository write access to upload them.

@rokotyan
rokotyan force-pushed the fix/parse-unit-calc branch from 8ef5764 to fdb4eb0 Compare November 17, 2026 03:15
@rokotyan
rokotyan marked this pull request as ready for review November 17, 2026 03:17
@rokotyan
rokotyan force-pushed the fix/parse-unit-calc branch from fdb4eb0 to 74f7bf8 Compare November 17, 2026 03:23
@lee00678
lee00678 merged commit e6a6549 into f5:main Dec 2, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parseUnit calc() misparses subtracted negative products/quotients and leading-dot decimals

2 participants