( kinds: NodeKind | listable<RootKind>, schema: unknown, opts: BaseParseOptions )
| 414 | this.node(schemaKindOf(schema), schema, opts) |
| 415 | |
| 416 | protected preparseNode( |
| 417 | kinds: NodeKind | listable<RootKind>, |
| 418 | schema: unknown, |
| 419 | opts: BaseParseOptions |
| 420 | ): BaseNode | NodeParseContextInput { |
| 421 | let kind: NodeKind = |
| 422 | typeof kinds === "string" ? kinds : schemaKindOf(schema, kinds) |
| 423 | |
| 424 | if (isNode(schema) && schema.kind === kind) return schema |
| 425 | |
| 426 | if (kind === "alias" && !opts?.prereduced) { |
| 427 | const { reference } = Alias.implementation.normalize( |
| 428 | schema as never, |
| 429 | this |
| 430 | ) |
| 431 | if (reference.startsWith("$")) { |
| 432 | const resolution = this.resolveRoot(reference.slice(1)) |
| 433 | schema = resolution |
| 434 | kind = resolution.kind |
| 435 | } |
| 436 | } else if (kind === "union" && hasDomain(schema, "object")) { |
| 437 | const branches = schemaBranchesOf(schema) |
| 438 | if (branches?.length === 1) { |
| 439 | schema = branches[0] |
| 440 | kind = schemaKindOf(schema) |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | if (isNode(schema) && schema.kind === kind) return schema |
| 445 | |
| 446 | const impl = nodeImplementationsByKind[kind] |
| 447 | const normalizedSchema = impl.normalize?.(schema, this) ?? schema |
| 448 | |
| 449 | // check again after normalization in case a node is a valid collapsed |
| 450 | // schema for the kind (e.g. sequence can collapse to element accepting a Node') |
| 451 | if (isNode(normalizedSchema)) { |
| 452 | return normalizedSchema.kind === kind ? |
| 453 | normalizedSchema |
| 454 | : throwMismatchedNodeRootError(kind, normalizedSchema.kind) |
| 455 | } |
| 456 | |
| 457 | return { |
| 458 | ...opts, |
| 459 | $: this, |
| 460 | kind, |
| 461 | def: normalizedSchema, |
| 462 | prefix: opts.alias ?? kind |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | bindReference<reference extends BaseNode | GenericRoot>( |
| 467 | reference: reference |
nothing calls this directly
no test coverage detected
searching dependent graphs…