@herb-tools/core 0.1.1 → 0.3.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.
- package/CHANGELOG.md +8 -0
- package/dist/herb-core.browser.js +576 -117
- package/dist/herb-core.browser.js.map +1 -1
- package/dist/herb-core.cjs +581 -117
- package/dist/herb-core.cjs.map +1 -1
- package/dist/herb-core.esm.js +576 -117
- package/dist/herb-core.esm.js.map +1 -1
- package/dist/herb-core.umd.js +581 -117
- package/dist/herb-core.umd.js.map +1 -1
- package/dist/types/errors.d.ts +16 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/lex-result.d.ts +13 -8
- package/dist/types/nodes.d.ts +206 -36
- package/dist/types/parse-result.d.ts +4 -4
- package/dist/types/result.d.ts +12 -4
- package/dist/types/visitor.d.ts +34 -9
- package/package.json +2 -11
- package/src/errors.ts +49 -14
- package/src/index.ts +1 -1
- package/src/lex-result.ts +15 -9
- package/src/nodes.ts +713 -95
- package/src/parse-result.ts +7 -5
- package/src/result.ts +14 -6
- package/src/visitor.ts +169 -10
- package/dist/types/ast.d.ts +0 -4
- package/dist/types/error.d.ts +0 -16
- package/dist/types/node.d.ts +0 -27
- package/src/ast.ts +0 -7
- package/src/error.ts +0 -38
- package/src/node.ts +0 -106
package/dist/types/nodes.d.ts
CHANGED
|
@@ -1,10 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Location } from "./location.js";
|
|
2
2
|
import { Token, SerializedToken } from "./token.js";
|
|
3
|
-
import { HerbError } from "./
|
|
4
|
-
import type {
|
|
5
|
-
|
|
3
|
+
import { HerbError } from "./errors.js";
|
|
4
|
+
import type { SerializedLocation } from "./location.js";
|
|
5
|
+
import type { SerializedHerbError } from "./errors.js";
|
|
6
|
+
import type { Visitor } from "./visitor.js";
|
|
6
7
|
export type SerializedNodeType = string;
|
|
7
|
-
export
|
|
8
|
+
export interface SerializedNode {
|
|
9
|
+
type: SerializedNodeType;
|
|
10
|
+
location: SerializedLocation;
|
|
11
|
+
errors: SerializedHerbError[];
|
|
12
|
+
}
|
|
13
|
+
export interface BaseNodeProps {
|
|
14
|
+
type: NodeType;
|
|
15
|
+
location: Location;
|
|
16
|
+
errors: HerbError[];
|
|
17
|
+
}
|
|
18
|
+
export type NodeType = "AST_DOCUMENT_NODE" | "AST_LITERAL_NODE" | "AST_HTML_OPEN_TAG_NODE" | "AST_HTML_CLOSE_TAG_NODE" | "AST_HTML_SELF_CLOSE_TAG_NODE" | "AST_HTML_ELEMENT_NODE" | "AST_HTML_ATTRIBUTE_VALUE_NODE" | "AST_HTML_ATTRIBUTE_NAME_NODE" | "AST_HTML_ATTRIBUTE_NODE" | "AST_HTML_TEXT_NODE" | "AST_HTML_COMMENT_NODE" | "AST_HTML_DOCTYPE_NODE" | "AST_WHITESPACE_NODE" | "AST_ERB_CONTENT_NODE" | "AST_ERB_END_NODE" | "AST_ERB_ELSE_NODE" | "AST_ERB_IF_NODE" | "AST_ERB_BLOCK_NODE" | "AST_ERB_WHEN_NODE" | "AST_ERB_CASE_NODE" | "AST_ERB_CASE_MATCH_NODE" | "AST_ERB_WHILE_NODE" | "AST_ERB_UNTIL_NODE" | "AST_ERB_FOR_NODE" | "AST_ERB_RESCUE_NODE" | "AST_ERB_ENSURE_NODE" | "AST_ERB_BEGIN_NODE" | "AST_ERB_UNLESS_NODE" | "AST_ERB_YIELD_NODE" | "AST_ERB_IN_NODE";
|
|
19
|
+
export declare abstract class Node implements BaseNodeProps {
|
|
20
|
+
readonly type: NodeType;
|
|
21
|
+
readonly location: Location;
|
|
22
|
+
readonly errors: HerbError[];
|
|
23
|
+
static from(node: SerializedNode): Node;
|
|
24
|
+
constructor(type: NodeType, location: Location, errors: HerbError[]);
|
|
25
|
+
toJSON(): SerializedNode;
|
|
26
|
+
inspect(): string;
|
|
27
|
+
get isSingleLine(): boolean;
|
|
28
|
+
abstract treeInspect(indent?: number): string;
|
|
29
|
+
abstract recursiveErrors(): HerbError[];
|
|
30
|
+
abstract accept(visitor: Visitor): void;
|
|
31
|
+
abstract childNodes(): (Node | null | undefined)[];
|
|
32
|
+
abstract compactChildNodes(): Node[];
|
|
33
|
+
protected inspectArray(array: (Node | HerbError)[] | null | undefined, prefix: string): string;
|
|
34
|
+
protected inspectNode(node: Node | HerbError | undefined | null, prefix: string, prefix2?: string, last?: boolean, trailingNewline?: boolean): string;
|
|
35
|
+
}
|
|
8
36
|
export interface SerializedDocumentNode extends SerializedNode {
|
|
9
37
|
type: "AST_DOCUMENT_NODE";
|
|
10
38
|
children: SerializedNode[];
|
|
@@ -16,7 +44,9 @@ export declare class DocumentNode extends Node {
|
|
|
16
44
|
readonly children: Node[];
|
|
17
45
|
static from(data: SerializedDocumentNode): DocumentNode;
|
|
18
46
|
constructor(props: DocumentNodeProps);
|
|
19
|
-
|
|
47
|
+
accept(visitor: Visitor): void;
|
|
48
|
+
childNodes(): (Node | null | undefined)[];
|
|
49
|
+
compactChildNodes(): Node[];
|
|
20
50
|
recursiveErrors(): HerbError[];
|
|
21
51
|
toJSON(): SerializedDocumentNode;
|
|
22
52
|
treeInspect(): string;
|
|
@@ -32,7 +62,9 @@ export declare class LiteralNode extends Node {
|
|
|
32
62
|
readonly content: string;
|
|
33
63
|
static from(data: SerializedLiteralNode): LiteralNode;
|
|
34
64
|
constructor(props: LiteralNodeProps);
|
|
35
|
-
|
|
65
|
+
accept(visitor: Visitor): void;
|
|
66
|
+
childNodes(): (Node | null | undefined)[];
|
|
67
|
+
compactChildNodes(): Node[];
|
|
36
68
|
recursiveErrors(): HerbError[];
|
|
37
69
|
toJSON(): SerializedLiteralNode;
|
|
38
70
|
treeInspect(): string;
|
|
@@ -60,7 +92,9 @@ export declare class HTMLOpenTagNode extends Node {
|
|
|
60
92
|
readonly is_void: boolean;
|
|
61
93
|
static from(data: SerializedHTMLOpenTagNode): HTMLOpenTagNode;
|
|
62
94
|
constructor(props: HTMLOpenTagNodeProps);
|
|
63
|
-
|
|
95
|
+
accept(visitor: Visitor): void;
|
|
96
|
+
childNodes(): (Node | null | undefined)[];
|
|
97
|
+
compactChildNodes(): Node[];
|
|
64
98
|
recursiveErrors(): HerbError[];
|
|
65
99
|
toJSON(): SerializedHTMLOpenTagNode;
|
|
66
100
|
treeInspect(): string;
|
|
@@ -82,7 +116,9 @@ export declare class HTMLCloseTagNode extends Node {
|
|
|
82
116
|
readonly tag_closing: Token | null;
|
|
83
117
|
static from(data: SerializedHTMLCloseTagNode): HTMLCloseTagNode;
|
|
84
118
|
constructor(props: HTMLCloseTagNodeProps);
|
|
85
|
-
|
|
119
|
+
accept(visitor: Visitor): void;
|
|
120
|
+
childNodes(): (Node | null | undefined)[];
|
|
121
|
+
compactChildNodes(): Node[];
|
|
86
122
|
recursiveErrors(): HerbError[];
|
|
87
123
|
toJSON(): SerializedHTMLCloseTagNode;
|
|
88
124
|
treeInspect(): string;
|
|
@@ -98,19 +134,21 @@ export interface SerializedHTMLSelfCloseTagNode extends SerializedNode {
|
|
|
98
134
|
export interface HTMLSelfCloseTagNodeProps extends BaseNodeProps {
|
|
99
135
|
tag_opening: Token | null;
|
|
100
136
|
tag_name: Token | null;
|
|
101
|
-
attributes:
|
|
137
|
+
attributes: any[];
|
|
102
138
|
tag_closing: Token | null;
|
|
103
139
|
is_void: boolean;
|
|
104
140
|
}
|
|
105
141
|
export declare class HTMLSelfCloseTagNode extends Node {
|
|
106
142
|
readonly tag_opening: Token | null;
|
|
107
143
|
readonly tag_name: Token | null;
|
|
108
|
-
readonly attributes:
|
|
144
|
+
readonly attributes: any[];
|
|
109
145
|
readonly tag_closing: Token | null;
|
|
110
146
|
readonly is_void: boolean;
|
|
111
147
|
static from(data: SerializedHTMLSelfCloseTagNode): HTMLSelfCloseTagNode;
|
|
112
148
|
constructor(props: HTMLSelfCloseTagNodeProps);
|
|
113
|
-
|
|
149
|
+
accept(visitor: Visitor): void;
|
|
150
|
+
childNodes(): (Node | null | undefined)[];
|
|
151
|
+
compactChildNodes(): Node[];
|
|
114
152
|
recursiveErrors(): HerbError[];
|
|
115
153
|
toJSON(): SerializedHTMLSelfCloseTagNode;
|
|
116
154
|
treeInspect(): string;
|
|
@@ -138,7 +176,9 @@ export declare class HTMLElementNode extends Node {
|
|
|
138
176
|
readonly is_void: boolean;
|
|
139
177
|
static from(data: SerializedHTMLElementNode): HTMLElementNode;
|
|
140
178
|
constructor(props: HTMLElementNodeProps);
|
|
141
|
-
|
|
179
|
+
accept(visitor: Visitor): void;
|
|
180
|
+
childNodes(): (Node | null | undefined)[];
|
|
181
|
+
compactChildNodes(): Node[];
|
|
142
182
|
recursiveErrors(): HerbError[];
|
|
143
183
|
toJSON(): SerializedHTMLElementNode;
|
|
144
184
|
treeInspect(): string;
|
|
@@ -163,7 +203,9 @@ export declare class HTMLAttributeValueNode extends Node {
|
|
|
163
203
|
readonly quoted: boolean;
|
|
164
204
|
static from(data: SerializedHTMLAttributeValueNode): HTMLAttributeValueNode;
|
|
165
205
|
constructor(props: HTMLAttributeValueNodeProps);
|
|
166
|
-
|
|
206
|
+
accept(visitor: Visitor): void;
|
|
207
|
+
childNodes(): (Node | null | undefined)[];
|
|
208
|
+
compactChildNodes(): Node[];
|
|
167
209
|
recursiveErrors(): HerbError[];
|
|
168
210
|
toJSON(): SerializedHTMLAttributeValueNode;
|
|
169
211
|
treeInspect(): string;
|
|
@@ -179,7 +221,9 @@ export declare class HTMLAttributeNameNode extends Node {
|
|
|
179
221
|
readonly name: Token | null;
|
|
180
222
|
static from(data: SerializedHTMLAttributeNameNode): HTMLAttributeNameNode;
|
|
181
223
|
constructor(props: HTMLAttributeNameNodeProps);
|
|
182
|
-
|
|
224
|
+
accept(visitor: Visitor): void;
|
|
225
|
+
childNodes(): (Node | null | undefined)[];
|
|
226
|
+
compactChildNodes(): Node[];
|
|
183
227
|
recursiveErrors(): HerbError[];
|
|
184
228
|
toJSON(): SerializedHTMLAttributeNameNode;
|
|
185
229
|
treeInspect(): string;
|
|
@@ -201,7 +245,9 @@ export declare class HTMLAttributeNode extends Node {
|
|
|
201
245
|
readonly value: Node | null;
|
|
202
246
|
static from(data: SerializedHTMLAttributeNode): HTMLAttributeNode;
|
|
203
247
|
constructor(props: HTMLAttributeNodeProps);
|
|
204
|
-
|
|
248
|
+
accept(visitor: Visitor): void;
|
|
249
|
+
childNodes(): (Node | null | undefined)[];
|
|
250
|
+
compactChildNodes(): Node[];
|
|
205
251
|
recursiveErrors(): HerbError[];
|
|
206
252
|
toJSON(): SerializedHTMLAttributeNode;
|
|
207
253
|
treeInspect(): string;
|
|
@@ -217,7 +263,9 @@ export declare class HTMLTextNode extends Node {
|
|
|
217
263
|
readonly content: string;
|
|
218
264
|
static from(data: SerializedHTMLTextNode): HTMLTextNode;
|
|
219
265
|
constructor(props: HTMLTextNodeProps);
|
|
220
|
-
|
|
266
|
+
accept(visitor: Visitor): void;
|
|
267
|
+
childNodes(): (Node | null | undefined)[];
|
|
268
|
+
compactChildNodes(): Node[];
|
|
221
269
|
recursiveErrors(): HerbError[];
|
|
222
270
|
toJSON(): SerializedHTMLTextNode;
|
|
223
271
|
treeInspect(): string;
|
|
@@ -239,7 +287,9 @@ export declare class HTMLCommentNode extends Node {
|
|
|
239
287
|
readonly comment_end: Token | null;
|
|
240
288
|
static from(data: SerializedHTMLCommentNode): HTMLCommentNode;
|
|
241
289
|
constructor(props: HTMLCommentNodeProps);
|
|
242
|
-
|
|
290
|
+
accept(visitor: Visitor): void;
|
|
291
|
+
childNodes(): (Node | null | undefined)[];
|
|
292
|
+
compactChildNodes(): Node[];
|
|
243
293
|
recursiveErrors(): HerbError[];
|
|
244
294
|
toJSON(): SerializedHTMLCommentNode;
|
|
245
295
|
treeInspect(): string;
|
|
@@ -261,7 +311,9 @@ export declare class HTMLDoctypeNode extends Node {
|
|
|
261
311
|
readonly tag_closing: Token | null;
|
|
262
312
|
static from(data: SerializedHTMLDoctypeNode): HTMLDoctypeNode;
|
|
263
313
|
constructor(props: HTMLDoctypeNodeProps);
|
|
264
|
-
|
|
314
|
+
accept(visitor: Visitor): void;
|
|
315
|
+
childNodes(): (Node | null | undefined)[];
|
|
316
|
+
compactChildNodes(): Node[];
|
|
265
317
|
recursiveErrors(): HerbError[];
|
|
266
318
|
toJSON(): SerializedHTMLDoctypeNode;
|
|
267
319
|
treeInspect(): string;
|
|
@@ -277,7 +329,9 @@ export declare class WhitespaceNode extends Node {
|
|
|
277
329
|
readonly value: Token | null;
|
|
278
330
|
static from(data: SerializedWhitespaceNode): WhitespaceNode;
|
|
279
331
|
constructor(props: WhitespaceNodeProps);
|
|
280
|
-
|
|
332
|
+
accept(visitor: Visitor): void;
|
|
333
|
+
childNodes(): (Node | null | undefined)[];
|
|
334
|
+
compactChildNodes(): Node[];
|
|
281
335
|
recursiveErrors(): HerbError[];
|
|
282
336
|
toJSON(): SerializedWhitespaceNode;
|
|
283
337
|
treeInspect(): string;
|
|
@@ -305,7 +359,9 @@ export declare class ERBContentNode extends Node {
|
|
|
305
359
|
readonly valid: boolean;
|
|
306
360
|
static from(data: SerializedERBContentNode): ERBContentNode;
|
|
307
361
|
constructor(props: ERBContentNodeProps);
|
|
308
|
-
|
|
362
|
+
accept(visitor: Visitor): void;
|
|
363
|
+
childNodes(): (Node | null | undefined)[];
|
|
364
|
+
compactChildNodes(): Node[];
|
|
309
365
|
recursiveErrors(): HerbError[];
|
|
310
366
|
toJSON(): SerializedERBContentNode;
|
|
311
367
|
treeInspect(): string;
|
|
@@ -327,7 +383,9 @@ export declare class ERBEndNode extends Node {
|
|
|
327
383
|
readonly tag_closing: Token | null;
|
|
328
384
|
static from(data: SerializedERBEndNode): ERBEndNode;
|
|
329
385
|
constructor(props: ERBEndNodeProps);
|
|
330
|
-
|
|
386
|
+
accept(visitor: Visitor): void;
|
|
387
|
+
childNodes(): (Node | null | undefined)[];
|
|
388
|
+
compactChildNodes(): Node[];
|
|
331
389
|
recursiveErrors(): HerbError[];
|
|
332
390
|
toJSON(): SerializedERBEndNode;
|
|
333
391
|
treeInspect(): string;
|
|
@@ -352,7 +410,9 @@ export declare class ERBElseNode extends Node {
|
|
|
352
410
|
readonly statements: Node[];
|
|
353
411
|
static from(data: SerializedERBElseNode): ERBElseNode;
|
|
354
412
|
constructor(props: ERBElseNodeProps);
|
|
355
|
-
|
|
413
|
+
accept(visitor: Visitor): void;
|
|
414
|
+
childNodes(): (Node | null | undefined)[];
|
|
415
|
+
compactChildNodes(): Node[];
|
|
356
416
|
recursiveErrors(): HerbError[];
|
|
357
417
|
toJSON(): SerializedERBElseNode;
|
|
358
418
|
treeInspect(): string;
|
|
@@ -383,7 +443,9 @@ export declare class ERBIfNode extends Node {
|
|
|
383
443
|
readonly end_node: Node | null;
|
|
384
444
|
static from(data: SerializedERBIfNode): ERBIfNode;
|
|
385
445
|
constructor(props: ERBIfNodeProps);
|
|
386
|
-
|
|
446
|
+
accept(visitor: Visitor): void;
|
|
447
|
+
childNodes(): (Node | null | undefined)[];
|
|
448
|
+
compactChildNodes(): Node[];
|
|
387
449
|
recursiveErrors(): HerbError[];
|
|
388
450
|
toJSON(): SerializedERBIfNode;
|
|
389
451
|
treeInspect(): string;
|
|
@@ -411,7 +473,9 @@ export declare class ERBBlockNode extends Node {
|
|
|
411
473
|
readonly end_node: Node | null;
|
|
412
474
|
static from(data: SerializedERBBlockNode): ERBBlockNode;
|
|
413
475
|
constructor(props: ERBBlockNodeProps);
|
|
414
|
-
|
|
476
|
+
accept(visitor: Visitor): void;
|
|
477
|
+
childNodes(): (Node | null | undefined)[];
|
|
478
|
+
compactChildNodes(): Node[];
|
|
415
479
|
recursiveErrors(): HerbError[];
|
|
416
480
|
toJSON(): SerializedERBBlockNode;
|
|
417
481
|
treeInspect(): string;
|
|
@@ -436,7 +500,9 @@ export declare class ERBWhenNode extends Node {
|
|
|
436
500
|
readonly statements: Node[];
|
|
437
501
|
static from(data: SerializedERBWhenNode): ERBWhenNode;
|
|
438
502
|
constructor(props: ERBWhenNodeProps);
|
|
439
|
-
|
|
503
|
+
accept(visitor: Visitor): void;
|
|
504
|
+
childNodes(): (Node | null | undefined)[];
|
|
505
|
+
compactChildNodes(): Node[];
|
|
440
506
|
recursiveErrors(): HerbError[];
|
|
441
507
|
toJSON(): SerializedERBWhenNode;
|
|
442
508
|
treeInspect(): string;
|
|
@@ -456,7 +522,7 @@ export interface ERBCaseNodeProps extends BaseNodeProps {
|
|
|
456
522
|
content: Token | null;
|
|
457
523
|
tag_closing: Token | null;
|
|
458
524
|
children: Node[];
|
|
459
|
-
conditions:
|
|
525
|
+
conditions: any[];
|
|
460
526
|
else_clause: Node | null;
|
|
461
527
|
end_node: Node | null;
|
|
462
528
|
}
|
|
@@ -465,16 +531,54 @@ export declare class ERBCaseNode extends Node {
|
|
|
465
531
|
readonly content: Token | null;
|
|
466
532
|
readonly tag_closing: Token | null;
|
|
467
533
|
readonly children: Node[];
|
|
468
|
-
readonly conditions:
|
|
534
|
+
readonly conditions: any[];
|
|
469
535
|
readonly else_clause: Node | null;
|
|
470
536
|
readonly end_node: Node | null;
|
|
471
537
|
static from(data: SerializedERBCaseNode): ERBCaseNode;
|
|
472
538
|
constructor(props: ERBCaseNodeProps);
|
|
473
|
-
|
|
539
|
+
accept(visitor: Visitor): void;
|
|
540
|
+
childNodes(): (Node | null | undefined)[];
|
|
541
|
+
compactChildNodes(): Node[];
|
|
474
542
|
recursiveErrors(): HerbError[];
|
|
475
543
|
toJSON(): SerializedERBCaseNode;
|
|
476
544
|
treeInspect(): string;
|
|
477
545
|
}
|
|
546
|
+
export interface SerializedERBCaseMatchNode extends SerializedNode {
|
|
547
|
+
type: "AST_ERB_CASE_MATCH_NODE";
|
|
548
|
+
tag_opening: SerializedToken | null;
|
|
549
|
+
content: SerializedToken | null;
|
|
550
|
+
tag_closing: SerializedToken | null;
|
|
551
|
+
children: SerializedNode[];
|
|
552
|
+
conditions: SerializedNode[];
|
|
553
|
+
else_clause: SerializedNode | null;
|
|
554
|
+
end_node: SerializedNode | null;
|
|
555
|
+
}
|
|
556
|
+
export interface ERBCaseMatchNodeProps extends BaseNodeProps {
|
|
557
|
+
tag_opening: Token | null;
|
|
558
|
+
content: Token | null;
|
|
559
|
+
tag_closing: Token | null;
|
|
560
|
+
children: Node[];
|
|
561
|
+
conditions: any[];
|
|
562
|
+
else_clause: Node | null;
|
|
563
|
+
end_node: Node | null;
|
|
564
|
+
}
|
|
565
|
+
export declare class ERBCaseMatchNode extends Node {
|
|
566
|
+
readonly tag_opening: Token | null;
|
|
567
|
+
readonly content: Token | null;
|
|
568
|
+
readonly tag_closing: Token | null;
|
|
569
|
+
readonly children: Node[];
|
|
570
|
+
readonly conditions: any[];
|
|
571
|
+
readonly else_clause: Node | null;
|
|
572
|
+
readonly end_node: Node | null;
|
|
573
|
+
static from(data: SerializedERBCaseMatchNode): ERBCaseMatchNode;
|
|
574
|
+
constructor(props: ERBCaseMatchNodeProps);
|
|
575
|
+
accept(visitor: Visitor): void;
|
|
576
|
+
childNodes(): (Node | null | undefined)[];
|
|
577
|
+
compactChildNodes(): Node[];
|
|
578
|
+
recursiveErrors(): HerbError[];
|
|
579
|
+
toJSON(): SerializedERBCaseMatchNode;
|
|
580
|
+
treeInspect(): string;
|
|
581
|
+
}
|
|
478
582
|
export interface SerializedERBWhileNode extends SerializedNode {
|
|
479
583
|
type: "AST_ERB_WHILE_NODE";
|
|
480
584
|
tag_opening: SerializedToken | null;
|
|
@@ -498,7 +602,9 @@ export declare class ERBWhileNode extends Node {
|
|
|
498
602
|
readonly end_node: Node | null;
|
|
499
603
|
static from(data: SerializedERBWhileNode): ERBWhileNode;
|
|
500
604
|
constructor(props: ERBWhileNodeProps);
|
|
501
|
-
|
|
605
|
+
accept(visitor: Visitor): void;
|
|
606
|
+
childNodes(): (Node | null | undefined)[];
|
|
607
|
+
compactChildNodes(): Node[];
|
|
502
608
|
recursiveErrors(): HerbError[];
|
|
503
609
|
toJSON(): SerializedERBWhileNode;
|
|
504
610
|
treeInspect(): string;
|
|
@@ -526,7 +632,9 @@ export declare class ERBUntilNode extends Node {
|
|
|
526
632
|
readonly end_node: Node | null;
|
|
527
633
|
static from(data: SerializedERBUntilNode): ERBUntilNode;
|
|
528
634
|
constructor(props: ERBUntilNodeProps);
|
|
529
|
-
|
|
635
|
+
accept(visitor: Visitor): void;
|
|
636
|
+
childNodes(): (Node | null | undefined)[];
|
|
637
|
+
compactChildNodes(): Node[];
|
|
530
638
|
recursiveErrors(): HerbError[];
|
|
531
639
|
toJSON(): SerializedERBUntilNode;
|
|
532
640
|
treeInspect(): string;
|
|
@@ -554,7 +662,9 @@ export declare class ERBForNode extends Node {
|
|
|
554
662
|
readonly end_node: Node | null;
|
|
555
663
|
static from(data: SerializedERBForNode): ERBForNode;
|
|
556
664
|
constructor(props: ERBForNodeProps);
|
|
557
|
-
|
|
665
|
+
accept(visitor: Visitor): void;
|
|
666
|
+
childNodes(): (Node | null | undefined)[];
|
|
667
|
+
compactChildNodes(): Node[];
|
|
558
668
|
recursiveErrors(): HerbError[];
|
|
559
669
|
toJSON(): SerializedERBForNode;
|
|
560
670
|
treeInspect(): string;
|
|
@@ -582,7 +692,9 @@ export declare class ERBRescueNode extends Node {
|
|
|
582
692
|
readonly subsequent: Node | null;
|
|
583
693
|
static from(data: SerializedERBRescueNode): ERBRescueNode;
|
|
584
694
|
constructor(props: ERBRescueNodeProps);
|
|
585
|
-
|
|
695
|
+
accept(visitor: Visitor): void;
|
|
696
|
+
childNodes(): (Node | null | undefined)[];
|
|
697
|
+
compactChildNodes(): Node[];
|
|
586
698
|
recursiveErrors(): HerbError[];
|
|
587
699
|
toJSON(): SerializedERBRescueNode;
|
|
588
700
|
treeInspect(): string;
|
|
@@ -607,7 +719,9 @@ export declare class ERBEnsureNode extends Node {
|
|
|
607
719
|
readonly statements: Node[];
|
|
608
720
|
static from(data: SerializedERBEnsureNode): ERBEnsureNode;
|
|
609
721
|
constructor(props: ERBEnsureNodeProps);
|
|
610
|
-
|
|
722
|
+
accept(visitor: Visitor): void;
|
|
723
|
+
childNodes(): (Node | null | undefined)[];
|
|
724
|
+
compactChildNodes(): Node[];
|
|
611
725
|
recursiveErrors(): HerbError[];
|
|
612
726
|
toJSON(): SerializedERBEnsureNode;
|
|
613
727
|
treeInspect(): string;
|
|
@@ -644,7 +758,9 @@ export declare class ERBBeginNode extends Node {
|
|
|
644
758
|
readonly end_node: Node | null;
|
|
645
759
|
static from(data: SerializedERBBeginNode): ERBBeginNode;
|
|
646
760
|
constructor(props: ERBBeginNodeProps);
|
|
647
|
-
|
|
761
|
+
accept(visitor: Visitor): void;
|
|
762
|
+
childNodes(): (Node | null | undefined)[];
|
|
763
|
+
compactChildNodes(): Node[];
|
|
648
764
|
recursiveErrors(): HerbError[];
|
|
649
765
|
toJSON(): SerializedERBBeginNode;
|
|
650
766
|
treeInspect(): string;
|
|
@@ -675,8 +791,62 @@ export declare class ERBUnlessNode extends Node {
|
|
|
675
791
|
readonly end_node: Node | null;
|
|
676
792
|
static from(data: SerializedERBUnlessNode): ERBUnlessNode;
|
|
677
793
|
constructor(props: ERBUnlessNodeProps);
|
|
678
|
-
|
|
794
|
+
accept(visitor: Visitor): void;
|
|
795
|
+
childNodes(): (Node | null | undefined)[];
|
|
796
|
+
compactChildNodes(): Node[];
|
|
679
797
|
recursiveErrors(): HerbError[];
|
|
680
798
|
toJSON(): SerializedERBUnlessNode;
|
|
681
799
|
treeInspect(): string;
|
|
682
800
|
}
|
|
801
|
+
export interface SerializedERBYieldNode extends SerializedNode {
|
|
802
|
+
type: "AST_ERB_YIELD_NODE";
|
|
803
|
+
tag_opening: SerializedToken | null;
|
|
804
|
+
content: SerializedToken | null;
|
|
805
|
+
tag_closing: SerializedToken | null;
|
|
806
|
+
}
|
|
807
|
+
export interface ERBYieldNodeProps extends BaseNodeProps {
|
|
808
|
+
tag_opening: Token | null;
|
|
809
|
+
content: Token | null;
|
|
810
|
+
tag_closing: Token | null;
|
|
811
|
+
}
|
|
812
|
+
export declare class ERBYieldNode extends Node {
|
|
813
|
+
readonly tag_opening: Token | null;
|
|
814
|
+
readonly content: Token | null;
|
|
815
|
+
readonly tag_closing: Token | null;
|
|
816
|
+
static from(data: SerializedERBYieldNode): ERBYieldNode;
|
|
817
|
+
constructor(props: ERBYieldNodeProps);
|
|
818
|
+
accept(visitor: Visitor): void;
|
|
819
|
+
childNodes(): (Node | null | undefined)[];
|
|
820
|
+
compactChildNodes(): Node[];
|
|
821
|
+
recursiveErrors(): HerbError[];
|
|
822
|
+
toJSON(): SerializedERBYieldNode;
|
|
823
|
+
treeInspect(): string;
|
|
824
|
+
}
|
|
825
|
+
export interface SerializedERBInNode extends SerializedNode {
|
|
826
|
+
type: "AST_ERB_IN_NODE";
|
|
827
|
+
tag_opening: SerializedToken | null;
|
|
828
|
+
content: SerializedToken | null;
|
|
829
|
+
tag_closing: SerializedToken | null;
|
|
830
|
+
statements: SerializedNode[];
|
|
831
|
+
}
|
|
832
|
+
export interface ERBInNodeProps extends BaseNodeProps {
|
|
833
|
+
tag_opening: Token | null;
|
|
834
|
+
content: Token | null;
|
|
835
|
+
tag_closing: Token | null;
|
|
836
|
+
statements: Node[];
|
|
837
|
+
}
|
|
838
|
+
export declare class ERBInNode extends Node {
|
|
839
|
+
readonly tag_opening: Token | null;
|
|
840
|
+
readonly content: Token | null;
|
|
841
|
+
readonly tag_closing: Token | null;
|
|
842
|
+
readonly statements: Node[];
|
|
843
|
+
static from(data: SerializedERBInNode): ERBInNode;
|
|
844
|
+
constructor(props: ERBInNodeProps);
|
|
845
|
+
accept(visitor: Visitor): void;
|
|
846
|
+
childNodes(): (Node | null | undefined)[];
|
|
847
|
+
compactChildNodes(): Node[];
|
|
848
|
+
recursiveErrors(): HerbError[];
|
|
849
|
+
toJSON(): SerializedERBInNode;
|
|
850
|
+
treeInspect(): string;
|
|
851
|
+
}
|
|
852
|
+
export declare function fromSerializedNode(node: SerializedNode): Node;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Result } from "./result.js";
|
|
2
2
|
import { DocumentNode } from "./nodes.js";
|
|
3
|
-
import { HerbError } from "./
|
|
3
|
+
import { HerbError } from "./errors.js";
|
|
4
4
|
import { HerbWarning } from "./warning.js";
|
|
5
|
-
import type { SerializedHerbError } from "./
|
|
5
|
+
import type { SerializedHerbError } from "./errors.js";
|
|
6
6
|
import type { SerializedHerbWarning } from "./warning.js";
|
|
7
7
|
import type { SerializedDocumentNode } from "./nodes.js";
|
|
8
8
|
import type { Visitor } from "./visitor.js";
|
|
@@ -37,12 +37,12 @@ export declare class ParseResult extends Result {
|
|
|
37
37
|
* Determines if the parsing failed.
|
|
38
38
|
* @returns `true` if there are errors, otherwise `false`.
|
|
39
39
|
*/
|
|
40
|
-
failed(): boolean;
|
|
40
|
+
get failed(): boolean;
|
|
41
41
|
/**
|
|
42
42
|
* Determines if the parsing was successful.
|
|
43
43
|
* @returns `true` if there are no errors, otherwise `false`.
|
|
44
44
|
*/
|
|
45
|
-
|
|
45
|
+
get successful(): boolean;
|
|
46
46
|
/**
|
|
47
47
|
* Returns a pretty-printed JSON string of the errors.
|
|
48
48
|
* @returns A string representation of the errors.
|
package/dist/types/result.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import { HerbError } from "./
|
|
1
|
+
import { HerbError } from "./errors.js";
|
|
2
2
|
import { HerbWarning } from "./warning.js";
|
|
3
|
-
export declare class Result {
|
|
3
|
+
export declare abstract class Result {
|
|
4
4
|
readonly source: string;
|
|
5
5
|
readonly warnings: HerbWarning[];
|
|
6
6
|
readonly errors: HerbError[];
|
|
7
7
|
constructor(source: string, warnings?: HerbWarning[], errors?: HerbError[]);
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Determines if the parsing was successful.
|
|
10
|
+
* @returns `true` if there are no errors, otherwise `false`.
|
|
11
|
+
*/
|
|
12
|
+
get successful(): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Determines if the parsing failed.
|
|
15
|
+
* @returns `true` if there are errors, otherwise `false`.
|
|
16
|
+
*/
|
|
17
|
+
get failed(): boolean;
|
|
10
18
|
}
|
package/dist/types/visitor.d.ts
CHANGED
|
@@ -1,11 +1,36 @@
|
|
|
1
|
-
import { Node } from "./
|
|
2
|
-
/**
|
|
3
|
-
* Represents a visitor that can traverse nodes.
|
|
4
|
-
*/
|
|
1
|
+
import { Node, DocumentNode, LiteralNode, HTMLOpenTagNode, HTMLCloseTagNode, HTMLSelfCloseTagNode, HTMLElementNode, HTMLAttributeValueNode, HTMLAttributeNameNode, HTMLAttributeNode, HTMLTextNode, HTMLCommentNode, HTMLDoctypeNode, WhitespaceNode, ERBContentNode, ERBEndNode, ERBElseNode, ERBIfNode, ERBBlockNode, ERBWhenNode, ERBCaseNode, ERBCaseMatchNode, ERBWhileNode, ERBUntilNode, ERBForNode, ERBRescueNode, ERBEnsureNode, ERBBeginNode, ERBUnlessNode, ERBYieldNode, ERBInNode } from "./nodes.js";
|
|
5
2
|
export declare class Visitor {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
visit(node: Node | null | undefined): void;
|
|
4
|
+
visitAll(nodes: (Node | null | undefined)[]): void;
|
|
5
|
+
visitChildNodes(node: Node): void;
|
|
6
|
+
visitDocumentNode(node: DocumentNode): void;
|
|
7
|
+
visitLiteralNode(node: LiteralNode): void;
|
|
8
|
+
visitHTMLOpenTagNode(node: HTMLOpenTagNode): void;
|
|
9
|
+
visitHTMLCloseTagNode(node: HTMLCloseTagNode): void;
|
|
10
|
+
visitHTMLSelfCloseTagNode(node: HTMLSelfCloseTagNode): void;
|
|
11
|
+
visitHTMLElementNode(node: HTMLElementNode): void;
|
|
12
|
+
visitHTMLAttributeValueNode(node: HTMLAttributeValueNode): void;
|
|
13
|
+
visitHTMLAttributeNameNode(node: HTMLAttributeNameNode): void;
|
|
14
|
+
visitHTMLAttributeNode(node: HTMLAttributeNode): void;
|
|
15
|
+
visitHTMLTextNode(node: HTMLTextNode): void;
|
|
16
|
+
visitHTMLCommentNode(node: HTMLCommentNode): void;
|
|
17
|
+
visitHTMLDoctypeNode(node: HTMLDoctypeNode): void;
|
|
18
|
+
visitWhitespaceNode(node: WhitespaceNode): void;
|
|
19
|
+
visitERBContentNode(node: ERBContentNode): void;
|
|
20
|
+
visitERBEndNode(node: ERBEndNode): void;
|
|
21
|
+
visitERBElseNode(node: ERBElseNode): void;
|
|
22
|
+
visitERBIfNode(node: ERBIfNode): void;
|
|
23
|
+
visitERBBlockNode(node: ERBBlockNode): void;
|
|
24
|
+
visitERBWhenNode(node: ERBWhenNode): void;
|
|
25
|
+
visitERBCaseNode(node: ERBCaseNode): void;
|
|
26
|
+
visitERBCaseMatchNode(node: ERBCaseMatchNode): void;
|
|
27
|
+
visitERBWhileNode(node: ERBWhileNode): void;
|
|
28
|
+
visitERBUntilNode(node: ERBUntilNode): void;
|
|
29
|
+
visitERBForNode(node: ERBForNode): void;
|
|
30
|
+
visitERBRescueNode(node: ERBRescueNode): void;
|
|
31
|
+
visitERBEnsureNode(node: ERBEnsureNode): void;
|
|
32
|
+
visitERBBeginNode(node: ERBBeginNode): void;
|
|
33
|
+
visitERBUnlessNode(node: ERBUnlessNode): void;
|
|
34
|
+
visitERBYieldNode(node: ERBYieldNode): void;
|
|
35
|
+
visitERBInNode(node: ERBInNode): void;
|
|
11
36
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@herb-tools/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://herb-tools.dev",
|
|
@@ -30,16 +30,7 @@
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {},
|
|
33
|
-
"devDependencies": {
|
|
34
|
-
"@rollup/plugin-json": "^6.1.0",
|
|
35
|
-
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
36
|
-
"@rollup/plugin-typescript": "^12.1.2",
|
|
37
|
-
"rimraf": "^6.0.1",
|
|
38
|
-
"rollup": "^4.35.0",
|
|
39
|
-
"tslib": "^2.8.1",
|
|
40
|
-
"typescript": "^5.8.2",
|
|
41
|
-
"vitest": "^3.0.0"
|
|
42
|
-
},
|
|
33
|
+
"devDependencies": {},
|
|
43
34
|
"files": [
|
|
44
35
|
"package.json",
|
|
45
36
|
"README.md",
|
package/src/errors.ts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
import { Location, SerializedLocation } from "./location.js"
|
|
5
5
|
import { Token, SerializedToken } from "./token.js"
|
|
6
|
-
import { HerbError, SerializedHerbError } from "./error.js"
|
|
7
6
|
|
|
8
7
|
type HerbDiagnostic = {
|
|
9
8
|
line: number
|
|
@@ -27,21 +26,40 @@ export type HerbErrorType =
|
|
|
27
26
|
|
|
28
27
|
export type SerializedErrorType = string
|
|
29
28
|
|
|
30
|
-
export
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
case "MISSING_CLOSING_TAG_ERROR": return MissingClosingTagError.from(error as SerializedMissingClosingTagError);
|
|
36
|
-
case "TAG_NAMES_MISMATCH_ERROR": return TagNamesMismatchError.from(error as SerializedTagNamesMismatchError);
|
|
37
|
-
case "QUOTES_MISMATCH_ERROR": return QuotesMismatchError.from(error as SerializedQuotesMismatchError);
|
|
38
|
-
case "VOID_ELEMENT_CLOSING_TAG_ERROR": return VoidElementClosingTagError.from(error as SerializedVoidElementClosingTagError);
|
|
39
|
-
case "UNCLOSED_ELEMENT_ERROR": return UnclosedElementError.from(error as SerializedUnclosedElementError);
|
|
40
|
-
case "RUBY_PARSE_ERROR": return RubyParseError.from(error as SerializedRubyParseError);
|
|
29
|
+
export interface SerializedHerbError {
|
|
30
|
+
type: string
|
|
31
|
+
message: string
|
|
32
|
+
location: SerializedLocation
|
|
33
|
+
}
|
|
41
34
|
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
export abstract class HerbError {
|
|
36
|
+
readonly type: string
|
|
37
|
+
readonly message: string
|
|
38
|
+
readonly location: Location
|
|
39
|
+
|
|
40
|
+
static from(error: SerializedHerbError): HerbError {
|
|
41
|
+
return fromSerializedError(error)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
constructor(type: string, message: string, location: Location) {
|
|
45
|
+
this.type = type
|
|
46
|
+
this.message = message
|
|
47
|
+
this.location = location
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
toJSON(): SerializedHerbError {
|
|
51
|
+
return {
|
|
52
|
+
type: this.type,
|
|
53
|
+
message: this.message,
|
|
54
|
+
location: this.location.toJSON(),
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
inspect(): string {
|
|
59
|
+
return this.treeInspect(0)
|
|
44
60
|
}
|
|
61
|
+
|
|
62
|
+
abstract treeInspect(indent?: number): string
|
|
45
63
|
}
|
|
46
64
|
|
|
47
65
|
export interface SerializedUnexpectedError {
|
|
@@ -818,3 +836,20 @@ export class RubyParseError extends HerbError {
|
|
|
818
836
|
}
|
|
819
837
|
}
|
|
820
838
|
|
|
839
|
+
|
|
840
|
+
export function fromSerializedError(error: SerializedHerbError): HerbError {
|
|
841
|
+
switch (error.type) {
|
|
842
|
+
case "UNEXPECTED_ERROR": return UnexpectedError.from(error as SerializedUnexpectedError);
|
|
843
|
+
case "UNEXPECTED_TOKEN_ERROR": return UnexpectedTokenError.from(error as SerializedUnexpectedTokenError);
|
|
844
|
+
case "MISSING_OPENING_TAG_ERROR": return MissingOpeningTagError.from(error as SerializedMissingOpeningTagError);
|
|
845
|
+
case "MISSING_CLOSING_TAG_ERROR": return MissingClosingTagError.from(error as SerializedMissingClosingTagError);
|
|
846
|
+
case "TAG_NAMES_MISMATCH_ERROR": return TagNamesMismatchError.from(error as SerializedTagNamesMismatchError);
|
|
847
|
+
case "QUOTES_MISMATCH_ERROR": return QuotesMismatchError.from(error as SerializedQuotesMismatchError);
|
|
848
|
+
case "VOID_ELEMENT_CLOSING_TAG_ERROR": return VoidElementClosingTagError.from(error as SerializedVoidElementClosingTagError);
|
|
849
|
+
case "UNCLOSED_ELEMENT_ERROR": return UnclosedElementError.from(error as SerializedUnclosedElementError);
|
|
850
|
+
case "RUBY_PARSE_ERROR": return RubyParseError.from(error as SerializedRubyParseError);
|
|
851
|
+
|
|
852
|
+
default:
|
|
853
|
+
throw new Error(`Unknown node type: ${error.type}`);
|
|
854
|
+
}
|
|
855
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export * from "./ast.js"
|
|
2
1
|
export * from "./backend.js"
|
|
3
2
|
export * from "./errors.js"
|
|
4
3
|
export * from "./herb-backend.js"
|
|
@@ -13,3 +12,4 @@ export * from "./token-list.js"
|
|
|
13
12
|
export * from "./token.js"
|
|
14
13
|
export * from "./util.js"
|
|
15
14
|
export * from "./visitor.js"
|
|
15
|
+
export * from "./warning.js"
|