@nette/neon 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,227 @@
1
+ import { CommentPolicy, type PathSegment } from './editing.ts';
2
+ import { setItems, setParent, setSlots } from './internal.ts';
3
+ import { type Position, Token, type Trivia } from './token.ts';
4
+ import { Entity, type NeonValue } from './values.ts';
5
+ type Child = Node | Token;
6
+ export type NodeClass<T extends Node> = abstract new (...args: any[]) => T;
7
+ /** Base of all nodes of the syntax tree. */
8
+ export declare abstract class Node {
9
+ #private;
10
+ get parent(): Node | null;
11
+ /** The slots in order, without nulls. */
12
+ abstract getChildren(): Child[];
13
+ /** A deep copy without a parent; tokens keep their origin. */
14
+ abstract clone(): Node;
15
+ getTokens(): Token[];
16
+ abstract getFirstToken(): Token;
17
+ abstract getLastToken(): Token;
18
+ /** Current position of the first token, computed by a walk from the root. */
19
+ getPosition(): Position | null;
20
+ /** The source text of the node, with the trivia of its tokens. */
21
+ print(): string;
22
+ toString(): string;
23
+ /** Whether the node spans more than one line, its outer trivia not counted. */
24
+ isMultiLine(): boolean;
25
+ hasLeadingComment(): boolean;
26
+ /** Comments in the leading trivia of the first token. */
27
+ getLeadingComments(): Trivia[];
28
+ /** Comments in the trailing trivia of the last token. */
29
+ getTrailingComments(): Trivia[];
30
+ findAncestor<T extends Node>(type: NodeClass<T>): T | null;
31
+ getNextSibling(): Node | null;
32
+ getPreviousSibling(): Node | null;
33
+ /** Descendants of the class, in document order. */
34
+ find<T extends Node>(type: NodeClass<T>, predicate?: (node: T) => boolean): T[];
35
+ findFirst<T extends Node>(type: NodeClass<T>, predicate?: (node: T) => boolean): T | null;
36
+ /** @internal */
37
+ [setParent](parent: Node | null): void;
38
+ }
39
+ /** A node that has a value. */
40
+ export declare abstract class ValueNode extends Node {
41
+ abstract toValue(): NeonValue;
42
+ abstract clone(): ValueNode;
43
+ /** Puts the node into the slot of this one, which decides what that means; the node gets the trivia at the edges of this one in place of its own. */
44
+ replaceWith(node: ValueNode): void;
45
+ /** Takes the node out of the tree, with the trivia at its edges; the emptied slot gets null. */
46
+ detach(): this;
47
+ }
48
+ export declare class DocumentNode extends Node {
49
+ #private;
50
+ /** Whether removing the last item leaves null instead of an empty collection. */
51
+ nullable: boolean;
52
+ /** @internal */
53
+ constructor(value: ValueNode | null, endOfFile: Token);
54
+ get value(): ValueNode | null;
55
+ /** The same as setValue([], node): the node takes the place of the root, null empties the document. */
56
+ set value(node: ValueNode | null);
57
+ get endOfFile(): Token;
58
+ getChildren(): Child[];
59
+ getFirstToken(): Token;
60
+ getLastToken(): Token;
61
+ clone(): DocumentNode;
62
+ toValue(): NeonValue;
63
+ /** The item at the path of keys, the same keys decode() gives; a path continues into the attributes of an entity. */
64
+ findItem(path: readonly PathSegment[]): ArrayItemNode | null;
65
+ /** Writes the value at the path; a missing last key is added, unless create is false. */
66
+ setValue(path: readonly PathSegment[], value: unknown, options?: {
67
+ create?: boolean;
68
+ }): void;
69
+ /** Adds an item to the array at the path, without a key unless given one. */
70
+ addItem(path: readonly PathSegment[], value: unknown, options?: {
71
+ key?: string;
72
+ position?: number;
73
+ }): ArrayItemNode;
74
+ /** Removes the item at the path with the comments it owns. */
75
+ removeItem(path: readonly PathSegment[], options?: {
76
+ comments?: CommentPolicy;
77
+ nullable?: boolean;
78
+ mergeBlankLines?: boolean;
79
+ }): void;
80
+ /** Renames the key of the item at the path. */
81
+ setKey(path: readonly PathSegment[], key: string): void;
82
+ /** @internal Writes the slot as it is, for an edit that moves the trivia itself. */
83
+ [setSlots](slots: {
84
+ value: ValueNode | null;
85
+ }): void;
86
+ }
87
+ /** Base of the two kinds of arrays. */
88
+ export declare abstract class ArrayNode extends ValueNode {
89
+ #private;
90
+ get items(): readonly ArrayItemNode[];
91
+ /** Whether the array without items is a map, `{}`. */
92
+ protected abstract isEmptyMap(): boolean;
93
+ /** @internal Replaces the list; items that leave it lose their parent, new ones must have none. */
94
+ [setItems](items: readonly ArrayItemNode[]): void;
95
+ /** The item with the canonical key, as decode() would find it. */
96
+ findItem(key: string | number): ArrayItemNode | null;
97
+ /** Adds an item built from the value, at the end or before the item at the position. */
98
+ addItem(value: unknown, options?: {
99
+ key?: string;
100
+ position?: number;
101
+ }): ArrayItemNode;
102
+ /** Removes the item with the comments it owns. */
103
+ removeItem(item: ArrayItemNode, comments?: CommentPolicy): void;
104
+ /** Inserts an item taken out of a tree by remove(), reindented to its new place, with its comments. */
105
+ insert(position: number, item: ArrayItemNode): void;
106
+ toValue(): NeonValue;
107
+ }
108
+ /** The key of each item, explicit or implicit. */
109
+ export declare function itemKeys(items: readonly ArrayItemNode[]): string[];
110
+ export declare class BlockArrayNode extends ArrayNode {
111
+ /** @internal */
112
+ constructor(items: readonly ArrayItemNode[]);
113
+ protected isEmptyMap(): boolean;
114
+ getChildren(): Child[];
115
+ getFirstToken(): Token;
116
+ getLastToken(): Token;
117
+ clone(): BlockArrayNode;
118
+ }
119
+ export declare class InlineArrayNode extends ArrayNode {
120
+ #private;
121
+ /** @internal */
122
+ constructor(openBracket: Token, items: readonly ArrayItemNode[], closeBracket: Token);
123
+ protected isEmptyMap(): boolean;
124
+ get openBracket(): Token;
125
+ get closeBracket(): Token;
126
+ getChildren(): Child[];
127
+ getFirstToken(): Token;
128
+ getLastToken(): Token;
129
+ clone(): InlineArrayNode;
130
+ }
131
+ export declare class ArrayItemNode extends Node {
132
+ #private;
133
+ /** Whether removing the last item of the value leaves null instead of an empty collection. */
134
+ nullable: boolean;
135
+ /** @internal */
136
+ constructor(bullet: Token | null, key: StringNode | LiteralNode | null, colon: Token | null, value: ValueNode | null, separator?: Token | null);
137
+ get bullet(): Token | null;
138
+ get key(): StringNode | LiteralNode | null;
139
+ get colon(): Token | null;
140
+ get value(): ValueNode | null;
141
+ /** The same as setValue(node) with a node: the node takes the place of the value, null empties it. */
142
+ set value(node: ValueNode | null);
143
+ get separator(): Token | null;
144
+ /** @internal Writes the slots as they are, for an edit that moves the trivia itself. */
145
+ [setSlots](slots: {
146
+ bullet?: Token | null;
147
+ key?: StringNode | LiteralNode | null;
148
+ colon?: Token | null;
149
+ value?: ValueNode | null;
150
+ separator?: Token | null;
151
+ }): void;
152
+ getChildren(): Child[];
153
+ getFirstToken(): Token;
154
+ getLastToken(): Token;
155
+ clone(): ArrayItemNode;
156
+ /** The canonical key, or null for an item without a key. */
157
+ getKeyValue(): string | null;
158
+ /** The value of the item, null without one. */
159
+ getValue(): NeonValue;
160
+ /** The indentation of the line the item starts on. */
161
+ getIndentation(): string;
162
+ /**
163
+ * Writes the value: a value of the host or a node. Writing an equal value changes nothing; a new
164
+ * scalar keeps the style of the old one where it can.
165
+ */
166
+ setValue(value: unknown): void;
167
+ /** Renames the key. */
168
+ setKey(key: string): void;
169
+ /** Removes the item from its array, with the comments it owns. */
170
+ remove(comments?: CommentPolicy, mergeBlankLines?: boolean): void;
171
+ }
172
+ export declare class EntityNode extends ValueNode {
173
+ #private;
174
+ /** @internal */
175
+ constructor(value: ValueNode, attributes: InlineArrayNode | null);
176
+ get value(): ValueNode;
177
+ get attributes(): InlineArrayNode | null;
178
+ /** @internal */
179
+ [setSlots](slots: {
180
+ value?: ValueNode;
181
+ attributes?: InlineArrayNode;
182
+ }): void;
183
+ getChildren(): Child[];
184
+ getFirstToken(): Token;
185
+ getLastToken(): Token;
186
+ clone(): EntityNode;
187
+ toValue(): Entity;
188
+ }
189
+ export declare class EntityChainNode extends ValueNode {
190
+ #private;
191
+ /** @internal */
192
+ constructor(entities: readonly EntityNode[]);
193
+ get entities(): readonly EntityNode[];
194
+ /** @internal */
195
+ [setSlots](slots: {
196
+ entities: readonly EntityNode[];
197
+ }): void;
198
+ getChildren(): Child[];
199
+ getFirstToken(): Token;
200
+ getLastToken(): Token;
201
+ clone(): EntityChainNode;
202
+ toValue(): Entity;
203
+ }
204
+ export declare class StringNode extends ValueNode {
205
+ #private;
206
+ /** @internal */
207
+ constructor(token: Token);
208
+ get token(): Token;
209
+ getChildren(): Child[];
210
+ getFirstToken(): Token;
211
+ getLastToken(): Token;
212
+ clone(): StringNode;
213
+ toValue(): string;
214
+ }
215
+ export declare class LiteralNode extends ValueNode {
216
+ #private;
217
+ /** @internal */
218
+ constructor(token: Token);
219
+ get token(): Token;
220
+ getChildren(): Child[];
221
+ getFirstToken(): Token;
222
+ getLastToken(): Token;
223
+ clone(): LiteralNode;
224
+ /** The value of the literal; a key keeps words and dates as strings. */
225
+ toValue(isKey?: boolean): NeonValue;
226
+ }
227
+ export {};