Merged
Conversation
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.
Summary
c.json()previously failed for object array arguments in two ways:return c.json([{ name: "Alice", age: 30 }])→ compile error: "JSON.stringify: unsupported argument type"const items = [...]; return c.json(items)→ garbage output like[2.140390922e-314]Both cases now produce correct JSON:
[{"name":"Alice","age":30.0}]Root Causes
Literal arrays:
generateStringifyArgWithSpaceshad no handler forarg.type === "array", falling through to the unsupported-type error.Variable arrays:
resolveExpressionTypedefaulted object-element arrays tonumber[]type. This caused the variable to be allocated asSymbolKind.Arrayinstead ofSymbolKind.ObjectArray, so the JSON serializer read the object pointer as adoubleand printed it as a float.Changes
type-inference.ts: detectfirstElem.type === "object"in array literals and returngetArrayType("object")so the variable allocator treats them as object arraysvariable-allocator.ts: when allocating an object array variable with no registered interface, extract field metadata from the inline array literal (extractInlineObjectArrayMeta) and store it inObjectArrayMetadatajson.ts: addarg.type === "array"dispatch for literal object arrays; fall back to metadata-based serialization for variables without a registered interfacejson-array.ts(new): standalone helpersstringifyObjectArrayLiteralandstringifyObjectArrayWithMeta— extracted to a separate file to keepjson.tsfrom growing further, and implemented as free functions (not class methods) to avoid Stage 0 closure-over-thisissuesTest
tests/fixtures/network/context-json-array.ts— covers both the literal and variable cases end-to-end through the HTTP router.