Repository navigation
Harden and extend Yaml parsing and add Yaml.stringify - #10287
Merged
tim-smart merged 82 commits intoNov 8, 2026
Merged
Conversation
🦋 Changeset detectedLatest commit: 96ced1a The changes in this PR will be included in the next version bump. This PR includes changesets to release 33 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|
tim-smart
force-pushed
the
v4/next-minor
branch
from
November 3, 2026 20:54
2e13c53 to
5f5a4b3
Compare
effect-bot
force-pushed
the
v4/next-minor
branch
7 times, most recently
from
November 3, 2026 22:52
97a1ee1 to
10d44ad
Compare
effect-bot
force-pushed
the
agent/effect-bot/eff-3232-printer-round-trip
branch
from
November 3, 2026 23:14
60cde73 to
006a562
Compare
effect-bot
force-pushed
the
v4/next-minor
branch
from
November 3, 2026 23:39
2650b53 to
0a68f11
Compare
effect-bot
force-pushed
the
agent/effect-bot/eff-3232-printer-round-trip
branch
from
November 3, 2026 23:40
006a562 to
26e2c51
Compare
effect-bot
changed the base branch from
v4/next-minor
to
agent/architect-effect-bot/6a52aa9988ae
November 3, 2026 23:40
This was referenced Nov 3, 2026
Closed
effect-bot
force-pushed
the
agent/effect-bot/eff-3232-printer-round-trip
branch
from
November 3, 2026 23:43
26e2c51 to
58b2c97
Compare
effect-bot
force-pushed
the
agent/architect-effect-bot/6a52aa9988ae
branch
from
November 3, 2026 23:43
7a672f9 to
3b465fb
Compare
effect-bot
changed the base branch from
agent/architect-effect-bot/6a52aa9988ae
to
v4/next-minor
November 3, 2026 23:57
effect-bot
force-pushed
the
agent/effect-bot/eff-3232-printer-round-trip
branch
2 times, most recently
from
November 4, 2026 01:02
d1233b6 to
c05b323
Compare
effect-bot
force-pushed
the
v4/next-minor
branch
from
November 4, 2026 01:44
863f511 to
6d1f02e
Compare
effect-bot
force-pushed
the
agent/effect-bot/eff-3232-printer-round-trip
branch
from
November 4, 2026 02:08
32277cb to
3e92887
Compare
effect-bot
force-pushed
the
v4/next-minor
branch
from
November 4, 2026 02:27
6d1f02e to
e2514b1
Compare
Remove the Date-origin flag from the printer: toJSON is applied first, so a Date prints as its ISO string with the same quoting as any other string, and the printer no longer reads the original value after toJSON has replaced it.
…gle toJSON reads A ? followed directly by : starts a plain key, Yaml.stringify quotes the YAML 1.1 spellings ., +., -., ._, .e1 and 2024-1-1T1:1:1, and toJSON is read once and called with its receiver and key.
…loats and read toJSON once A ? directly before the : separator starts a plain key in block and flow mappings and flow sequence pairs, while ? followed by white space is still rejected as an explicit key. Yaml.stringify quotes YAML 1.1 floats without digits (., +., .e1) and timestamps with one-digit time fields, and reads a toJSON method once before calling it on its value.
…ON call Yaml.stringify must quote e1, E1 and -e+1, which yaml with version 1.1 reads as NaN, while e1x stays plain, and must invoke a toJSON method without reading its own call property.
…l property Yaml.stringify quotes e1, E1, +e1 and -e+1, which yaml with version 1.1 reads as NaN, while near misses such as e1x and e_1 stay plain. A toJSON method is invoked with Reflect.apply so its own call property is never consulted.
…ter depth limit A comment ends a plain scalar in a flow collection, so a quote on its continuation line is text and further content needs a comma. Yaml.stringify must fail with the path of a collection nested deeper than the 1000 levels Yaml.parse accepts, including empty collections and values deep enough to overflow the stack.
In a flow collection, a comment ends a plain scalar and a quote that starts a plain continuation line is text, as in block context. Yaml.stringify fails with the path of the first collection nested deeper than the 1000 levels Yaml.parse accepts, counting empty collections, instead of printing unparseable output or overflowing the stack. The changeset names the remaining behavior changes from the base.
After a --- marker, a quoted # in a flow collection is content and a following plain scalar continues on the next line, while a real comment ends the plain scalar. Both are checked through Yaml.parse and Yaml.parseAll.
… the marker The flag that ends flow and plain scalars at a comment came from scanning the whole line, where the --- marker hid a leading quote, so a quoted # was read as a comment. It now comes from the scan of the content after the marker that also strips its comment.
…chor nesting Yaml.stringify must print only the items an array had before their toJSON ran, as JSON.stringify does, so an item that appends to its own array cannot extend the output. A fresh Node process must parse 700 nested mappings whose anchors sit alone on the line after each key, which the base parser accepts. The fixture runs in a child process because a warmed test worker hides the overflow.
Yaml.stringify reads an array's length once before visiting its items, as JSON.stringify does, so a toJSON that appends to its own array no longer extends the output. Index iteration still keeps sparse positions. An empty block value now goes straight to the node on the following lines, from a mapping entry, a sequence entry, or properties alone on their line, instead of passing through parseNodeValue and parseValue. This takes three frames off each level of nested mappings whose anchors sit on their own lines, so a cold Node 26.13 process parses about 778 levels, up from 621 and above the base parser's 730.
Keys are their source text until they are set, with a plain << merging, so the key record and its helper are gone. The printer visits mapping entries once, emitting the header on the first printed entry, instead of collecting replacements first.
…ore flow key colons
effect-bot
force-pushed
the
agent/effect-bot/eff-3232-printer-round-trip
branch
from
November 8, 2026 07:27
287991d to
1df74de
Compare
Carry afterJsonNode from readQuoted through stripComment into findIndicator. The closing-line rescan now recognizes a colon after the quoted key as a value separator, keeping a literal hash in an adjacent quoted value. Other scans retain the default initial context.
Shorten the changeset with labeled migration bullets and concise examples. Remove redundant implementation commentary while retaining scanner context, resource-safety and performance rationale, API contracts, known limits and runnable examples.
tim-smart
added a commit
that referenced
this pull request
Nov 16, 2026
Co-authored-by: Tim Smart <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 16, 2026
Co-authored-by: Tim Smart <[email protected]>
effect-bot
added a commit
that referenced
this pull request
Nov 16, 2026
Co-authored-by: Tim Smart <[email protected]>
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.
The rest of the YAML expansion in one PR. #10271 (
Yaml.parseAll, directives, andResultfromYaml.parse) has already merged. This PR adds the parser hardening, new grammar, core schema tags, and the printer. It replaces #10276, #10279, #10282, #10283, #10284, #10285 and #10272, which were reviewed as separate stages and are now closed. Their commits are kept here unchanged.Parser
Input that used to be misread now fails or parses correctly
!!str,!!int,!!float,!!bool,!!null,!!seqand!!map.!!str 0x10is"0x10"and!!int "42"is42.!!int x,!!bool yesor!!seq {a: 1}.!custom), the non-specific tag!, verbatim tags (even for core tags), YAML 1.1 tags (!!binary,!!timestamp,!!set) and unknown!!tags.!inside a plain scalar (x!y) is still text.? key,{? a : 1},[? a]) fail with a clear error. The flow forms used to give the key"? a".&m <<,!!str 1,*name). Keys are plain or quoted scalars, so a quoted key such as"&a"is still text.{0x10: 1}gives"16".tRuE,1_000,0X1Fand-0x10are strings, and012,0644,5.and.5e3are numbers.:ends a plain scalar.{a: b: c}and[a: 1: 2]fail instead of giving"b: c"and"a: 1: 2", and{http://x: 1}gives the key"http://x". A flow mapping key without a value that contains:({a:1}) fails, since YAML reads it as the key"a:1"while JSON-like input means{a: 1}. An unquoted[or{inside a flow plain scalar fails ([a[, b],{a[}), asns-plain-safe-inrequires.EncodingErrorinstead of a stack overflow.-. A-followed by white space or a flow indicator ([- 1],[1, -]) fails, asns-plain-firstin §7.3.3 requires.key: - valuefails. It used to be read as the string"- value".[b # notefollowed byc]fails instead of giving["b c"], and a quote that starts a plain continuation line is text, so[b/'c # note/]gives["b 'c"].New grammar
- - value, §8.2.1), to any depth within the nesting limit.-\t1is an entry. A tab before a compact nested collection (-\t- 1) fails, because indentation can't use tabs.[a: 1, b]gives[{a: 1}, "b"], §7.4.1) and flow mapping keys without values ({a, b: 1}gives{a: null, b: 1}).Printer
null, booleans, numbers, strings, arrays and plain objects. The output is block style with keys in insertion order,{}and[]for empty collections, and a single trailing newline.parseand the core schema both read them back as the same string. Otherwise they are double-quoted with YAML escapes. Keys follow the same rule. As a convenience for YAML 1.1 readers, a fixed list of spellings is quoted as well: any letter case ofnull,true,false,yes,no,on,off,yandn, numbers such as1_000and0X1F, andYYYY-MM-DDdates with an optional full time, fraction and time zone. Other YAML 1.1 forms such as1:20or0b101print plain. Strings that start with---or...are quoted. Multiline strings print as|,|-or|+literal block scalars when that is safe..inf,-.inf,.nanand-0.0round-trip.JSON.stringify:toJSONis applied once per value with its key, andundefinedproperties are omitted. The order oftoJSONcalls across siblings, and whether a change one makes to another value shows up in the output, are unspecified.JSON.stringify, nothing is silently dropped. Bigints, functions, symbols, non-plain objects withouttoJSON, and cycles fail with anEncodingErrorthat names the path.parsedoes, fail with the path of the first collection past the limit, sostringifynever prints output thatparserejects and never overflows the stack.-, then an indented- item). Shared references print in full each time, without anchors.yaml2.9.1 reads, which is added as a devDependency ofpackages/effectfor that purpose, and read it back withYaml.parseorYaml.parseAll. Tests oftoJSONhandling, theindentoption and failures check the printed text or the error directly. The core schema patterns are shared between tag resolution and the printer.Remaining limits
The module docs describe these limits:
%TAGand other directives, and YAML versions other than 1.2, are not supported.a: &x/b: &x 1/c: *xgivesc: {b: 1}where YAML 1.2.2 gives1).EncodingError.Number.MAX_SAFE_INTEGERlose precision unless they are quoted.History
70bb91dbbajoins them, and it is the only place their changes conflicted. The printer was added after the parser code inYaml.ts, and the printer tests after the parser tests. The printer branch's olderparsewas dropped.minorchangeset,.changeset/yaml-parse-stringify.md, is the release note for the whole PR. It replaces the seven per-stage changesets and describes the changes againstv4/next-minor, with a migration bullet for each input that now reads differently or fails.a: !!seq/&items/- 1), including properties that start on the line after the key. The printer trims a literal block's trailing line breaks with a backward scan instead of/\n+$/, which retried from every newline of an interior run and took seconds on 64,000 newlines followed by text.---or..., and the release note entries for input that now fails.stringify(scalar classification, double-quoting and error paths) and one forparseandparseAll(single-pass line scans, character-code checks and plain key assignment). Neither changes behavior, tests or the changeset.toJSONresults in the printer, plain?keys, comments ending flow plain scalars, the printer depth limit, the matching release note entries, and the array length snapshot and the stack use of empty block values.toJSONcontract leaves sibling ordering and mutation unspecified, and the cold-process depth test and its fixture are gone, with the stack limit documented instead.:inside a plain scalar is text, so it no longer hides a following comment ({a:'b: # note/42}gives42), and a comment may separate a key that contains:from its value indicator.Validation
1df74de575on814015eafe:pnpm lint-fix,pnpm lint,pnpm check,pnpm jsdocs --check,pnpm circularand the fourYaml.tsdoctests pass. The encoding andMcpServertests pass 2,022 with 50 skipped, including all 415 inYaml.test.ts. The CLI, AI/MCP, ai-codegen and openapi-generator tests pass 2,362 with 53 skipped.git range-diff.Closes EFF-3232