Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104/** Render a {@link ValueNode} to TOML text. A clean child re-emits through {@link emitContentNode} so its original raw spelling (hex integers, quote style, datetime text) survives even when a sibling changed. A synthetic child renders canonically from its structure, reusing the shared array/inline-table assemblers so layout matches the from-scratch encoders. @module */
import type { ValueNode, } from './document.ts';import { assembleArrayParts, assembleInlineTableParts, emitContentNode,} from './emit-value.ts';import { encodeKey, } from './keys.ts';import type { CanonicalOptions, } from './types.ts';import { jsValueToTomlText, } from './values.ts';
/** Render `value` as TOML text at nesting `depth`. @returns Computed string. @example ```ts renderValueNode({ value: kv.value, options: edit.canonical, depth: 0, },); ``` */export function renderValueNode( { value, options, depth, }: { readonly value: ValueNode; readonly options: CanonicalOptions; readonly depth: number; },): string { if (value.origin .kind === 'clean') { return emitContentNode({ node: value.origin .astNode, options, depth, },); } if (value.kind === 'scalar') { return value.renderText ?? jsValueToTomlText({ input: value.jsValue, options, },); } if (value.kind === 'array') { /** Per-element text so the assembler can choose inline or multi-line layout. */ const parts = value.elements .map(function each(el,) { return renderValueNode({ value: el, options, depth: depth + 1, },); },); return assembleArrayParts({ parts, options, depth, },); } /** Per-entry `key = value` fragments for the inline-table assembler. */ const parts = value.entries .map(function each(entry,) { /** Encoded dotted key so each segment reuses canonical key spelling. */ const keyText = entry.keySegments .map(function eachSeg(seg,) { return encodeKey({ key: seg, },); },) .join('.',); return `${keyText} = ${ renderValueNode({ value: entry.value, options, depth: depth + 1, },) }`; },); return assembleInlineTableParts({ parts, },);}