Repository navigation
fix: print nested undefined unquoted in error messages - #1717
Merged
Merged
Conversation
printable serialized a nested undefined as the string "undefined", so
JSON.stringify quoted it and {a: undefined} printed the same as
{a: "undefined"}. Mark it the same way arktypeio#1626 marks bigints and strip
the quotes.
Member
|
Nice catch, thanks! Reusing the bigint marker for this is exactly right 🙌 |
ssalbdivad
approved these changes
Oct 27, 2026
ssalbdivad
pushed a commit
that referenced
this pull request
Oct 27, 2026
printable serialized a nested undefined as the string "undefined", so
JSON.stringify quoted it and {a: undefined} printed the same as
{a: "undefined"}. Mark it the same way bigints are marked and strip the
quotes.
Ported from main. The narrow error test is left out: errors here
describe arrays rather than print them. The aot shadow snapshot now
shows the unquoted undefined.
ssalbdivad
added a commit
that referenced
this pull request
Oct 27, 2026
ssalbdivad
added a commit
that referenced
this pull request
Oct 27, 2026
ssalbdivad
added a commit
that referenced
this pull request
Oct 28, 2026
A precompiled program imports a few functions from @ark/util's build
(isValidDate for a Date key, isUuid, isIso8601, isIpv6, ...). Importing any
of them kept about 850 B gz of util the program never calls: objectKindOf,
builtinsOf and its constructor tables, printable's options, baseNameOf and
isDotAccessible. esbuild keeps a top-level statement it can't prove free of
side effects, and three in the util chunk read as possible effects once
the chunk's consts are `var`s it no longer folds: printableOpts' template
`${unquotedMarker}undefined` (a template over a binding may call toString),
`new RegExp(\`...${unquotedMarker}...\`)`, and nonFiniteNumbers' Number.NaN
member reads. Those roots then held everything they referenced.
The marker is now written as a literal where it's used, the pattern is a
regex literal and nonFiniteNumbers reads the NaN and Infinity globals.
Source-mode builds (the ark-ts condition, which the tests and the earlier
size measurements used) never showed this, as a module-level const folds
there; it entered with #1717's marker and the non-finite keywords.
Built rows (tools/sizes.ts, gz): sb 2753 -> 1908, shop 6686 -> 6218,
saas 11140 -> 10667; form, login, moltar and Sury's rows carry no util and
are unchanged. `export { isValidDate } from "@ark/util"` built: 1667 -> 215.
ssalbdivad
added a commit
that referenced
this pull request
Oct 28, 2026
…d than from source A precompiled program imports a few of arktype/runtime's exports, which a bundler tree-shakes from the build's chunks. A statement esbuild can't prove free of side effects, as #1717's `${unquotedMarker}` template and `new RegExp` and the non-finite keywords' Number.NaN reads were, keeps everything it reaches in every program importing anything from the chunk: about 850 B gz of util in each program checking a Date, UUID, ISO date or IP, which the tests and the source-mode size runs (the ark-ts condition, where a module const folds) never showed. testBuild now bundles each runtime export alone from the build and from source and fails where the build is over a quarter larger (plus 32 B for the `var` declarations a chunk lowers consts to; today's widest gap is 1.13 on a 63 B export). Appending a kept template to the util chunk by hand fails it at 8393 vs 4364 B. The check adds about 5 s.
ssalbdivad
added a commit
that referenced
this pull request
Nov 18, 2026
Bumps all publishable packages and documents the change merged since 2.2.9: - print a nested undefined unquoted in error messages (#1717, @youdie006) The last 2.x release before main becomes the 3.0 line with the 3.0.0-beta.0 release, so this fix reaches arktype 2 users. @ark/attest's checker option already shipped in 0.58.0, so attest only takes the bumped pins.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#1626 stopped nested bigints from printing as strings, but nested
undefinedstill goes through_serializeas the string"undefined", soJSON.stringifyquotes it and error messages can't tell it apart from the string:This gives
undefinedthe same private-use marker as bigints inprintableOptsand strips the quotes around it in the samereplace. I renamedbigIntMarkertounquotedMarkersince it now marks both; the marker has to be declared beforeprintableOptsbecauseonUndefinedis a plain string. Top-levelprintable(undefined),quoteKeys: falseand attest'ssnapshot()(its ownonUndefined) are unchanged.Tests: two
printablecases (each with a"undefined"string next to it) and anarrowerror case next to the bigint one; all three fail without the change. Locallypnpm test(1792 passing),pnpm typecheckRepo,pnpm checkPrettierand eslint on the changed files pass; I did not run the fullpnpm prCheckschain (build, docs, benches, TS versions, integration).Written with AI assistance (Claude); I have reviewed the change.