3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-20 07:05:44 +01:00

Answer architecture round 1: name a non-string by typeof alone, name and comment what the seats could not read, file items 81 and 82

This commit is contained in:
2026-10-05 09:28:06 +02:00
committed by Lillem4n
parent 2c4fadbd8b
commit 41ac4510f5
12 changed files with 51 additions and 20 deletions
+10 -2
View File
@@ -8,7 +8,7 @@ import type { LinkDefinitions } from './inline-content.ts'
import { carryFenceType, readCarriedBlock } from '../opaque-carry.ts'
import { commonMarkSpelling, type SpellingMemo } from '../emit/adf-to-markdown.ts'
import { documentAttribute, documentName, documentSpelling, listBreakName, listBreakSpelling } from '../block-directive.ts'
import { describe, emptyKeys, nodeAttrs, nodeContent } from '../../adf/document.ts'
import { emptyKeys, nodeAttrs, nodeContent } from '../../adf/document.ts'
import { failure, faulted, positioned, success, type ConvertErrorPath, type ParseError, type Result, type SourcePosition } from '../../result.ts'
import { inlineLeaves } from '../plain/inline-reduction.ts'
import { languageSlot } from '../code-language.ts'
@@ -39,7 +39,7 @@ export function plainMarkdownToAdf(markdown: string): Result<AdfDocument, ParseE
}
function readDocument(markdown: string, flavour: Flavour): Result<AdfDocument, ParseError> {
if (typeof markdown !== 'string') return positioned(failure('not-a-string', `markdown is a string: found ${describe(markdown)}`, []), documentStart)
if (typeof markdown !== 'string') return positioned(failure('not-a-string', `markdown is a string: found ${typeName(markdown)}`, []), documentStart)
const parsed = parseBlocks(markdown)
const [only] = parsed.blocks
if (parsed.blocks.length === 1 && only?.kind === 'directive' && only.name === documentName) {
@@ -54,6 +54,14 @@ function readDocument(markdown: string, flavour: Flavour): Result<AdfDocument, P
return success(document)
}
// `typeof` alone, since anything more throws on a revoked Proxy.
function typeName(value: unknown): string {
if (value === null) return 'null'
const type = typeof value
if (type === 'undefined') return type
return type === 'object' ? 'an object' : `a ${type}`
}
function readBlocks(blocks: readonly Block[], reading: Reading, path: ConvertErrorPath, depth: number): Result<AdfNode[]> {
if (depth > largestNesting) return failure('unsupported-nesting-depth', `the input nests deeper than the ${largestNesting} levels the parser carries`, path)
const content: AdfNode[] = []