Skip to content

fix: keep NaN, Infinity and -0 in inlined macro values - #185

Closed
bardrop wants to merge 1 commit into
unplugin:mainfrom
bardrop:fix-non-finite-numbers
Closed

bardrop wants to merge 1 commit into
unplugin:mainfrom
bardrop:fix-non-finite-numbers

Conversation

@bardrop

@bardrop bardrop commented Nov 12, 2026

Copy link
Copy Markdown

Closes #183

stringifyValue fell back to JSON.stringify for numbers, which turns NaN, Infinity and -Infinity into null and -0 into 0. The build passed but the bundle used the wrong value, also inside arrays and objects.

Now -0 is written as -0 and non-finite numbers as NaN / Infinity / -Infinity, next to the existing special cases for bigint, RegExp and Date.

Added a number.js fixture (top-level values, an array and an object). On main its snapshot shows null / 0; with this change it shows the real values. vitest run (46 tests), eslint . and tsc --noEmit pass.

Note: a negative value can still need parens where it is inlined: at the start of a line it can join the previous line by ASI, and x-macro() or -macro() gives x--0 / --Infinity. That already happens for any negative number today (x--1) and is part of #182, so I left it out here.

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@bardrop

bardrop commented Nov 12, 2026

Copy link
Copy Markdown
Author

Closing this. It was made with an AI coding agent, and the contributing guide asks for PR text in a person's own words. Sorry for the noise. The issue and the test case above still show the bug, if it helps.

@bardrop bardrop closed this Nov 12, 2026
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.

Macro values Infinity, NaN and -0 are inlined as null, null and 0

2 participants