Repository navigation
JsonValue by key: value["name"] and value[0] - #86
Merged
Merged
Conversation
JsonValue declares `[key: number | string]: JsonValue`, so `value["name"]`
and `value[0]` read through get(), and `value["name"] = member` and
`value[0] = element` write through set(). get and set take a number for an
array and a string for an object; `get("x")` and `set("x", v)` work as
before, and `at(i)` stays.
Writing past an array's end leaves JSON nulls before the new element, as in
JavaScript; a negative index is a RangeError. A key that names a JsonValue
member (length, kind, keys, ...) is that member, as in TypeScript.
Literal string keys need TypeScriptCompiler#799 and #800. Under -mm=own two
writes by key to a JsonValue crash the compiler (a known issue), so
tests/json_index.ts writes by key under the other models only, and the
README says to use set() there.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ASDAlexander77
added a commit
that referenced
this pull request
Nov 9, 2026
Conflicts with #86 (JsonValue by key) in JsonValue's set() and push(), in src/lib.ts and src/lib.d.ts: set() takes #86's `key: number | string` and body, with this branch's `: this` result and no @Lends("this"); push() returns `this` as here. Tested with tslang built from TypeScriptCompiler main plus #800 and #801: every test passes in release JIT under gc, rc, none and own (json.ts with its chains, json_index.ts). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
JsonValuedeclares[key: number | string]: JsonValue.value["name"]andvalue[0]read throughget().value["name"] = memberandvalue[0] = elementwrite throughset().getandsetnow takenumber | string: a number for an array, a string for an object.get("x")andset("x", v)work as before, andat(i)stays.RangeError.JsonValuemember (length,kind,keys, ...) is that member, as in TypeScript.tests/json_index.ts, and a README note in the JSON section.Depends on a compiler release
Literal string keys (
value["name"]) need ASDAlexander77/TypeScriptCompiler#799 (merged) and ASDAlexander77/TypeScriptCompiler#800. This repository's CI compiles with the newest compiler release,v0.0-pre-alpha120, which has neither. Sojson_index.tsfails on every CI leg until a release includes both. Re-run CI after that release;compiler_taginworkflow_dispatchcan pick it.Known issue under -mm=own
Two writes by key to a
JsonValuecrash tslang.exe under-mm=ownwhen it builds the exe. This happens on compilermaintoo, and also with variable keys. Directset()calls work, and so does a test class of the same shape, in one file or across a shared library. Sojson_index.tswrites by key under the other models only, and the README says to useset()underownfor now.Testing
I built the library for gc, rc, none and own with a compiler that has #799 and #800, and ran every test in release JIT. All pass.
console_readLineandstdio_byteswere run with their.stdinpiped in. Debug wasn't run locally.🤖 Generated with Claude Code