1 | import type { Document } from '../doc/Document.js';
|
---|
2 | import type { ToJSOptions } from '../options.js';
|
---|
3 | import { Token } from '../parse/cst.js';
|
---|
4 | import type { StringifyContext } from '../stringify/stringify.js';
|
---|
5 | import type { Alias } from './Alias.js';
|
---|
6 | import { NODE_TYPE } from './identity.js';
|
---|
7 | import type { Scalar } from './Scalar.js';
|
---|
8 | import type { YAMLMap } from './YAMLMap.js';
|
---|
9 | import type { YAMLSeq } from './YAMLSeq.js';
|
---|
10 | export type Node<T = unknown> = Alias | Scalar<T> | YAMLMap<unknown, T> | YAMLSeq<T>;
|
---|
11 | /** Utility type mapper */
|
---|
12 | export type NodeType<T> = T extends string | number | bigint | boolean | null | undefined ? Scalar<T> : T extends Date ? Scalar<string | Date> : T extends Array<any> ? YAMLSeq<NodeType<T[number]>> : T extends {
|
---|
13 | [key: string]: any;
|
---|
14 | } ? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>> : T extends {
|
---|
15 | [key: number]: any;
|
---|
16 | } ? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>> : Node;
|
---|
17 | export type ParsedNode = Alias.Parsed | Scalar.Parsed | YAMLMap.Parsed | YAMLSeq.Parsed;
|
---|
18 | export type Range = [number, number, number];
|
---|
19 | export declare abstract class NodeBase {
|
---|
20 | readonly [NODE_TYPE]: symbol;
|
---|
21 | /** A comment on or immediately after this */
|
---|
22 | comment?: string | null;
|
---|
23 | /** A comment before this */
|
---|
24 | commentBefore?: string | null;
|
---|
25 | /**
|
---|
26 | * The `[start, value-end, node-end]` character offsets for the part of the
|
---|
27 | * source parsed into this node (undefined if not parsed). The `value-end`
|
---|
28 | * and `node-end` positions are themselves not included in their respective
|
---|
29 | * ranges.
|
---|
30 | */
|
---|
31 | range?: Range | null;
|
---|
32 | /** A blank line before this node and its commentBefore */
|
---|
33 | spaceBefore?: boolean;
|
---|
34 | /** The CST token that was composed into this node. */
|
---|
35 | srcToken?: Token;
|
---|
36 | /** A fully qualified tag, if required */
|
---|
37 | tag?: string;
|
---|
38 | /** A plain JS representation of this node */
|
---|
39 | abstract toJSON(): any;
|
---|
40 | abstract toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
|
---|
41 | constructor(type: symbol);
|
---|
42 | /** Create a copy of this node. */
|
---|
43 | clone(): NodeBase;
|
---|
44 | /** A plain JavaScript representation of this node. */
|
---|
45 | toJS(doc: Document<Node, boolean>, { mapAsMap, maxAliasCount, onAnchor, reviver }?: ToJSOptions): any;
|
---|
46 | }
|
---|