@herb-tools/core 0.1.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 +3 -0
- package/README.md +9 -0
- package/dist/herb-core.browser.js +2704 -0
- package/dist/herb-core.browser.js.map +1 -0
- package/dist/herb-core.cjs +2759 -0
- package/dist/herb-core.cjs.map +1 -0
- package/dist/herb-core.esm.js +2704 -0
- package/dist/herb-core.esm.js.map +1 -0
- package/dist/herb-core.umd.js +2765 -0
- package/dist/herb-core.umd.js.map +1 -0
- package/dist/types/ast.d.ts +4 -0
- package/dist/types/backend.d.ts +24 -0
- package/dist/types/error.d.ts +16 -0
- package/dist/types/errors.d.ts +222 -0
- package/dist/types/herb-backend.d.ts +87 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/lex-result.d.ts +50 -0
- package/dist/types/location.d.ts +18 -0
- package/dist/types/node.d.ts +27 -0
- package/dist/types/nodes.d.ts +682 -0
- package/dist/types/parse-result.d.ts +62 -0
- package/dist/types/position.d.ts +15 -0
- package/dist/types/range.d.ts +12 -0
- package/dist/types/result.d.ts +10 -0
- package/dist/types/token-list.d.ts +16 -0
- package/dist/types/token.d.ts +22 -0
- package/dist/types/util.d.ts +2 -0
- package/dist/types/visitor.d.ts +11 -0
- package/dist/types/warning.d.ts +11 -0
- package/package.json +49 -0
- package/src/ast.ts +7 -0
- package/src/backend.ts +85 -0
- package/src/error.ts +38 -0
- package/src/errors.ts +820 -0
- package/src/herb-backend.ts +152 -0
- package/src/index.ts +15 -0
- package/src/lex-result.ts +78 -0
- package/src/location.ts +51 -0
- package/src/node.ts +106 -0
- package/src/nodes.ts +2294 -0
- package/src/parse-result.ts +101 -0
- package/src/position.ts +38 -0
- package/src/range.ts +35 -0
- package/src/result.ts +26 -0
- package/src/token-list.ts +57 -0
- package/src/token.ts +63 -0
- package/src/util.ts +19 -0
- package/src/visitor.ts +14 -0
- package/src/warning.ts +20 -0
|
@@ -0,0 +1,2704 @@
|
|
|
1
|
+
class ASTNode {
|
|
2
|
+
errors;
|
|
3
|
+
constructor() {
|
|
4
|
+
this.errors = [];
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const expectedFunctions = [
|
|
9
|
+
"parse",
|
|
10
|
+
"lex",
|
|
11
|
+
"parseFile",
|
|
12
|
+
"lexFile",
|
|
13
|
+
"extractRuby",
|
|
14
|
+
"extractHTML",
|
|
15
|
+
"version",
|
|
16
|
+
];
|
|
17
|
+
// NOTE: This function should never be called and is only for type checking
|
|
18
|
+
// so we can make sure `expectedFunctions` matches the functions defined
|
|
19
|
+
// in `LibHerbBackendFunctions` and the other way around.
|
|
20
|
+
//
|
|
21
|
+
function _TYPECHECK() {
|
|
22
|
+
const checkFunctionsExist = true;
|
|
23
|
+
const checkInterfaceComplete = true;
|
|
24
|
+
return { checkFunctionsExist, checkInterfaceComplete };
|
|
25
|
+
}
|
|
26
|
+
function isLibHerbBackend(object, libherbpath = "unknown") {
|
|
27
|
+
for (const expectedFunction of expectedFunctions) {
|
|
28
|
+
if (object[expectedFunction] === undefined) {
|
|
29
|
+
throw new Error(`Libherb at "${libherbpath}" doesn't expose function "${expectedFunction}".`);
|
|
30
|
+
}
|
|
31
|
+
if (typeof object[expectedFunction] !== "function") {
|
|
32
|
+
throw new Error(`Libherb at "${libherbpath}" has "${expectedFunction}" but it's not a function.`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
function ensureLibHerbBackend(object, libherbpath = "unknown") {
|
|
38
|
+
isLibHerbBackend(object, libherbpath);
|
|
39
|
+
return object;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
class Position {
|
|
43
|
+
line;
|
|
44
|
+
column;
|
|
45
|
+
static from(position) {
|
|
46
|
+
return new Position(position.line, position.column);
|
|
47
|
+
}
|
|
48
|
+
constructor(line, column) {
|
|
49
|
+
this.line = line;
|
|
50
|
+
this.column = column;
|
|
51
|
+
}
|
|
52
|
+
toHash() {
|
|
53
|
+
return { line: this.line, column: this.column };
|
|
54
|
+
}
|
|
55
|
+
toJSON() {
|
|
56
|
+
return this.toHash();
|
|
57
|
+
}
|
|
58
|
+
treeInspect() {
|
|
59
|
+
return `(${this.line}:${this.column})`;
|
|
60
|
+
}
|
|
61
|
+
inspect() {
|
|
62
|
+
return `#<Herb::Position ${this.treeInspect()}>`;
|
|
63
|
+
}
|
|
64
|
+
toString() {
|
|
65
|
+
return this.inspect();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
class Location {
|
|
70
|
+
start;
|
|
71
|
+
end;
|
|
72
|
+
static from(location) {
|
|
73
|
+
const start = Position.from(location.start);
|
|
74
|
+
const end = Position.from(location.end);
|
|
75
|
+
return new Location(start, end);
|
|
76
|
+
}
|
|
77
|
+
constructor(start, end) {
|
|
78
|
+
this.start = start;
|
|
79
|
+
this.end = end;
|
|
80
|
+
}
|
|
81
|
+
toHash() {
|
|
82
|
+
return {
|
|
83
|
+
start: this.start.toHash(),
|
|
84
|
+
end: this.end.toHash(),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
toJSON() {
|
|
88
|
+
return this.toHash();
|
|
89
|
+
}
|
|
90
|
+
treeInspect() {
|
|
91
|
+
return `${this.start.treeInspect()}-${this.end.treeInspect()}`;
|
|
92
|
+
}
|
|
93
|
+
treeInspectWithLabel() {
|
|
94
|
+
return `(location: ${this.treeInspect()})`;
|
|
95
|
+
}
|
|
96
|
+
inspect() {
|
|
97
|
+
return `#<Herb::Location ${this.treeInspect()}>`;
|
|
98
|
+
}
|
|
99
|
+
toString() {
|
|
100
|
+
return this.inspect();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
class Range {
|
|
105
|
+
start;
|
|
106
|
+
end;
|
|
107
|
+
static from(range) {
|
|
108
|
+
return new Range(range[0], range[1]);
|
|
109
|
+
}
|
|
110
|
+
constructor(start, end) {
|
|
111
|
+
this.start = start;
|
|
112
|
+
this.end = end;
|
|
113
|
+
}
|
|
114
|
+
toArray() {
|
|
115
|
+
return [this.start, this.end];
|
|
116
|
+
}
|
|
117
|
+
toJSON() {
|
|
118
|
+
return this.toArray();
|
|
119
|
+
}
|
|
120
|
+
treeInspect() {
|
|
121
|
+
return `[${this.start}, ${this.end}]`;
|
|
122
|
+
}
|
|
123
|
+
inspect() {
|
|
124
|
+
return `#<Herb::Range ${this.toArray()}>`;
|
|
125
|
+
}
|
|
126
|
+
toString() {
|
|
127
|
+
return this.inspect();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
class Token {
|
|
132
|
+
value;
|
|
133
|
+
range;
|
|
134
|
+
location;
|
|
135
|
+
type;
|
|
136
|
+
static from(token) {
|
|
137
|
+
return new Token(token.value, Range.from(token.range), Location.from(token.location), token.type);
|
|
138
|
+
}
|
|
139
|
+
constructor(value, range, location, type) {
|
|
140
|
+
this.value = value;
|
|
141
|
+
this.range = range;
|
|
142
|
+
this.location = location;
|
|
143
|
+
this.type = type;
|
|
144
|
+
}
|
|
145
|
+
toHash() {
|
|
146
|
+
return {
|
|
147
|
+
value: this.value,
|
|
148
|
+
range: this.range?.toArray(),
|
|
149
|
+
location: this.location?.toHash(),
|
|
150
|
+
type: this.type,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
toJSON() {
|
|
154
|
+
return this.toHash();
|
|
155
|
+
}
|
|
156
|
+
treeInspect() {
|
|
157
|
+
return `"${this.value}" ${this.location.treeInspectWithLabel()}`;
|
|
158
|
+
}
|
|
159
|
+
valueInspect() {
|
|
160
|
+
return this.type === "TOKEN_EOF"
|
|
161
|
+
? JSON.stringify("<EOF>")
|
|
162
|
+
: JSON.stringify(this.value);
|
|
163
|
+
}
|
|
164
|
+
inspect() {
|
|
165
|
+
return `#<Herb::Token type="${this.type}" value=${this.valueInspect()} range=${this.range.treeInspect()} start=${this.location.start.treeInspect()} end=${this.location.end.treeInspect()}>`;
|
|
166
|
+
}
|
|
167
|
+
toString() {
|
|
168
|
+
return this.inspect();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
class HerbError {
|
|
173
|
+
type;
|
|
174
|
+
message;
|
|
175
|
+
location;
|
|
176
|
+
static from(error) {
|
|
177
|
+
return fromSerializedError(error);
|
|
178
|
+
}
|
|
179
|
+
constructor(type, message, location) {
|
|
180
|
+
this.type = type;
|
|
181
|
+
this.message = message;
|
|
182
|
+
this.location = location;
|
|
183
|
+
}
|
|
184
|
+
toJSON() {
|
|
185
|
+
return {
|
|
186
|
+
type: this.type,
|
|
187
|
+
message: this.message,
|
|
188
|
+
location: this.location.toJSON(),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
inspect() {
|
|
192
|
+
return this.treeInspect(0);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
197
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/errors.ts.erb
|
|
198
|
+
function fromSerializedError(error) {
|
|
199
|
+
switch (error.type) {
|
|
200
|
+
case "UNEXPECTED_ERROR": return UnexpectedError.from(error);
|
|
201
|
+
case "UNEXPECTED_TOKEN_ERROR": return UnexpectedTokenError.from(error);
|
|
202
|
+
case "MISSING_OPENING_TAG_ERROR": return MissingOpeningTagError.from(error);
|
|
203
|
+
case "MISSING_CLOSING_TAG_ERROR": return MissingClosingTagError.from(error);
|
|
204
|
+
case "TAG_NAMES_MISMATCH_ERROR": return TagNamesMismatchError.from(error);
|
|
205
|
+
case "QUOTES_MISMATCH_ERROR": return QuotesMismatchError.from(error);
|
|
206
|
+
case "VOID_ELEMENT_CLOSING_TAG_ERROR": return VoidElementClosingTagError.from(error);
|
|
207
|
+
case "UNCLOSED_ELEMENT_ERROR": return UnclosedElementError.from(error);
|
|
208
|
+
case "RUBY_PARSE_ERROR": return RubyParseError.from(error);
|
|
209
|
+
default:
|
|
210
|
+
throw new Error(`Unknown node type: ${error.type}`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
class UnexpectedError extends HerbError {
|
|
214
|
+
description;
|
|
215
|
+
expected;
|
|
216
|
+
found;
|
|
217
|
+
static from(data) {
|
|
218
|
+
return new UnexpectedError({
|
|
219
|
+
type: data.type,
|
|
220
|
+
message: data.message,
|
|
221
|
+
location: Location.from(data.location),
|
|
222
|
+
description: data.description,
|
|
223
|
+
expected: data.expected,
|
|
224
|
+
found: data.found,
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
constructor(props) {
|
|
228
|
+
super(props.type, props.message, props.location);
|
|
229
|
+
this.description = props.description;
|
|
230
|
+
this.expected = props.expected;
|
|
231
|
+
this.found = props.found;
|
|
232
|
+
}
|
|
233
|
+
toJSON() {
|
|
234
|
+
return {
|
|
235
|
+
...super.toJSON(),
|
|
236
|
+
type: "UNEXPECTED_ERROR",
|
|
237
|
+
description: this.description,
|
|
238
|
+
expected: this.expected,
|
|
239
|
+
found: this.found,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
toDiagnostics() {
|
|
243
|
+
const diagnostics = [
|
|
244
|
+
{
|
|
245
|
+
line: this.location.start.line,
|
|
246
|
+
column: this.location.start.column,
|
|
247
|
+
endLine: this.location.end.line,
|
|
248
|
+
endColumn: this.location.end.column,
|
|
249
|
+
message: this.message,
|
|
250
|
+
severity: 'error'
|
|
251
|
+
}
|
|
252
|
+
];
|
|
253
|
+
// no-op for description
|
|
254
|
+
// no-op for expected
|
|
255
|
+
// no-op for found
|
|
256
|
+
return diagnostics;
|
|
257
|
+
}
|
|
258
|
+
treeInspect() {
|
|
259
|
+
let output = "";
|
|
260
|
+
output += `@ UnexpectedError ${this.location.treeInspectWithLabel()}\n`;
|
|
261
|
+
output += `├── message: "${this.message}"\n`;
|
|
262
|
+
output += `├── description: ${JSON.stringify(this.description)}\n`;
|
|
263
|
+
output += `├── expected: ${JSON.stringify(this.expected)}\n`;
|
|
264
|
+
output += `└── found: ${JSON.stringify(this.found)}\n`;
|
|
265
|
+
return output;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
class UnexpectedTokenError extends HerbError {
|
|
269
|
+
expected_type;
|
|
270
|
+
found;
|
|
271
|
+
static from(data) {
|
|
272
|
+
return new UnexpectedTokenError({
|
|
273
|
+
type: data.type,
|
|
274
|
+
message: data.message,
|
|
275
|
+
location: Location.from(data.location),
|
|
276
|
+
expected_type: data.expected_type,
|
|
277
|
+
found: data.found ? Token.from(data.found) : null,
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
constructor(props) {
|
|
281
|
+
super(props.type, props.message, props.location);
|
|
282
|
+
this.expected_type = props.expected_type;
|
|
283
|
+
this.found = props.found;
|
|
284
|
+
}
|
|
285
|
+
toJSON() {
|
|
286
|
+
return {
|
|
287
|
+
...super.toJSON(),
|
|
288
|
+
type: "UNEXPECTED_TOKEN_ERROR",
|
|
289
|
+
expected_type: this.expected_type,
|
|
290
|
+
found: this.found ? this.found.toJSON() : null,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
toDiagnostics() {
|
|
294
|
+
const diagnostics = [
|
|
295
|
+
{
|
|
296
|
+
line: this.location.start.line,
|
|
297
|
+
column: this.location.start.column,
|
|
298
|
+
endLine: this.location.end.line,
|
|
299
|
+
endColumn: this.location.end.column,
|
|
300
|
+
message: this.message,
|
|
301
|
+
severity: 'error'
|
|
302
|
+
}
|
|
303
|
+
];
|
|
304
|
+
// no-op for expected_type
|
|
305
|
+
if (this.found) {
|
|
306
|
+
diagnostics.push({
|
|
307
|
+
line: this.found.location.start.line,
|
|
308
|
+
column: this.found.location.start.column,
|
|
309
|
+
endLine: this.found.location.end.line,
|
|
310
|
+
endColumn: this.found.location.end.column,
|
|
311
|
+
message: `found "${(this.found.value)}" is here`,
|
|
312
|
+
severity: 'info'
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
return diagnostics;
|
|
316
|
+
}
|
|
317
|
+
treeInspect() {
|
|
318
|
+
let output = "";
|
|
319
|
+
output += `@ UnexpectedTokenError ${this.location.treeInspectWithLabel()}\n`;
|
|
320
|
+
output += `├── message: "${this.message}"\n`;
|
|
321
|
+
output += `├── expected_type: ${JSON.stringify(this.expected_type)}\n`;
|
|
322
|
+
output += `└── found: ${this.found ? this.found.treeInspect() : "∅"}\n`;
|
|
323
|
+
return output;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
class MissingOpeningTagError extends HerbError {
|
|
327
|
+
closing_tag;
|
|
328
|
+
static from(data) {
|
|
329
|
+
return new MissingOpeningTagError({
|
|
330
|
+
type: data.type,
|
|
331
|
+
message: data.message,
|
|
332
|
+
location: Location.from(data.location),
|
|
333
|
+
closing_tag: data.closing_tag ? Token.from(data.closing_tag) : null,
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
constructor(props) {
|
|
337
|
+
super(props.type, props.message, props.location);
|
|
338
|
+
this.closing_tag = props.closing_tag;
|
|
339
|
+
}
|
|
340
|
+
toJSON() {
|
|
341
|
+
return {
|
|
342
|
+
...super.toJSON(),
|
|
343
|
+
type: "MISSING_OPENING_TAG_ERROR",
|
|
344
|
+
closing_tag: this.closing_tag ? this.closing_tag.toJSON() : null,
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
toDiagnostics() {
|
|
348
|
+
const diagnostics = [
|
|
349
|
+
{
|
|
350
|
+
line: this.location.start.line,
|
|
351
|
+
column: this.location.start.column,
|
|
352
|
+
endLine: this.location.end.line,
|
|
353
|
+
endColumn: this.location.end.column,
|
|
354
|
+
message: this.message,
|
|
355
|
+
severity: 'error'
|
|
356
|
+
}
|
|
357
|
+
];
|
|
358
|
+
if (this.closing_tag) {
|
|
359
|
+
diagnostics.push({
|
|
360
|
+
line: this.closing_tag.location.start.line,
|
|
361
|
+
column: this.closing_tag.location.start.column,
|
|
362
|
+
endLine: this.closing_tag.location.end.line,
|
|
363
|
+
endColumn: this.closing_tag.location.end.column,
|
|
364
|
+
message: `closing_tag "${(this.closing_tag.value)}" is here`,
|
|
365
|
+
severity: 'info'
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
return diagnostics;
|
|
369
|
+
}
|
|
370
|
+
treeInspect() {
|
|
371
|
+
let output = "";
|
|
372
|
+
output += `@ MissingOpeningTagError ${this.location.treeInspectWithLabel()}\n`;
|
|
373
|
+
output += `├── message: "${this.message}"\n`;
|
|
374
|
+
output += `└── closing_tag: ${this.closing_tag ? this.closing_tag.treeInspect() : "∅"}\n`;
|
|
375
|
+
return output;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
class MissingClosingTagError extends HerbError {
|
|
379
|
+
opening_tag;
|
|
380
|
+
static from(data) {
|
|
381
|
+
return new MissingClosingTagError({
|
|
382
|
+
type: data.type,
|
|
383
|
+
message: data.message,
|
|
384
|
+
location: Location.from(data.location),
|
|
385
|
+
opening_tag: data.opening_tag ? Token.from(data.opening_tag) : null,
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
constructor(props) {
|
|
389
|
+
super(props.type, props.message, props.location);
|
|
390
|
+
this.opening_tag = props.opening_tag;
|
|
391
|
+
}
|
|
392
|
+
toJSON() {
|
|
393
|
+
return {
|
|
394
|
+
...super.toJSON(),
|
|
395
|
+
type: "MISSING_CLOSING_TAG_ERROR",
|
|
396
|
+
opening_tag: this.opening_tag ? this.opening_tag.toJSON() : null,
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
toDiagnostics() {
|
|
400
|
+
const diagnostics = [
|
|
401
|
+
{
|
|
402
|
+
line: this.location.start.line,
|
|
403
|
+
column: this.location.start.column,
|
|
404
|
+
endLine: this.location.end.line,
|
|
405
|
+
endColumn: this.location.end.column,
|
|
406
|
+
message: this.message,
|
|
407
|
+
severity: 'error'
|
|
408
|
+
}
|
|
409
|
+
];
|
|
410
|
+
if (this.opening_tag) {
|
|
411
|
+
diagnostics.push({
|
|
412
|
+
line: this.opening_tag.location.start.line,
|
|
413
|
+
column: this.opening_tag.location.start.column,
|
|
414
|
+
endLine: this.opening_tag.location.end.line,
|
|
415
|
+
endColumn: this.opening_tag.location.end.column,
|
|
416
|
+
message: `opening_tag "${(this.opening_tag.value)}" is here`,
|
|
417
|
+
severity: 'info'
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
return diagnostics;
|
|
421
|
+
}
|
|
422
|
+
treeInspect() {
|
|
423
|
+
let output = "";
|
|
424
|
+
output += `@ MissingClosingTagError ${this.location.treeInspectWithLabel()}\n`;
|
|
425
|
+
output += `├── message: "${this.message}"\n`;
|
|
426
|
+
output += `└── opening_tag: ${this.opening_tag ? this.opening_tag.treeInspect() : "∅"}\n`;
|
|
427
|
+
return output;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
class TagNamesMismatchError extends HerbError {
|
|
431
|
+
opening_tag;
|
|
432
|
+
closing_tag;
|
|
433
|
+
static from(data) {
|
|
434
|
+
return new TagNamesMismatchError({
|
|
435
|
+
type: data.type,
|
|
436
|
+
message: data.message,
|
|
437
|
+
location: Location.from(data.location),
|
|
438
|
+
opening_tag: data.opening_tag ? Token.from(data.opening_tag) : null,
|
|
439
|
+
closing_tag: data.closing_tag ? Token.from(data.closing_tag) : null,
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
constructor(props) {
|
|
443
|
+
super(props.type, props.message, props.location);
|
|
444
|
+
this.opening_tag = props.opening_tag;
|
|
445
|
+
this.closing_tag = props.closing_tag;
|
|
446
|
+
}
|
|
447
|
+
toJSON() {
|
|
448
|
+
return {
|
|
449
|
+
...super.toJSON(),
|
|
450
|
+
type: "TAG_NAMES_MISMATCH_ERROR",
|
|
451
|
+
opening_tag: this.opening_tag ? this.opening_tag.toJSON() : null,
|
|
452
|
+
closing_tag: this.closing_tag ? this.closing_tag.toJSON() : null,
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
toDiagnostics() {
|
|
456
|
+
const diagnostics = [
|
|
457
|
+
{
|
|
458
|
+
line: this.location.start.line,
|
|
459
|
+
column: this.location.start.column,
|
|
460
|
+
endLine: this.location.end.line,
|
|
461
|
+
endColumn: this.location.end.column,
|
|
462
|
+
message: this.message,
|
|
463
|
+
severity: 'error'
|
|
464
|
+
}
|
|
465
|
+
];
|
|
466
|
+
if (this.opening_tag) {
|
|
467
|
+
diagnostics.push({
|
|
468
|
+
line: this.opening_tag.location.start.line,
|
|
469
|
+
column: this.opening_tag.location.start.column,
|
|
470
|
+
endLine: this.opening_tag.location.end.line,
|
|
471
|
+
endColumn: this.opening_tag.location.end.column,
|
|
472
|
+
message: `opening_tag "${(this.opening_tag.value)}" is here`,
|
|
473
|
+
severity: 'info'
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
if (this.closing_tag) {
|
|
477
|
+
diagnostics.push({
|
|
478
|
+
line: this.closing_tag.location.start.line,
|
|
479
|
+
column: this.closing_tag.location.start.column,
|
|
480
|
+
endLine: this.closing_tag.location.end.line,
|
|
481
|
+
endColumn: this.closing_tag.location.end.column,
|
|
482
|
+
message: `closing_tag "${(this.closing_tag.value)}" is here`,
|
|
483
|
+
severity: 'info'
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
return diagnostics;
|
|
487
|
+
}
|
|
488
|
+
treeInspect() {
|
|
489
|
+
let output = "";
|
|
490
|
+
output += `@ TagNamesMismatchError ${this.location.treeInspectWithLabel()}\n`;
|
|
491
|
+
output += `├── message: "${this.message}"\n`;
|
|
492
|
+
output += `├── opening_tag: ${this.opening_tag ? this.opening_tag.treeInspect() : "∅"}\n`;
|
|
493
|
+
output += `└── closing_tag: ${this.closing_tag ? this.closing_tag.treeInspect() : "∅"}\n`;
|
|
494
|
+
return output;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
class QuotesMismatchError extends HerbError {
|
|
498
|
+
opening_quote;
|
|
499
|
+
closing_quote;
|
|
500
|
+
static from(data) {
|
|
501
|
+
return new QuotesMismatchError({
|
|
502
|
+
type: data.type,
|
|
503
|
+
message: data.message,
|
|
504
|
+
location: Location.from(data.location),
|
|
505
|
+
opening_quote: data.opening_quote ? Token.from(data.opening_quote) : null,
|
|
506
|
+
closing_quote: data.closing_quote ? Token.from(data.closing_quote) : null,
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
constructor(props) {
|
|
510
|
+
super(props.type, props.message, props.location);
|
|
511
|
+
this.opening_quote = props.opening_quote;
|
|
512
|
+
this.closing_quote = props.closing_quote;
|
|
513
|
+
}
|
|
514
|
+
toJSON() {
|
|
515
|
+
return {
|
|
516
|
+
...super.toJSON(),
|
|
517
|
+
type: "QUOTES_MISMATCH_ERROR",
|
|
518
|
+
opening_quote: this.opening_quote ? this.opening_quote.toJSON() : null,
|
|
519
|
+
closing_quote: this.closing_quote ? this.closing_quote.toJSON() : null,
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
toDiagnostics() {
|
|
523
|
+
const diagnostics = [
|
|
524
|
+
{
|
|
525
|
+
line: this.location.start.line,
|
|
526
|
+
column: this.location.start.column,
|
|
527
|
+
endLine: this.location.end.line,
|
|
528
|
+
endColumn: this.location.end.column,
|
|
529
|
+
message: this.message,
|
|
530
|
+
severity: 'error'
|
|
531
|
+
}
|
|
532
|
+
];
|
|
533
|
+
if (this.opening_quote) {
|
|
534
|
+
diagnostics.push({
|
|
535
|
+
line: this.opening_quote.location.start.line,
|
|
536
|
+
column: this.opening_quote.location.start.column,
|
|
537
|
+
endLine: this.opening_quote.location.end.line,
|
|
538
|
+
endColumn: this.opening_quote.location.end.column,
|
|
539
|
+
message: `opening_quote "${(this.opening_quote.value)}" is here`,
|
|
540
|
+
severity: 'info'
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
if (this.closing_quote) {
|
|
544
|
+
diagnostics.push({
|
|
545
|
+
line: this.closing_quote.location.start.line,
|
|
546
|
+
column: this.closing_quote.location.start.column,
|
|
547
|
+
endLine: this.closing_quote.location.end.line,
|
|
548
|
+
endColumn: this.closing_quote.location.end.column,
|
|
549
|
+
message: `closing_quote "${(this.closing_quote.value)}" is here`,
|
|
550
|
+
severity: 'info'
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
return diagnostics;
|
|
554
|
+
}
|
|
555
|
+
treeInspect() {
|
|
556
|
+
let output = "";
|
|
557
|
+
output += `@ QuotesMismatchError ${this.location.treeInspectWithLabel()}\n`;
|
|
558
|
+
output += `├── message: "${this.message}"\n`;
|
|
559
|
+
output += `├── opening_quote: ${this.opening_quote ? this.opening_quote.treeInspect() : "∅"}\n`;
|
|
560
|
+
output += `└── closing_quote: ${this.closing_quote ? this.closing_quote.treeInspect() : "∅"}\n`;
|
|
561
|
+
return output;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
class VoidElementClosingTagError extends HerbError {
|
|
565
|
+
tag_name;
|
|
566
|
+
expected;
|
|
567
|
+
found;
|
|
568
|
+
static from(data) {
|
|
569
|
+
return new VoidElementClosingTagError({
|
|
570
|
+
type: data.type,
|
|
571
|
+
message: data.message,
|
|
572
|
+
location: Location.from(data.location),
|
|
573
|
+
tag_name: data.tag_name ? Token.from(data.tag_name) : null,
|
|
574
|
+
expected: data.expected,
|
|
575
|
+
found: data.found,
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
constructor(props) {
|
|
579
|
+
super(props.type, props.message, props.location);
|
|
580
|
+
this.tag_name = props.tag_name;
|
|
581
|
+
this.expected = props.expected;
|
|
582
|
+
this.found = props.found;
|
|
583
|
+
}
|
|
584
|
+
toJSON() {
|
|
585
|
+
return {
|
|
586
|
+
...super.toJSON(),
|
|
587
|
+
type: "VOID_ELEMENT_CLOSING_TAG_ERROR",
|
|
588
|
+
tag_name: this.tag_name ? this.tag_name.toJSON() : null,
|
|
589
|
+
expected: this.expected,
|
|
590
|
+
found: this.found,
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
toDiagnostics() {
|
|
594
|
+
const diagnostics = [
|
|
595
|
+
{
|
|
596
|
+
line: this.location.start.line,
|
|
597
|
+
column: this.location.start.column,
|
|
598
|
+
endLine: this.location.end.line,
|
|
599
|
+
endColumn: this.location.end.column,
|
|
600
|
+
message: this.message,
|
|
601
|
+
severity: 'error'
|
|
602
|
+
}
|
|
603
|
+
];
|
|
604
|
+
if (this.tag_name) {
|
|
605
|
+
diagnostics.push({
|
|
606
|
+
line: this.tag_name.location.start.line,
|
|
607
|
+
column: this.tag_name.location.start.column,
|
|
608
|
+
endLine: this.tag_name.location.end.line,
|
|
609
|
+
endColumn: this.tag_name.location.end.column,
|
|
610
|
+
message: `tag_name "${(this.tag_name.value)}" is here`,
|
|
611
|
+
severity: 'info'
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
// no-op for expected
|
|
615
|
+
// no-op for found
|
|
616
|
+
return diagnostics;
|
|
617
|
+
}
|
|
618
|
+
treeInspect() {
|
|
619
|
+
let output = "";
|
|
620
|
+
output += `@ VoidElementClosingTagError ${this.location.treeInspectWithLabel()}\n`;
|
|
621
|
+
output += `├── message: "${this.message}"\n`;
|
|
622
|
+
output += `├── tag_name: ${this.tag_name ? this.tag_name.treeInspect() : "∅"}\n`;
|
|
623
|
+
output += `├── expected: ${JSON.stringify(this.expected)}\n`;
|
|
624
|
+
output += `└── found: ${JSON.stringify(this.found)}\n`;
|
|
625
|
+
return output;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
class UnclosedElementError extends HerbError {
|
|
629
|
+
opening_tag;
|
|
630
|
+
static from(data) {
|
|
631
|
+
return new UnclosedElementError({
|
|
632
|
+
type: data.type,
|
|
633
|
+
message: data.message,
|
|
634
|
+
location: Location.from(data.location),
|
|
635
|
+
opening_tag: data.opening_tag ? Token.from(data.opening_tag) : null,
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
constructor(props) {
|
|
639
|
+
super(props.type, props.message, props.location);
|
|
640
|
+
this.opening_tag = props.opening_tag;
|
|
641
|
+
}
|
|
642
|
+
toJSON() {
|
|
643
|
+
return {
|
|
644
|
+
...super.toJSON(),
|
|
645
|
+
type: "UNCLOSED_ELEMENT_ERROR",
|
|
646
|
+
opening_tag: this.opening_tag ? this.opening_tag.toJSON() : null,
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
toDiagnostics() {
|
|
650
|
+
const diagnostics = [
|
|
651
|
+
{
|
|
652
|
+
line: this.location.start.line,
|
|
653
|
+
column: this.location.start.column,
|
|
654
|
+
endLine: this.location.end.line,
|
|
655
|
+
endColumn: this.location.end.column,
|
|
656
|
+
message: this.message,
|
|
657
|
+
severity: 'error'
|
|
658
|
+
}
|
|
659
|
+
];
|
|
660
|
+
if (this.opening_tag) {
|
|
661
|
+
diagnostics.push({
|
|
662
|
+
line: this.opening_tag.location.start.line,
|
|
663
|
+
column: this.opening_tag.location.start.column,
|
|
664
|
+
endLine: this.opening_tag.location.end.line,
|
|
665
|
+
endColumn: this.opening_tag.location.end.column,
|
|
666
|
+
message: `opening_tag "${(this.opening_tag.value)}" is here`,
|
|
667
|
+
severity: 'info'
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
return diagnostics;
|
|
671
|
+
}
|
|
672
|
+
treeInspect() {
|
|
673
|
+
let output = "";
|
|
674
|
+
output += `@ UnclosedElementError ${this.location.treeInspectWithLabel()}\n`;
|
|
675
|
+
output += `├── message: "${this.message}"\n`;
|
|
676
|
+
output += `└── opening_tag: ${this.opening_tag ? this.opening_tag.treeInspect() : "∅"}\n`;
|
|
677
|
+
return output;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
class RubyParseError extends HerbError {
|
|
681
|
+
error_message;
|
|
682
|
+
diagnostic_id;
|
|
683
|
+
level;
|
|
684
|
+
static from(data) {
|
|
685
|
+
return new RubyParseError({
|
|
686
|
+
type: data.type,
|
|
687
|
+
message: data.message,
|
|
688
|
+
location: Location.from(data.location),
|
|
689
|
+
error_message: data.error_message,
|
|
690
|
+
diagnostic_id: data.diagnostic_id,
|
|
691
|
+
level: data.level,
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
constructor(props) {
|
|
695
|
+
super(props.type, props.message, props.location);
|
|
696
|
+
this.error_message = props.error_message;
|
|
697
|
+
this.diagnostic_id = props.diagnostic_id;
|
|
698
|
+
this.level = props.level;
|
|
699
|
+
}
|
|
700
|
+
toJSON() {
|
|
701
|
+
return {
|
|
702
|
+
...super.toJSON(),
|
|
703
|
+
type: "RUBY_PARSE_ERROR",
|
|
704
|
+
error_message: this.error_message,
|
|
705
|
+
diagnostic_id: this.diagnostic_id,
|
|
706
|
+
level: this.level,
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
toDiagnostics() {
|
|
710
|
+
const diagnostics = [
|
|
711
|
+
{
|
|
712
|
+
line: this.location.start.line,
|
|
713
|
+
column: this.location.start.column,
|
|
714
|
+
endLine: this.location.end.line,
|
|
715
|
+
endColumn: this.location.end.column,
|
|
716
|
+
message: this.message,
|
|
717
|
+
severity: 'error'
|
|
718
|
+
}
|
|
719
|
+
];
|
|
720
|
+
// no-op for error_message
|
|
721
|
+
// no-op for diagnostic_id
|
|
722
|
+
// no-op for level
|
|
723
|
+
return diagnostics;
|
|
724
|
+
}
|
|
725
|
+
treeInspect() {
|
|
726
|
+
let output = "";
|
|
727
|
+
output += `@ RubyParseError ${this.location.treeInspectWithLabel()}\n`;
|
|
728
|
+
output += `├── message: "${this.message}"\n`;
|
|
729
|
+
output += `├── error_message: ${JSON.stringify(this.error_message)}\n`;
|
|
730
|
+
output += `├── diagnostic_id: ${JSON.stringify(this.diagnostic_id)}\n`;
|
|
731
|
+
output += `└── level: ${JSON.stringify(this.level)}\n`;
|
|
732
|
+
return output;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
var name = "@herb-tools/core";
|
|
737
|
+
var version = "0.1.0";
|
|
738
|
+
var packageJSON = {
|
|
739
|
+
name: name,
|
|
740
|
+
version: version};
|
|
741
|
+
|
|
742
|
+
function ensureString(object) {
|
|
743
|
+
if (typeof object === "string") {
|
|
744
|
+
return object;
|
|
745
|
+
}
|
|
746
|
+
throw new TypeError("Argument must be a string");
|
|
747
|
+
}
|
|
748
|
+
function convertToUTF8(string) {
|
|
749
|
+
const bytes = [];
|
|
750
|
+
for (let i = 0; i < string.length; i++) {
|
|
751
|
+
bytes.push(string.charCodeAt(i));
|
|
752
|
+
}
|
|
753
|
+
const decoder = new TextDecoder("utf-8");
|
|
754
|
+
return decoder.decode(new Uint8Array(bytes));
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
class Result {
|
|
758
|
+
source;
|
|
759
|
+
warnings;
|
|
760
|
+
errors;
|
|
761
|
+
constructor(source, warnings = [], errors = []) {
|
|
762
|
+
this.source = source;
|
|
763
|
+
this.warnings = warnings || [];
|
|
764
|
+
this.errors = errors || [];
|
|
765
|
+
}
|
|
766
|
+
success() {
|
|
767
|
+
return false;
|
|
768
|
+
}
|
|
769
|
+
failed() {
|
|
770
|
+
return true;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
class TokenList {
|
|
775
|
+
list;
|
|
776
|
+
static from(list) {
|
|
777
|
+
return new TokenList(list.map((token) => Token.from(token)));
|
|
778
|
+
}
|
|
779
|
+
constructor(list) {
|
|
780
|
+
this.list = list;
|
|
781
|
+
}
|
|
782
|
+
get length() {
|
|
783
|
+
return this.list.length;
|
|
784
|
+
}
|
|
785
|
+
[Symbol.iterator]() {
|
|
786
|
+
return this.list[Symbol.iterator]();
|
|
787
|
+
}
|
|
788
|
+
at(index) {
|
|
789
|
+
return this.list.at(index);
|
|
790
|
+
}
|
|
791
|
+
forEach(callback) {
|
|
792
|
+
this.list.forEach(callback);
|
|
793
|
+
}
|
|
794
|
+
map(callback) {
|
|
795
|
+
return this.list.map(callback);
|
|
796
|
+
}
|
|
797
|
+
filter(predicate) {
|
|
798
|
+
return this.list.filter(predicate);
|
|
799
|
+
}
|
|
800
|
+
__getobj__() {
|
|
801
|
+
return this.list;
|
|
802
|
+
}
|
|
803
|
+
inspect() {
|
|
804
|
+
return this.list.map((token) => token.inspect()).join("\n") + "\n";
|
|
805
|
+
}
|
|
806
|
+
toString() {
|
|
807
|
+
return this.inspect();
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
/**
|
|
812
|
+
* Represents the result of a lexical analysis, extending the base `Result` class.
|
|
813
|
+
* It contains the token list, source code, warnings, and errors.
|
|
814
|
+
*/
|
|
815
|
+
class LexResult extends Result {
|
|
816
|
+
/** The list of tokens generated from the source code. */
|
|
817
|
+
value;
|
|
818
|
+
/**
|
|
819
|
+
* Creates a `LexResult` instance from a serialized result.
|
|
820
|
+
* @param result - The serialized lexical result containing tokens, source, warnings, and errors.
|
|
821
|
+
* @returns A new `LexResult` instance.
|
|
822
|
+
*/
|
|
823
|
+
static from(result) {
|
|
824
|
+
return new LexResult(TokenList.from(result.tokens || []), result.source, result.warnings, result.errors);
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Constructs a new `LexResult`.
|
|
828
|
+
* @param value - The list of tokens.
|
|
829
|
+
* @param source - The source code that was lexed.
|
|
830
|
+
* @param warnings - An array of warnings encountered during lexing.
|
|
831
|
+
* @param errors - An array of errors encountered during lexing.
|
|
832
|
+
*/
|
|
833
|
+
constructor(value, source, warnings = [], errors = []) {
|
|
834
|
+
super(source, warnings, errors);
|
|
835
|
+
this.value = value;
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Determines if the lexing was successful.
|
|
839
|
+
* @returns `true` if there are no errors, otherwise `false`.
|
|
840
|
+
*/
|
|
841
|
+
success() {
|
|
842
|
+
return this.errors.length === 0;
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* Determines if the lexing failed.
|
|
846
|
+
* @returns `true` if there are errors, otherwise `false`.
|
|
847
|
+
*/
|
|
848
|
+
failed() {
|
|
849
|
+
return this.errors.length > 0;
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* Converts the `LexResult` to a JSON representation.
|
|
853
|
+
* @returns An object containing the token list, source, warnings, and errors.
|
|
854
|
+
*/
|
|
855
|
+
toJSON() {
|
|
856
|
+
return {
|
|
857
|
+
value: this.value,
|
|
858
|
+
source: this.source,
|
|
859
|
+
warnings: this.warnings,
|
|
860
|
+
errors: this.errors,
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
class Node {
|
|
866
|
+
type;
|
|
867
|
+
location;
|
|
868
|
+
errors;
|
|
869
|
+
static from(node) {
|
|
870
|
+
return fromSerializedNode(node);
|
|
871
|
+
}
|
|
872
|
+
constructor(type, location, errors) {
|
|
873
|
+
this.type = type;
|
|
874
|
+
this.location = location;
|
|
875
|
+
this.errors = errors;
|
|
876
|
+
}
|
|
877
|
+
toJSON() {
|
|
878
|
+
return {
|
|
879
|
+
type: this.type,
|
|
880
|
+
location: this.location.toJSON(),
|
|
881
|
+
errors: this.errors,
|
|
882
|
+
};
|
|
883
|
+
}
|
|
884
|
+
inspect() {
|
|
885
|
+
return this.treeInspect(0);
|
|
886
|
+
}
|
|
887
|
+
inspectArray(array, prefix) {
|
|
888
|
+
if (!array)
|
|
889
|
+
return "∅\n";
|
|
890
|
+
if (array.length === 0)
|
|
891
|
+
return "[]\n";
|
|
892
|
+
let output = `(${array.length} item${array.length == 1 ? "" : "s"})\n`;
|
|
893
|
+
array.forEach((item, index) => {
|
|
894
|
+
const isLast = index === array.length - 1;
|
|
895
|
+
if (item instanceof Node || item instanceof HerbError) {
|
|
896
|
+
output += this.inspectNode(item, prefix, isLast ? " " : "│ ", isLast, false);
|
|
897
|
+
}
|
|
898
|
+
else {
|
|
899
|
+
const symbol = isLast ? "└── " : "├── ";
|
|
900
|
+
output += `${prefix}${symbol} ${item}\n`;
|
|
901
|
+
}
|
|
902
|
+
});
|
|
903
|
+
output += `${prefix}\n`;
|
|
904
|
+
return output;
|
|
905
|
+
}
|
|
906
|
+
inspectNode(node, prefix, prefix2 = " ", last = true, trailingNewline = true) {
|
|
907
|
+
if (!node)
|
|
908
|
+
return "∅\n";
|
|
909
|
+
let output = trailingNewline ? "\n" : "";
|
|
910
|
+
output += `${prefix}`;
|
|
911
|
+
output += last ? "└── " : "├── ";
|
|
912
|
+
output += node
|
|
913
|
+
.treeInspect()
|
|
914
|
+
.trimStart()
|
|
915
|
+
.split("\n")
|
|
916
|
+
.map((line, index) => index == 0 ? line.trimStart() : `${prefix}${prefix2}${line}`)
|
|
917
|
+
.join("\n")
|
|
918
|
+
.trimStart();
|
|
919
|
+
output += `\n`;
|
|
920
|
+
return output;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
925
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/nodes.ts.erb
|
|
926
|
+
function fromSerializedNode(node) {
|
|
927
|
+
switch (node.type) {
|
|
928
|
+
case "AST_DOCUMENT_NODE": return DocumentNode.from(node);
|
|
929
|
+
case "AST_LITERAL_NODE": return LiteralNode.from(node);
|
|
930
|
+
case "AST_HTML_OPEN_TAG_NODE": return HTMLOpenTagNode.from(node);
|
|
931
|
+
case "AST_HTML_CLOSE_TAG_NODE": return HTMLCloseTagNode.from(node);
|
|
932
|
+
case "AST_HTML_SELF_CLOSE_TAG_NODE": return HTMLSelfCloseTagNode.from(node);
|
|
933
|
+
case "AST_HTML_ELEMENT_NODE": return HTMLElementNode.from(node);
|
|
934
|
+
case "AST_HTML_ATTRIBUTE_VALUE_NODE": return HTMLAttributeValueNode.from(node);
|
|
935
|
+
case "AST_HTML_ATTRIBUTE_NAME_NODE": return HTMLAttributeNameNode.from(node);
|
|
936
|
+
case "AST_HTML_ATTRIBUTE_NODE": return HTMLAttributeNode.from(node);
|
|
937
|
+
case "AST_HTML_TEXT_NODE": return HTMLTextNode.from(node);
|
|
938
|
+
case "AST_HTML_COMMENT_NODE": return HTMLCommentNode.from(node);
|
|
939
|
+
case "AST_HTML_DOCTYPE_NODE": return HTMLDoctypeNode.from(node);
|
|
940
|
+
case "AST_WHITESPACE_NODE": return WhitespaceNode.from(node);
|
|
941
|
+
case "AST_ERB_CONTENT_NODE": return ERBContentNode.from(node);
|
|
942
|
+
case "AST_ERB_END_NODE": return ERBEndNode.from(node);
|
|
943
|
+
case "AST_ERB_ELSE_NODE": return ERBElseNode.from(node);
|
|
944
|
+
case "AST_ERB_IF_NODE": return ERBIfNode.from(node);
|
|
945
|
+
case "AST_ERB_BLOCK_NODE": return ERBBlockNode.from(node);
|
|
946
|
+
case "AST_ERB_WHEN_NODE": return ERBWhenNode.from(node);
|
|
947
|
+
case "AST_ERB_CASE_NODE": return ERBCaseNode.from(node);
|
|
948
|
+
case "AST_ERB_WHILE_NODE": return ERBWhileNode.from(node);
|
|
949
|
+
case "AST_ERB_UNTIL_NODE": return ERBUntilNode.from(node);
|
|
950
|
+
case "AST_ERB_FOR_NODE": return ERBForNode.from(node);
|
|
951
|
+
case "AST_ERB_RESCUE_NODE": return ERBRescueNode.from(node);
|
|
952
|
+
case "AST_ERB_ENSURE_NODE": return ERBEnsureNode.from(node);
|
|
953
|
+
case "AST_ERB_BEGIN_NODE": return ERBBeginNode.from(node);
|
|
954
|
+
case "AST_ERB_UNLESS_NODE": return ERBUnlessNode.from(node);
|
|
955
|
+
default:
|
|
956
|
+
throw new Error(`Unknown node type: ${node.type}`);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
class DocumentNode extends Node {
|
|
960
|
+
children;
|
|
961
|
+
static from(data) {
|
|
962
|
+
return new DocumentNode({
|
|
963
|
+
type: data.type,
|
|
964
|
+
location: Location.from(data.location),
|
|
965
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
966
|
+
children: (data.children || []).map(node => fromSerializedNode(node)),
|
|
967
|
+
});
|
|
968
|
+
}
|
|
969
|
+
constructor(props) {
|
|
970
|
+
super(props.type, props.location, props.errors);
|
|
971
|
+
this.children = props.children;
|
|
972
|
+
}
|
|
973
|
+
childNodes() {
|
|
974
|
+
return [
|
|
975
|
+
...this.children,
|
|
976
|
+
].filter(node => node !== null && node !== undefined);
|
|
977
|
+
}
|
|
978
|
+
recursiveErrors() {
|
|
979
|
+
return [
|
|
980
|
+
...this.errors,
|
|
981
|
+
...this.children.map(node => node.recursiveErrors()),
|
|
982
|
+
].flat();
|
|
983
|
+
}
|
|
984
|
+
toJSON() {
|
|
985
|
+
return {
|
|
986
|
+
...super.toJSON(),
|
|
987
|
+
type: "AST_DOCUMENT_NODE",
|
|
988
|
+
children: this.children.map(node => node.toJSON()),
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
treeInspect() {
|
|
992
|
+
let output = "";
|
|
993
|
+
output += `@ DocumentNode ${this.location.treeInspectWithLabel()}\n`;
|
|
994
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
995
|
+
output += `└── children: ${this.inspectArray(this.children, " ")}`;
|
|
996
|
+
// output += "\n";
|
|
997
|
+
return output;
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
class LiteralNode extends Node {
|
|
1001
|
+
content;
|
|
1002
|
+
static from(data) {
|
|
1003
|
+
return new LiteralNode({
|
|
1004
|
+
type: data.type,
|
|
1005
|
+
location: Location.from(data.location),
|
|
1006
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
1007
|
+
content: data.content,
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
constructor(props) {
|
|
1011
|
+
super(props.type, props.location, props.errors);
|
|
1012
|
+
this.content = convertToUTF8(props.content);
|
|
1013
|
+
}
|
|
1014
|
+
childNodes() {
|
|
1015
|
+
return [].filter(node => node !== null && node !== undefined);
|
|
1016
|
+
}
|
|
1017
|
+
recursiveErrors() {
|
|
1018
|
+
return [
|
|
1019
|
+
...this.errors,
|
|
1020
|
+
].flat();
|
|
1021
|
+
}
|
|
1022
|
+
toJSON() {
|
|
1023
|
+
return {
|
|
1024
|
+
...super.toJSON(),
|
|
1025
|
+
type: "AST_LITERAL_NODE",
|
|
1026
|
+
content: this.content,
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
treeInspect() {
|
|
1030
|
+
let output = "";
|
|
1031
|
+
output += `@ LiteralNode ${this.location.treeInspectWithLabel()}\n`;
|
|
1032
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
1033
|
+
output += `└── content: ${this.content ? JSON.stringify(this.content) : "∅"}\n`;
|
|
1034
|
+
// output += "\n";
|
|
1035
|
+
return output;
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
class HTMLOpenTagNode extends Node {
|
|
1039
|
+
tag_opening;
|
|
1040
|
+
tag_name;
|
|
1041
|
+
tag_closing;
|
|
1042
|
+
children;
|
|
1043
|
+
is_void;
|
|
1044
|
+
static from(data) {
|
|
1045
|
+
return new HTMLOpenTagNode({
|
|
1046
|
+
type: data.type,
|
|
1047
|
+
location: Location.from(data.location),
|
|
1048
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
1049
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
1050
|
+
tag_name: data.tag_name ? Token.from(data.tag_name) : null,
|
|
1051
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
1052
|
+
children: (data.children || []).map(node => fromSerializedNode(node)),
|
|
1053
|
+
is_void: data.is_void,
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
constructor(props) {
|
|
1057
|
+
super(props.type, props.location, props.errors);
|
|
1058
|
+
this.tag_opening = props.tag_opening;
|
|
1059
|
+
this.tag_name = props.tag_name;
|
|
1060
|
+
this.tag_closing = props.tag_closing;
|
|
1061
|
+
this.children = props.children;
|
|
1062
|
+
this.is_void = props.is_void;
|
|
1063
|
+
}
|
|
1064
|
+
childNodes() {
|
|
1065
|
+
return [
|
|
1066
|
+
...this.children,
|
|
1067
|
+
].filter(node => node !== null && node !== undefined);
|
|
1068
|
+
}
|
|
1069
|
+
recursiveErrors() {
|
|
1070
|
+
return [
|
|
1071
|
+
...this.errors,
|
|
1072
|
+
...this.children.map(node => node.recursiveErrors()),
|
|
1073
|
+
].flat();
|
|
1074
|
+
}
|
|
1075
|
+
toJSON() {
|
|
1076
|
+
return {
|
|
1077
|
+
...super.toJSON(),
|
|
1078
|
+
type: "AST_HTML_OPEN_TAG_NODE",
|
|
1079
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
1080
|
+
tag_name: this.tag_name ? this.tag_name.toJSON() : null,
|
|
1081
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
1082
|
+
children: this.children.map(node => node.toJSON()),
|
|
1083
|
+
is_void: this.is_void,
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
treeInspect() {
|
|
1087
|
+
let output = "";
|
|
1088
|
+
output += `@ HTMLOpenTagNode ${this.location.treeInspectWithLabel()}\n`;
|
|
1089
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
1090
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
1091
|
+
output += `├── tag_name: ${this.tag_name ? this.tag_name.treeInspect() : "∅"}\n`;
|
|
1092
|
+
output += `├── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
1093
|
+
output += `├── children: ${this.inspectArray(this.children, "│ ")}`;
|
|
1094
|
+
output += `└── is_void: ${typeof this.is_void === 'boolean' ? String(this.is_void) : "∅"}\n`;
|
|
1095
|
+
// output += "\n";
|
|
1096
|
+
return output;
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
class HTMLCloseTagNode extends Node {
|
|
1100
|
+
tag_opening;
|
|
1101
|
+
tag_name;
|
|
1102
|
+
tag_closing;
|
|
1103
|
+
static from(data) {
|
|
1104
|
+
return new HTMLCloseTagNode({
|
|
1105
|
+
type: data.type,
|
|
1106
|
+
location: Location.from(data.location),
|
|
1107
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
1108
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
1109
|
+
tag_name: data.tag_name ? Token.from(data.tag_name) : null,
|
|
1110
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
constructor(props) {
|
|
1114
|
+
super(props.type, props.location, props.errors);
|
|
1115
|
+
this.tag_opening = props.tag_opening;
|
|
1116
|
+
this.tag_name = props.tag_name;
|
|
1117
|
+
this.tag_closing = props.tag_closing;
|
|
1118
|
+
}
|
|
1119
|
+
childNodes() {
|
|
1120
|
+
return [].filter(node => node !== null && node !== undefined);
|
|
1121
|
+
}
|
|
1122
|
+
recursiveErrors() {
|
|
1123
|
+
return [
|
|
1124
|
+
...this.errors,
|
|
1125
|
+
].flat();
|
|
1126
|
+
}
|
|
1127
|
+
toJSON() {
|
|
1128
|
+
return {
|
|
1129
|
+
...super.toJSON(),
|
|
1130
|
+
type: "AST_HTML_CLOSE_TAG_NODE",
|
|
1131
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
1132
|
+
tag_name: this.tag_name ? this.tag_name.toJSON() : null,
|
|
1133
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
1134
|
+
};
|
|
1135
|
+
}
|
|
1136
|
+
treeInspect() {
|
|
1137
|
+
let output = "";
|
|
1138
|
+
output += `@ HTMLCloseTagNode ${this.location.treeInspectWithLabel()}\n`;
|
|
1139
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
1140
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
1141
|
+
output += `├── tag_name: ${this.tag_name ? this.tag_name.treeInspect() : "∅"}\n`;
|
|
1142
|
+
output += `└── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
1143
|
+
// output += "\n";
|
|
1144
|
+
return output;
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
class HTMLSelfCloseTagNode extends Node {
|
|
1148
|
+
tag_opening;
|
|
1149
|
+
tag_name;
|
|
1150
|
+
attributes;
|
|
1151
|
+
tag_closing;
|
|
1152
|
+
is_void;
|
|
1153
|
+
static from(data) {
|
|
1154
|
+
return new HTMLSelfCloseTagNode({
|
|
1155
|
+
type: data.type,
|
|
1156
|
+
location: Location.from(data.location),
|
|
1157
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
1158
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
1159
|
+
tag_name: data.tag_name ? Token.from(data.tag_name) : null,
|
|
1160
|
+
attributes: (data.attributes || []).map(node => fromSerializedNode(node)),
|
|
1161
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
1162
|
+
is_void: data.is_void,
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
constructor(props) {
|
|
1166
|
+
super(props.type, props.location, props.errors);
|
|
1167
|
+
this.tag_opening = props.tag_opening;
|
|
1168
|
+
this.tag_name = props.tag_name;
|
|
1169
|
+
this.attributes = props.attributes;
|
|
1170
|
+
this.tag_closing = props.tag_closing;
|
|
1171
|
+
this.is_void = props.is_void;
|
|
1172
|
+
}
|
|
1173
|
+
childNodes() {
|
|
1174
|
+
return [
|
|
1175
|
+
...this.attributes,
|
|
1176
|
+
].filter(node => node !== null && node !== undefined);
|
|
1177
|
+
}
|
|
1178
|
+
recursiveErrors() {
|
|
1179
|
+
return [
|
|
1180
|
+
...this.errors,
|
|
1181
|
+
...this.attributes.map(node => node.recursiveErrors()),
|
|
1182
|
+
].flat();
|
|
1183
|
+
}
|
|
1184
|
+
toJSON() {
|
|
1185
|
+
return {
|
|
1186
|
+
...super.toJSON(),
|
|
1187
|
+
type: "AST_HTML_SELF_CLOSE_TAG_NODE",
|
|
1188
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
1189
|
+
tag_name: this.tag_name ? this.tag_name.toJSON() : null,
|
|
1190
|
+
attributes: this.attributes.map(node => node.toJSON()),
|
|
1191
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
1192
|
+
is_void: this.is_void,
|
|
1193
|
+
};
|
|
1194
|
+
}
|
|
1195
|
+
treeInspect() {
|
|
1196
|
+
let output = "";
|
|
1197
|
+
output += `@ HTMLSelfCloseTagNode ${this.location.treeInspectWithLabel()}\n`;
|
|
1198
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
1199
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
1200
|
+
output += `├── tag_name: ${this.tag_name ? this.tag_name.treeInspect() : "∅"}\n`;
|
|
1201
|
+
output += `├── attributes: ${this.inspectArray(this.attributes, "│ ")}`;
|
|
1202
|
+
output += `├── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
1203
|
+
output += `└── is_void: ${typeof this.is_void === 'boolean' ? String(this.is_void) : "∅"}\n`;
|
|
1204
|
+
// output += "\n";
|
|
1205
|
+
return output;
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
class HTMLElementNode extends Node {
|
|
1209
|
+
open_tag;
|
|
1210
|
+
tag_name;
|
|
1211
|
+
body;
|
|
1212
|
+
close_tag;
|
|
1213
|
+
is_void;
|
|
1214
|
+
static from(data) {
|
|
1215
|
+
return new HTMLElementNode({
|
|
1216
|
+
type: data.type,
|
|
1217
|
+
location: Location.from(data.location),
|
|
1218
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
1219
|
+
open_tag: data.open_tag ? fromSerializedNode(data.open_tag) : null,
|
|
1220
|
+
tag_name: data.tag_name ? Token.from(data.tag_name) : null,
|
|
1221
|
+
body: (data.body || []).map(node => fromSerializedNode(node)),
|
|
1222
|
+
close_tag: data.close_tag ? fromSerializedNode(data.close_tag) : null,
|
|
1223
|
+
is_void: data.is_void,
|
|
1224
|
+
});
|
|
1225
|
+
}
|
|
1226
|
+
constructor(props) {
|
|
1227
|
+
super(props.type, props.location, props.errors);
|
|
1228
|
+
this.open_tag = props.open_tag;
|
|
1229
|
+
this.tag_name = props.tag_name;
|
|
1230
|
+
this.body = props.body;
|
|
1231
|
+
this.close_tag = props.close_tag;
|
|
1232
|
+
this.is_void = props.is_void;
|
|
1233
|
+
}
|
|
1234
|
+
childNodes() {
|
|
1235
|
+
return [
|
|
1236
|
+
this.open_tag,
|
|
1237
|
+
...this.body,
|
|
1238
|
+
this.close_tag,
|
|
1239
|
+
].filter(node => node !== null && node !== undefined);
|
|
1240
|
+
}
|
|
1241
|
+
recursiveErrors() {
|
|
1242
|
+
return [
|
|
1243
|
+
...this.errors,
|
|
1244
|
+
this.open_tag ? this.open_tag.recursiveErrors() : [],
|
|
1245
|
+
...this.body.map(node => node.recursiveErrors()),
|
|
1246
|
+
this.close_tag ? this.close_tag.recursiveErrors() : [],
|
|
1247
|
+
].flat();
|
|
1248
|
+
}
|
|
1249
|
+
toJSON() {
|
|
1250
|
+
return {
|
|
1251
|
+
...super.toJSON(),
|
|
1252
|
+
type: "AST_HTML_ELEMENT_NODE",
|
|
1253
|
+
open_tag: this.open_tag ? this.open_tag.toJSON() : null,
|
|
1254
|
+
tag_name: this.tag_name ? this.tag_name.toJSON() : null,
|
|
1255
|
+
body: this.body.map(node => node.toJSON()),
|
|
1256
|
+
close_tag: this.close_tag ? this.close_tag.toJSON() : null,
|
|
1257
|
+
is_void: this.is_void,
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1260
|
+
treeInspect() {
|
|
1261
|
+
let output = "";
|
|
1262
|
+
output += `@ HTMLElementNode ${this.location.treeInspectWithLabel()}\n`;
|
|
1263
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
1264
|
+
output += `├── open_tag: ${this.inspectNode(this.open_tag, "│ ")}`;
|
|
1265
|
+
output += `├── tag_name: ${this.tag_name ? this.tag_name.treeInspect() : "∅"}\n`;
|
|
1266
|
+
output += `├── body: ${this.inspectArray(this.body, "│ ")}`;
|
|
1267
|
+
output += `├── close_tag: ${this.inspectNode(this.close_tag, "│ ")}`;
|
|
1268
|
+
output += `└── is_void: ${typeof this.is_void === 'boolean' ? String(this.is_void) : "∅"}\n`;
|
|
1269
|
+
// output += "\n";
|
|
1270
|
+
return output;
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
class HTMLAttributeValueNode extends Node {
|
|
1274
|
+
open_quote;
|
|
1275
|
+
children;
|
|
1276
|
+
close_quote;
|
|
1277
|
+
quoted;
|
|
1278
|
+
static from(data) {
|
|
1279
|
+
return new HTMLAttributeValueNode({
|
|
1280
|
+
type: data.type,
|
|
1281
|
+
location: Location.from(data.location),
|
|
1282
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
1283
|
+
open_quote: data.open_quote ? Token.from(data.open_quote) : null,
|
|
1284
|
+
children: (data.children || []).map(node => fromSerializedNode(node)),
|
|
1285
|
+
close_quote: data.close_quote ? Token.from(data.close_quote) : null,
|
|
1286
|
+
quoted: data.quoted,
|
|
1287
|
+
});
|
|
1288
|
+
}
|
|
1289
|
+
constructor(props) {
|
|
1290
|
+
super(props.type, props.location, props.errors);
|
|
1291
|
+
this.open_quote = props.open_quote;
|
|
1292
|
+
this.children = props.children;
|
|
1293
|
+
this.close_quote = props.close_quote;
|
|
1294
|
+
this.quoted = props.quoted;
|
|
1295
|
+
}
|
|
1296
|
+
childNodes() {
|
|
1297
|
+
return [
|
|
1298
|
+
...this.children,
|
|
1299
|
+
].filter(node => node !== null && node !== undefined);
|
|
1300
|
+
}
|
|
1301
|
+
recursiveErrors() {
|
|
1302
|
+
return [
|
|
1303
|
+
...this.errors,
|
|
1304
|
+
...this.children.map(node => node.recursiveErrors()),
|
|
1305
|
+
].flat();
|
|
1306
|
+
}
|
|
1307
|
+
toJSON() {
|
|
1308
|
+
return {
|
|
1309
|
+
...super.toJSON(),
|
|
1310
|
+
type: "AST_HTML_ATTRIBUTE_VALUE_NODE",
|
|
1311
|
+
open_quote: this.open_quote ? this.open_quote.toJSON() : null,
|
|
1312
|
+
children: this.children.map(node => node.toJSON()),
|
|
1313
|
+
close_quote: this.close_quote ? this.close_quote.toJSON() : null,
|
|
1314
|
+
quoted: this.quoted,
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
treeInspect() {
|
|
1318
|
+
let output = "";
|
|
1319
|
+
output += `@ HTMLAttributeValueNode ${this.location.treeInspectWithLabel()}\n`;
|
|
1320
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
1321
|
+
output += `├── open_quote: ${this.open_quote ? this.open_quote.treeInspect() : "∅"}\n`;
|
|
1322
|
+
output += `├── children: ${this.inspectArray(this.children, "│ ")}`;
|
|
1323
|
+
output += `├── close_quote: ${this.close_quote ? this.close_quote.treeInspect() : "∅"}\n`;
|
|
1324
|
+
output += `└── quoted: ${typeof this.quoted === 'boolean' ? String(this.quoted) : "∅"}\n`;
|
|
1325
|
+
// output += "\n";
|
|
1326
|
+
return output;
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
class HTMLAttributeNameNode extends Node {
|
|
1330
|
+
name;
|
|
1331
|
+
static from(data) {
|
|
1332
|
+
return new HTMLAttributeNameNode({
|
|
1333
|
+
type: data.type,
|
|
1334
|
+
location: Location.from(data.location),
|
|
1335
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
1336
|
+
name: data.name ? Token.from(data.name) : null,
|
|
1337
|
+
});
|
|
1338
|
+
}
|
|
1339
|
+
constructor(props) {
|
|
1340
|
+
super(props.type, props.location, props.errors);
|
|
1341
|
+
this.name = props.name;
|
|
1342
|
+
}
|
|
1343
|
+
childNodes() {
|
|
1344
|
+
return [].filter(node => node !== null && node !== undefined);
|
|
1345
|
+
}
|
|
1346
|
+
recursiveErrors() {
|
|
1347
|
+
return [
|
|
1348
|
+
...this.errors,
|
|
1349
|
+
].flat();
|
|
1350
|
+
}
|
|
1351
|
+
toJSON() {
|
|
1352
|
+
return {
|
|
1353
|
+
...super.toJSON(),
|
|
1354
|
+
type: "AST_HTML_ATTRIBUTE_NAME_NODE",
|
|
1355
|
+
name: this.name ? this.name.toJSON() : null,
|
|
1356
|
+
};
|
|
1357
|
+
}
|
|
1358
|
+
treeInspect() {
|
|
1359
|
+
let output = "";
|
|
1360
|
+
output += `@ HTMLAttributeNameNode ${this.location.treeInspectWithLabel()}\n`;
|
|
1361
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
1362
|
+
output += `└── name: ${this.name ? this.name.treeInspect() : "∅"}\n`;
|
|
1363
|
+
// output += "\n";
|
|
1364
|
+
return output;
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
class HTMLAttributeNode extends Node {
|
|
1368
|
+
name;
|
|
1369
|
+
equals;
|
|
1370
|
+
value;
|
|
1371
|
+
static from(data) {
|
|
1372
|
+
return new HTMLAttributeNode({
|
|
1373
|
+
type: data.type,
|
|
1374
|
+
location: Location.from(data.location),
|
|
1375
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
1376
|
+
name: data.name ? fromSerializedNode(data.name) : null,
|
|
1377
|
+
equals: data.equals ? Token.from(data.equals) : null,
|
|
1378
|
+
value: data.value ? fromSerializedNode(data.value) : null,
|
|
1379
|
+
});
|
|
1380
|
+
}
|
|
1381
|
+
constructor(props) {
|
|
1382
|
+
super(props.type, props.location, props.errors);
|
|
1383
|
+
this.name = props.name;
|
|
1384
|
+
this.equals = props.equals;
|
|
1385
|
+
this.value = props.value;
|
|
1386
|
+
}
|
|
1387
|
+
childNodes() {
|
|
1388
|
+
return [
|
|
1389
|
+
this.name,
|
|
1390
|
+
this.value,
|
|
1391
|
+
].filter(node => node !== null && node !== undefined);
|
|
1392
|
+
}
|
|
1393
|
+
recursiveErrors() {
|
|
1394
|
+
return [
|
|
1395
|
+
...this.errors,
|
|
1396
|
+
this.name ? this.name.recursiveErrors() : [],
|
|
1397
|
+
this.value ? this.value.recursiveErrors() : [],
|
|
1398
|
+
].flat();
|
|
1399
|
+
}
|
|
1400
|
+
toJSON() {
|
|
1401
|
+
return {
|
|
1402
|
+
...super.toJSON(),
|
|
1403
|
+
type: "AST_HTML_ATTRIBUTE_NODE",
|
|
1404
|
+
name: this.name ? this.name.toJSON() : null,
|
|
1405
|
+
equals: this.equals ? this.equals.toJSON() : null,
|
|
1406
|
+
value: this.value ? this.value.toJSON() : null,
|
|
1407
|
+
};
|
|
1408
|
+
}
|
|
1409
|
+
treeInspect() {
|
|
1410
|
+
let output = "";
|
|
1411
|
+
output += `@ HTMLAttributeNode ${this.location.treeInspectWithLabel()}\n`;
|
|
1412
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
1413
|
+
output += `├── name: ${this.inspectNode(this.name, "│ ")}`;
|
|
1414
|
+
output += `├── equals: ${this.equals ? this.equals.treeInspect() : "∅"}\n`;
|
|
1415
|
+
output += `└── value: ${this.inspectNode(this.value, " ")}`;
|
|
1416
|
+
// output += "\n";
|
|
1417
|
+
return output;
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
class HTMLTextNode extends Node {
|
|
1421
|
+
content;
|
|
1422
|
+
static from(data) {
|
|
1423
|
+
return new HTMLTextNode({
|
|
1424
|
+
type: data.type,
|
|
1425
|
+
location: Location.from(data.location),
|
|
1426
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
1427
|
+
content: data.content,
|
|
1428
|
+
});
|
|
1429
|
+
}
|
|
1430
|
+
constructor(props) {
|
|
1431
|
+
super(props.type, props.location, props.errors);
|
|
1432
|
+
this.content = convertToUTF8(props.content);
|
|
1433
|
+
}
|
|
1434
|
+
childNodes() {
|
|
1435
|
+
return [].filter(node => node !== null && node !== undefined);
|
|
1436
|
+
}
|
|
1437
|
+
recursiveErrors() {
|
|
1438
|
+
return [
|
|
1439
|
+
...this.errors,
|
|
1440
|
+
].flat();
|
|
1441
|
+
}
|
|
1442
|
+
toJSON() {
|
|
1443
|
+
return {
|
|
1444
|
+
...super.toJSON(),
|
|
1445
|
+
type: "AST_HTML_TEXT_NODE",
|
|
1446
|
+
content: this.content,
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
treeInspect() {
|
|
1450
|
+
let output = "";
|
|
1451
|
+
output += `@ HTMLTextNode ${this.location.treeInspectWithLabel()}\n`;
|
|
1452
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
1453
|
+
output += `└── content: ${this.content ? JSON.stringify(this.content) : "∅"}\n`;
|
|
1454
|
+
// output += "\n";
|
|
1455
|
+
return output;
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
class HTMLCommentNode extends Node {
|
|
1459
|
+
comment_start;
|
|
1460
|
+
children;
|
|
1461
|
+
comment_end;
|
|
1462
|
+
static from(data) {
|
|
1463
|
+
return new HTMLCommentNode({
|
|
1464
|
+
type: data.type,
|
|
1465
|
+
location: Location.from(data.location),
|
|
1466
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
1467
|
+
comment_start: data.comment_start ? Token.from(data.comment_start) : null,
|
|
1468
|
+
children: (data.children || []).map(node => fromSerializedNode(node)),
|
|
1469
|
+
comment_end: data.comment_end ? Token.from(data.comment_end) : null,
|
|
1470
|
+
});
|
|
1471
|
+
}
|
|
1472
|
+
constructor(props) {
|
|
1473
|
+
super(props.type, props.location, props.errors);
|
|
1474
|
+
this.comment_start = props.comment_start;
|
|
1475
|
+
this.children = props.children;
|
|
1476
|
+
this.comment_end = props.comment_end;
|
|
1477
|
+
}
|
|
1478
|
+
childNodes() {
|
|
1479
|
+
return [
|
|
1480
|
+
...this.children,
|
|
1481
|
+
].filter(node => node !== null && node !== undefined);
|
|
1482
|
+
}
|
|
1483
|
+
recursiveErrors() {
|
|
1484
|
+
return [
|
|
1485
|
+
...this.errors,
|
|
1486
|
+
...this.children.map(node => node.recursiveErrors()),
|
|
1487
|
+
].flat();
|
|
1488
|
+
}
|
|
1489
|
+
toJSON() {
|
|
1490
|
+
return {
|
|
1491
|
+
...super.toJSON(),
|
|
1492
|
+
type: "AST_HTML_COMMENT_NODE",
|
|
1493
|
+
comment_start: this.comment_start ? this.comment_start.toJSON() : null,
|
|
1494
|
+
children: this.children.map(node => node.toJSON()),
|
|
1495
|
+
comment_end: this.comment_end ? this.comment_end.toJSON() : null,
|
|
1496
|
+
};
|
|
1497
|
+
}
|
|
1498
|
+
treeInspect() {
|
|
1499
|
+
let output = "";
|
|
1500
|
+
output += `@ HTMLCommentNode ${this.location.treeInspectWithLabel()}\n`;
|
|
1501
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
1502
|
+
output += `├── comment_start: ${this.comment_start ? this.comment_start.treeInspect() : "∅"}\n`;
|
|
1503
|
+
output += `├── children: ${this.inspectArray(this.children, "│ ")}`;
|
|
1504
|
+
output += `└── comment_end: ${this.comment_end ? this.comment_end.treeInspect() : "∅"}\n`;
|
|
1505
|
+
// output += "\n";
|
|
1506
|
+
return output;
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
class HTMLDoctypeNode extends Node {
|
|
1510
|
+
tag_opening;
|
|
1511
|
+
children;
|
|
1512
|
+
tag_closing;
|
|
1513
|
+
static from(data) {
|
|
1514
|
+
return new HTMLDoctypeNode({
|
|
1515
|
+
type: data.type,
|
|
1516
|
+
location: Location.from(data.location),
|
|
1517
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
1518
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
1519
|
+
children: (data.children || []).map(node => fromSerializedNode(node)),
|
|
1520
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
1521
|
+
});
|
|
1522
|
+
}
|
|
1523
|
+
constructor(props) {
|
|
1524
|
+
super(props.type, props.location, props.errors);
|
|
1525
|
+
this.tag_opening = props.tag_opening;
|
|
1526
|
+
this.children = props.children;
|
|
1527
|
+
this.tag_closing = props.tag_closing;
|
|
1528
|
+
}
|
|
1529
|
+
childNodes() {
|
|
1530
|
+
return [
|
|
1531
|
+
...this.children,
|
|
1532
|
+
].filter(node => node !== null && node !== undefined);
|
|
1533
|
+
}
|
|
1534
|
+
recursiveErrors() {
|
|
1535
|
+
return [
|
|
1536
|
+
...this.errors,
|
|
1537
|
+
...this.children.map(node => node.recursiveErrors()),
|
|
1538
|
+
].flat();
|
|
1539
|
+
}
|
|
1540
|
+
toJSON() {
|
|
1541
|
+
return {
|
|
1542
|
+
...super.toJSON(),
|
|
1543
|
+
type: "AST_HTML_DOCTYPE_NODE",
|
|
1544
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
1545
|
+
children: this.children.map(node => node.toJSON()),
|
|
1546
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
1547
|
+
};
|
|
1548
|
+
}
|
|
1549
|
+
treeInspect() {
|
|
1550
|
+
let output = "";
|
|
1551
|
+
output += `@ HTMLDoctypeNode ${this.location.treeInspectWithLabel()}\n`;
|
|
1552
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
1553
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
1554
|
+
output += `├── children: ${this.inspectArray(this.children, "│ ")}`;
|
|
1555
|
+
output += `└── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
1556
|
+
// output += "\n";
|
|
1557
|
+
return output;
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
class WhitespaceNode extends Node {
|
|
1561
|
+
value;
|
|
1562
|
+
static from(data) {
|
|
1563
|
+
return new WhitespaceNode({
|
|
1564
|
+
type: data.type,
|
|
1565
|
+
location: Location.from(data.location),
|
|
1566
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
1567
|
+
value: data.value ? Token.from(data.value) : null,
|
|
1568
|
+
});
|
|
1569
|
+
}
|
|
1570
|
+
constructor(props) {
|
|
1571
|
+
super(props.type, props.location, props.errors);
|
|
1572
|
+
this.value = props.value;
|
|
1573
|
+
}
|
|
1574
|
+
childNodes() {
|
|
1575
|
+
return [].filter(node => node !== null && node !== undefined);
|
|
1576
|
+
}
|
|
1577
|
+
recursiveErrors() {
|
|
1578
|
+
return [
|
|
1579
|
+
...this.errors,
|
|
1580
|
+
].flat();
|
|
1581
|
+
}
|
|
1582
|
+
toJSON() {
|
|
1583
|
+
return {
|
|
1584
|
+
...super.toJSON(),
|
|
1585
|
+
type: "AST_WHITESPACE_NODE",
|
|
1586
|
+
value: this.value ? this.value.toJSON() : null,
|
|
1587
|
+
};
|
|
1588
|
+
}
|
|
1589
|
+
treeInspect() {
|
|
1590
|
+
let output = "";
|
|
1591
|
+
output += `@ WhitespaceNode ${this.location.treeInspectWithLabel()}\n`;
|
|
1592
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
1593
|
+
output += `└── value: ${this.value ? this.value.treeInspect() : "∅"}\n`;
|
|
1594
|
+
// output += "\n";
|
|
1595
|
+
return output;
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
class ERBContentNode extends Node {
|
|
1599
|
+
tag_opening;
|
|
1600
|
+
content;
|
|
1601
|
+
tag_closing;
|
|
1602
|
+
// no-op for analyzed_ruby
|
|
1603
|
+
parsed;
|
|
1604
|
+
valid;
|
|
1605
|
+
static from(data) {
|
|
1606
|
+
return new ERBContentNode({
|
|
1607
|
+
type: data.type,
|
|
1608
|
+
location: Location.from(data.location),
|
|
1609
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
1610
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
1611
|
+
content: data.content ? Token.from(data.content) : null,
|
|
1612
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
1613
|
+
// no-op for analyzed_ruby
|
|
1614
|
+
parsed: data.parsed,
|
|
1615
|
+
valid: data.valid,
|
|
1616
|
+
});
|
|
1617
|
+
}
|
|
1618
|
+
constructor(props) {
|
|
1619
|
+
super(props.type, props.location, props.errors);
|
|
1620
|
+
this.tag_opening = props.tag_opening;
|
|
1621
|
+
this.content = props.content;
|
|
1622
|
+
this.tag_closing = props.tag_closing;
|
|
1623
|
+
// no-op for analyzed_ruby
|
|
1624
|
+
this.parsed = props.parsed;
|
|
1625
|
+
this.valid = props.valid;
|
|
1626
|
+
}
|
|
1627
|
+
childNodes() {
|
|
1628
|
+
return [].filter(node => node !== null && node !== undefined);
|
|
1629
|
+
}
|
|
1630
|
+
recursiveErrors() {
|
|
1631
|
+
return [
|
|
1632
|
+
...this.errors,
|
|
1633
|
+
].flat();
|
|
1634
|
+
}
|
|
1635
|
+
toJSON() {
|
|
1636
|
+
return {
|
|
1637
|
+
...super.toJSON(),
|
|
1638
|
+
type: "AST_ERB_CONTENT_NODE",
|
|
1639
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
1640
|
+
content: this.content ? this.content.toJSON() : null,
|
|
1641
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
1642
|
+
// no-op for analyzed_ruby
|
|
1643
|
+
parsed: this.parsed,
|
|
1644
|
+
valid: this.valid,
|
|
1645
|
+
};
|
|
1646
|
+
}
|
|
1647
|
+
treeInspect() {
|
|
1648
|
+
let output = "";
|
|
1649
|
+
output += `@ ERBContentNode ${this.location.treeInspectWithLabel()}\n`;
|
|
1650
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
1651
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
1652
|
+
output += `├── content: ${this.content ? this.content.treeInspect() : "∅"}\n`;
|
|
1653
|
+
output += `├── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
1654
|
+
// no-op for analyzed_ruby
|
|
1655
|
+
output += `├── parsed: ${typeof this.parsed === 'boolean' ? String(this.parsed) : "∅"}\n`;
|
|
1656
|
+
output += `└── valid: ${typeof this.valid === 'boolean' ? String(this.valid) : "∅"}\n`;
|
|
1657
|
+
// output += "\n";
|
|
1658
|
+
return output;
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
class ERBEndNode extends Node {
|
|
1662
|
+
tag_opening;
|
|
1663
|
+
content;
|
|
1664
|
+
tag_closing;
|
|
1665
|
+
static from(data) {
|
|
1666
|
+
return new ERBEndNode({
|
|
1667
|
+
type: data.type,
|
|
1668
|
+
location: Location.from(data.location),
|
|
1669
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
1670
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
1671
|
+
content: data.content ? Token.from(data.content) : null,
|
|
1672
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
1673
|
+
});
|
|
1674
|
+
}
|
|
1675
|
+
constructor(props) {
|
|
1676
|
+
super(props.type, props.location, props.errors);
|
|
1677
|
+
this.tag_opening = props.tag_opening;
|
|
1678
|
+
this.content = props.content;
|
|
1679
|
+
this.tag_closing = props.tag_closing;
|
|
1680
|
+
}
|
|
1681
|
+
childNodes() {
|
|
1682
|
+
return [].filter(node => node !== null && node !== undefined);
|
|
1683
|
+
}
|
|
1684
|
+
recursiveErrors() {
|
|
1685
|
+
return [
|
|
1686
|
+
...this.errors,
|
|
1687
|
+
].flat();
|
|
1688
|
+
}
|
|
1689
|
+
toJSON() {
|
|
1690
|
+
return {
|
|
1691
|
+
...super.toJSON(),
|
|
1692
|
+
type: "AST_ERB_END_NODE",
|
|
1693
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
1694
|
+
content: this.content ? this.content.toJSON() : null,
|
|
1695
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
1696
|
+
};
|
|
1697
|
+
}
|
|
1698
|
+
treeInspect() {
|
|
1699
|
+
let output = "";
|
|
1700
|
+
output += `@ ERBEndNode ${this.location.treeInspectWithLabel()}\n`;
|
|
1701
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
1702
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
1703
|
+
output += `├── content: ${this.content ? this.content.treeInspect() : "∅"}\n`;
|
|
1704
|
+
output += `└── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
1705
|
+
// output += "\n";
|
|
1706
|
+
return output;
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
class ERBElseNode extends Node {
|
|
1710
|
+
tag_opening;
|
|
1711
|
+
content;
|
|
1712
|
+
tag_closing;
|
|
1713
|
+
statements;
|
|
1714
|
+
static from(data) {
|
|
1715
|
+
return new ERBElseNode({
|
|
1716
|
+
type: data.type,
|
|
1717
|
+
location: Location.from(data.location),
|
|
1718
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
1719
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
1720
|
+
content: data.content ? Token.from(data.content) : null,
|
|
1721
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
1722
|
+
statements: (data.statements || []).map(node => fromSerializedNode(node)),
|
|
1723
|
+
});
|
|
1724
|
+
}
|
|
1725
|
+
constructor(props) {
|
|
1726
|
+
super(props.type, props.location, props.errors);
|
|
1727
|
+
this.tag_opening = props.tag_opening;
|
|
1728
|
+
this.content = props.content;
|
|
1729
|
+
this.tag_closing = props.tag_closing;
|
|
1730
|
+
this.statements = props.statements;
|
|
1731
|
+
}
|
|
1732
|
+
childNodes() {
|
|
1733
|
+
return [
|
|
1734
|
+
...this.statements,
|
|
1735
|
+
].filter(node => node !== null && node !== undefined);
|
|
1736
|
+
}
|
|
1737
|
+
recursiveErrors() {
|
|
1738
|
+
return [
|
|
1739
|
+
...this.errors,
|
|
1740
|
+
...this.statements.map(node => node.recursiveErrors()),
|
|
1741
|
+
].flat();
|
|
1742
|
+
}
|
|
1743
|
+
toJSON() {
|
|
1744
|
+
return {
|
|
1745
|
+
...super.toJSON(),
|
|
1746
|
+
type: "AST_ERB_ELSE_NODE",
|
|
1747
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
1748
|
+
content: this.content ? this.content.toJSON() : null,
|
|
1749
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
1750
|
+
statements: this.statements.map(node => node.toJSON()),
|
|
1751
|
+
};
|
|
1752
|
+
}
|
|
1753
|
+
treeInspect() {
|
|
1754
|
+
let output = "";
|
|
1755
|
+
output += `@ ERBElseNode ${this.location.treeInspectWithLabel()}\n`;
|
|
1756
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
1757
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
1758
|
+
output += `├── content: ${this.content ? this.content.treeInspect() : "∅"}\n`;
|
|
1759
|
+
output += `├── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
1760
|
+
output += `└── statements: ${this.inspectArray(this.statements, " ")}`;
|
|
1761
|
+
// output += "\n";
|
|
1762
|
+
return output;
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
class ERBIfNode extends Node {
|
|
1766
|
+
tag_opening;
|
|
1767
|
+
content;
|
|
1768
|
+
tag_closing;
|
|
1769
|
+
statements;
|
|
1770
|
+
subsequent;
|
|
1771
|
+
end_node;
|
|
1772
|
+
static from(data) {
|
|
1773
|
+
return new ERBIfNode({
|
|
1774
|
+
type: data.type,
|
|
1775
|
+
location: Location.from(data.location),
|
|
1776
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
1777
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
1778
|
+
content: data.content ? Token.from(data.content) : null,
|
|
1779
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
1780
|
+
statements: (data.statements || []).map(node => fromSerializedNode(node)),
|
|
1781
|
+
subsequent: data.subsequent ? fromSerializedNode(data.subsequent) : null,
|
|
1782
|
+
end_node: data.end_node ? fromSerializedNode(data.end_node) : null,
|
|
1783
|
+
});
|
|
1784
|
+
}
|
|
1785
|
+
constructor(props) {
|
|
1786
|
+
super(props.type, props.location, props.errors);
|
|
1787
|
+
this.tag_opening = props.tag_opening;
|
|
1788
|
+
this.content = props.content;
|
|
1789
|
+
this.tag_closing = props.tag_closing;
|
|
1790
|
+
this.statements = props.statements;
|
|
1791
|
+
this.subsequent = props.subsequent;
|
|
1792
|
+
this.end_node = props.end_node;
|
|
1793
|
+
}
|
|
1794
|
+
childNodes() {
|
|
1795
|
+
return [
|
|
1796
|
+
...this.statements,
|
|
1797
|
+
this.subsequent,
|
|
1798
|
+
this.end_node,
|
|
1799
|
+
].filter(node => node !== null && node !== undefined);
|
|
1800
|
+
}
|
|
1801
|
+
recursiveErrors() {
|
|
1802
|
+
return [
|
|
1803
|
+
...this.errors,
|
|
1804
|
+
...this.statements.map(node => node.recursiveErrors()),
|
|
1805
|
+
this.subsequent ? this.subsequent.recursiveErrors() : [],
|
|
1806
|
+
this.end_node ? this.end_node.recursiveErrors() : [],
|
|
1807
|
+
].flat();
|
|
1808
|
+
}
|
|
1809
|
+
toJSON() {
|
|
1810
|
+
return {
|
|
1811
|
+
...super.toJSON(),
|
|
1812
|
+
type: "AST_ERB_IF_NODE",
|
|
1813
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
1814
|
+
content: this.content ? this.content.toJSON() : null,
|
|
1815
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
1816
|
+
statements: this.statements.map(node => node.toJSON()),
|
|
1817
|
+
subsequent: this.subsequent ? this.subsequent.toJSON() : null,
|
|
1818
|
+
end_node: this.end_node ? this.end_node.toJSON() : null,
|
|
1819
|
+
};
|
|
1820
|
+
}
|
|
1821
|
+
treeInspect() {
|
|
1822
|
+
let output = "";
|
|
1823
|
+
output += `@ ERBIfNode ${this.location.treeInspectWithLabel()}\n`;
|
|
1824
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
1825
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
1826
|
+
output += `├── content: ${this.content ? this.content.treeInspect() : "∅"}\n`;
|
|
1827
|
+
output += `├── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
1828
|
+
output += `├── statements: ${this.inspectArray(this.statements, "│ ")}`;
|
|
1829
|
+
output += `├── subsequent: ${this.inspectNode(this.subsequent, "│ ")}`;
|
|
1830
|
+
output += `└── end_node: ${this.inspectNode(this.end_node, " ")}`;
|
|
1831
|
+
// output += "\n";
|
|
1832
|
+
return output;
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
class ERBBlockNode extends Node {
|
|
1836
|
+
tag_opening;
|
|
1837
|
+
content;
|
|
1838
|
+
tag_closing;
|
|
1839
|
+
body;
|
|
1840
|
+
end_node;
|
|
1841
|
+
static from(data) {
|
|
1842
|
+
return new ERBBlockNode({
|
|
1843
|
+
type: data.type,
|
|
1844
|
+
location: Location.from(data.location),
|
|
1845
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
1846
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
1847
|
+
content: data.content ? Token.from(data.content) : null,
|
|
1848
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
1849
|
+
body: (data.body || []).map(node => fromSerializedNode(node)),
|
|
1850
|
+
end_node: data.end_node ? fromSerializedNode(data.end_node) : null,
|
|
1851
|
+
});
|
|
1852
|
+
}
|
|
1853
|
+
constructor(props) {
|
|
1854
|
+
super(props.type, props.location, props.errors);
|
|
1855
|
+
this.tag_opening = props.tag_opening;
|
|
1856
|
+
this.content = props.content;
|
|
1857
|
+
this.tag_closing = props.tag_closing;
|
|
1858
|
+
this.body = props.body;
|
|
1859
|
+
this.end_node = props.end_node;
|
|
1860
|
+
}
|
|
1861
|
+
childNodes() {
|
|
1862
|
+
return [
|
|
1863
|
+
...this.body,
|
|
1864
|
+
this.end_node,
|
|
1865
|
+
].filter(node => node !== null && node !== undefined);
|
|
1866
|
+
}
|
|
1867
|
+
recursiveErrors() {
|
|
1868
|
+
return [
|
|
1869
|
+
...this.errors,
|
|
1870
|
+
...this.body.map(node => node.recursiveErrors()),
|
|
1871
|
+
this.end_node ? this.end_node.recursiveErrors() : [],
|
|
1872
|
+
].flat();
|
|
1873
|
+
}
|
|
1874
|
+
toJSON() {
|
|
1875
|
+
return {
|
|
1876
|
+
...super.toJSON(),
|
|
1877
|
+
type: "AST_ERB_BLOCK_NODE",
|
|
1878
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
1879
|
+
content: this.content ? this.content.toJSON() : null,
|
|
1880
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
1881
|
+
body: this.body.map(node => node.toJSON()),
|
|
1882
|
+
end_node: this.end_node ? this.end_node.toJSON() : null,
|
|
1883
|
+
};
|
|
1884
|
+
}
|
|
1885
|
+
treeInspect() {
|
|
1886
|
+
let output = "";
|
|
1887
|
+
output += `@ ERBBlockNode ${this.location.treeInspectWithLabel()}\n`;
|
|
1888
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
1889
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
1890
|
+
output += `├── content: ${this.content ? this.content.treeInspect() : "∅"}\n`;
|
|
1891
|
+
output += `├── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
1892
|
+
output += `├── body: ${this.inspectArray(this.body, "│ ")}`;
|
|
1893
|
+
output += `└── end_node: ${this.inspectNode(this.end_node, " ")}`;
|
|
1894
|
+
// output += "\n";
|
|
1895
|
+
return output;
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
class ERBWhenNode extends Node {
|
|
1899
|
+
tag_opening;
|
|
1900
|
+
content;
|
|
1901
|
+
tag_closing;
|
|
1902
|
+
statements;
|
|
1903
|
+
static from(data) {
|
|
1904
|
+
return new ERBWhenNode({
|
|
1905
|
+
type: data.type,
|
|
1906
|
+
location: Location.from(data.location),
|
|
1907
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
1908
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
1909
|
+
content: data.content ? Token.from(data.content) : null,
|
|
1910
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
1911
|
+
statements: (data.statements || []).map(node => fromSerializedNode(node)),
|
|
1912
|
+
});
|
|
1913
|
+
}
|
|
1914
|
+
constructor(props) {
|
|
1915
|
+
super(props.type, props.location, props.errors);
|
|
1916
|
+
this.tag_opening = props.tag_opening;
|
|
1917
|
+
this.content = props.content;
|
|
1918
|
+
this.tag_closing = props.tag_closing;
|
|
1919
|
+
this.statements = props.statements;
|
|
1920
|
+
}
|
|
1921
|
+
childNodes() {
|
|
1922
|
+
return [
|
|
1923
|
+
...this.statements,
|
|
1924
|
+
].filter(node => node !== null && node !== undefined);
|
|
1925
|
+
}
|
|
1926
|
+
recursiveErrors() {
|
|
1927
|
+
return [
|
|
1928
|
+
...this.errors,
|
|
1929
|
+
...this.statements.map(node => node.recursiveErrors()),
|
|
1930
|
+
].flat();
|
|
1931
|
+
}
|
|
1932
|
+
toJSON() {
|
|
1933
|
+
return {
|
|
1934
|
+
...super.toJSON(),
|
|
1935
|
+
type: "AST_ERB_WHEN_NODE",
|
|
1936
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
1937
|
+
content: this.content ? this.content.toJSON() : null,
|
|
1938
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
1939
|
+
statements: this.statements.map(node => node.toJSON()),
|
|
1940
|
+
};
|
|
1941
|
+
}
|
|
1942
|
+
treeInspect() {
|
|
1943
|
+
let output = "";
|
|
1944
|
+
output += `@ ERBWhenNode ${this.location.treeInspectWithLabel()}\n`;
|
|
1945
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
1946
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
1947
|
+
output += `├── content: ${this.content ? this.content.treeInspect() : "∅"}\n`;
|
|
1948
|
+
output += `├── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
1949
|
+
output += `└── statements: ${this.inspectArray(this.statements, " ")}`;
|
|
1950
|
+
// output += "\n";
|
|
1951
|
+
return output;
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
class ERBCaseNode extends Node {
|
|
1955
|
+
tag_opening;
|
|
1956
|
+
content;
|
|
1957
|
+
tag_closing;
|
|
1958
|
+
children;
|
|
1959
|
+
conditions;
|
|
1960
|
+
else_clause;
|
|
1961
|
+
end_node;
|
|
1962
|
+
static from(data) {
|
|
1963
|
+
return new ERBCaseNode({
|
|
1964
|
+
type: data.type,
|
|
1965
|
+
location: Location.from(data.location),
|
|
1966
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
1967
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
1968
|
+
content: data.content ? Token.from(data.content) : null,
|
|
1969
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
1970
|
+
children: (data.children || []).map(node => fromSerializedNode(node)),
|
|
1971
|
+
conditions: (data.conditions || []).map(node => fromSerializedNode(node)),
|
|
1972
|
+
else_clause: data.else_clause ? fromSerializedNode(data.else_clause) : null,
|
|
1973
|
+
end_node: data.end_node ? fromSerializedNode(data.end_node) : null,
|
|
1974
|
+
});
|
|
1975
|
+
}
|
|
1976
|
+
constructor(props) {
|
|
1977
|
+
super(props.type, props.location, props.errors);
|
|
1978
|
+
this.tag_opening = props.tag_opening;
|
|
1979
|
+
this.content = props.content;
|
|
1980
|
+
this.tag_closing = props.tag_closing;
|
|
1981
|
+
this.children = props.children;
|
|
1982
|
+
this.conditions = props.conditions;
|
|
1983
|
+
this.else_clause = props.else_clause;
|
|
1984
|
+
this.end_node = props.end_node;
|
|
1985
|
+
}
|
|
1986
|
+
childNodes() {
|
|
1987
|
+
return [
|
|
1988
|
+
...this.children,
|
|
1989
|
+
...this.conditions,
|
|
1990
|
+
this.else_clause,
|
|
1991
|
+
this.end_node,
|
|
1992
|
+
].filter(node => node !== null && node !== undefined);
|
|
1993
|
+
}
|
|
1994
|
+
recursiveErrors() {
|
|
1995
|
+
return [
|
|
1996
|
+
...this.errors,
|
|
1997
|
+
...this.children.map(node => node.recursiveErrors()),
|
|
1998
|
+
...this.conditions.map(node => node.recursiveErrors()),
|
|
1999
|
+
this.else_clause ? this.else_clause.recursiveErrors() : [],
|
|
2000
|
+
this.end_node ? this.end_node.recursiveErrors() : [],
|
|
2001
|
+
].flat();
|
|
2002
|
+
}
|
|
2003
|
+
toJSON() {
|
|
2004
|
+
return {
|
|
2005
|
+
...super.toJSON(),
|
|
2006
|
+
type: "AST_ERB_CASE_NODE",
|
|
2007
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
2008
|
+
content: this.content ? this.content.toJSON() : null,
|
|
2009
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
2010
|
+
children: this.children.map(node => node.toJSON()),
|
|
2011
|
+
conditions: this.conditions.map(node => node.toJSON()),
|
|
2012
|
+
else_clause: this.else_clause ? this.else_clause.toJSON() : null,
|
|
2013
|
+
end_node: this.end_node ? this.end_node.toJSON() : null,
|
|
2014
|
+
};
|
|
2015
|
+
}
|
|
2016
|
+
treeInspect() {
|
|
2017
|
+
let output = "";
|
|
2018
|
+
output += `@ ERBCaseNode ${this.location.treeInspectWithLabel()}\n`;
|
|
2019
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
2020
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
2021
|
+
output += `├── content: ${this.content ? this.content.treeInspect() : "∅"}\n`;
|
|
2022
|
+
output += `├── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
2023
|
+
output += `├── children: ${this.inspectArray(this.children, "│ ")}`;
|
|
2024
|
+
output += `├── conditions: ${this.inspectArray(this.conditions, "│ ")}`;
|
|
2025
|
+
output += `├── else_clause: ${this.inspectNode(this.else_clause, "│ ")}`;
|
|
2026
|
+
output += `└── end_node: ${this.inspectNode(this.end_node, " ")}`;
|
|
2027
|
+
// output += "\n";
|
|
2028
|
+
return output;
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
class ERBWhileNode extends Node {
|
|
2032
|
+
tag_opening;
|
|
2033
|
+
content;
|
|
2034
|
+
tag_closing;
|
|
2035
|
+
statements;
|
|
2036
|
+
end_node;
|
|
2037
|
+
static from(data) {
|
|
2038
|
+
return new ERBWhileNode({
|
|
2039
|
+
type: data.type,
|
|
2040
|
+
location: Location.from(data.location),
|
|
2041
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
2042
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
2043
|
+
content: data.content ? Token.from(data.content) : null,
|
|
2044
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
2045
|
+
statements: (data.statements || []).map(node => fromSerializedNode(node)),
|
|
2046
|
+
end_node: data.end_node ? fromSerializedNode(data.end_node) : null,
|
|
2047
|
+
});
|
|
2048
|
+
}
|
|
2049
|
+
constructor(props) {
|
|
2050
|
+
super(props.type, props.location, props.errors);
|
|
2051
|
+
this.tag_opening = props.tag_opening;
|
|
2052
|
+
this.content = props.content;
|
|
2053
|
+
this.tag_closing = props.tag_closing;
|
|
2054
|
+
this.statements = props.statements;
|
|
2055
|
+
this.end_node = props.end_node;
|
|
2056
|
+
}
|
|
2057
|
+
childNodes() {
|
|
2058
|
+
return [
|
|
2059
|
+
...this.statements,
|
|
2060
|
+
this.end_node,
|
|
2061
|
+
].filter(node => node !== null && node !== undefined);
|
|
2062
|
+
}
|
|
2063
|
+
recursiveErrors() {
|
|
2064
|
+
return [
|
|
2065
|
+
...this.errors,
|
|
2066
|
+
...this.statements.map(node => node.recursiveErrors()),
|
|
2067
|
+
this.end_node ? this.end_node.recursiveErrors() : [],
|
|
2068
|
+
].flat();
|
|
2069
|
+
}
|
|
2070
|
+
toJSON() {
|
|
2071
|
+
return {
|
|
2072
|
+
...super.toJSON(),
|
|
2073
|
+
type: "AST_ERB_WHILE_NODE",
|
|
2074
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
2075
|
+
content: this.content ? this.content.toJSON() : null,
|
|
2076
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
2077
|
+
statements: this.statements.map(node => node.toJSON()),
|
|
2078
|
+
end_node: this.end_node ? this.end_node.toJSON() : null,
|
|
2079
|
+
};
|
|
2080
|
+
}
|
|
2081
|
+
treeInspect() {
|
|
2082
|
+
let output = "";
|
|
2083
|
+
output += `@ ERBWhileNode ${this.location.treeInspectWithLabel()}\n`;
|
|
2084
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
2085
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
2086
|
+
output += `├── content: ${this.content ? this.content.treeInspect() : "∅"}\n`;
|
|
2087
|
+
output += `├── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
2088
|
+
output += `├── statements: ${this.inspectArray(this.statements, "│ ")}`;
|
|
2089
|
+
output += `└── end_node: ${this.inspectNode(this.end_node, " ")}`;
|
|
2090
|
+
// output += "\n";
|
|
2091
|
+
return output;
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
class ERBUntilNode extends Node {
|
|
2095
|
+
tag_opening;
|
|
2096
|
+
content;
|
|
2097
|
+
tag_closing;
|
|
2098
|
+
statements;
|
|
2099
|
+
end_node;
|
|
2100
|
+
static from(data) {
|
|
2101
|
+
return new ERBUntilNode({
|
|
2102
|
+
type: data.type,
|
|
2103
|
+
location: Location.from(data.location),
|
|
2104
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
2105
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
2106
|
+
content: data.content ? Token.from(data.content) : null,
|
|
2107
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
2108
|
+
statements: (data.statements || []).map(node => fromSerializedNode(node)),
|
|
2109
|
+
end_node: data.end_node ? fromSerializedNode(data.end_node) : null,
|
|
2110
|
+
});
|
|
2111
|
+
}
|
|
2112
|
+
constructor(props) {
|
|
2113
|
+
super(props.type, props.location, props.errors);
|
|
2114
|
+
this.tag_opening = props.tag_opening;
|
|
2115
|
+
this.content = props.content;
|
|
2116
|
+
this.tag_closing = props.tag_closing;
|
|
2117
|
+
this.statements = props.statements;
|
|
2118
|
+
this.end_node = props.end_node;
|
|
2119
|
+
}
|
|
2120
|
+
childNodes() {
|
|
2121
|
+
return [
|
|
2122
|
+
...this.statements,
|
|
2123
|
+
this.end_node,
|
|
2124
|
+
].filter(node => node !== null && node !== undefined);
|
|
2125
|
+
}
|
|
2126
|
+
recursiveErrors() {
|
|
2127
|
+
return [
|
|
2128
|
+
...this.errors,
|
|
2129
|
+
...this.statements.map(node => node.recursiveErrors()),
|
|
2130
|
+
this.end_node ? this.end_node.recursiveErrors() : [],
|
|
2131
|
+
].flat();
|
|
2132
|
+
}
|
|
2133
|
+
toJSON() {
|
|
2134
|
+
return {
|
|
2135
|
+
...super.toJSON(),
|
|
2136
|
+
type: "AST_ERB_UNTIL_NODE",
|
|
2137
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
2138
|
+
content: this.content ? this.content.toJSON() : null,
|
|
2139
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
2140
|
+
statements: this.statements.map(node => node.toJSON()),
|
|
2141
|
+
end_node: this.end_node ? this.end_node.toJSON() : null,
|
|
2142
|
+
};
|
|
2143
|
+
}
|
|
2144
|
+
treeInspect() {
|
|
2145
|
+
let output = "";
|
|
2146
|
+
output += `@ ERBUntilNode ${this.location.treeInspectWithLabel()}\n`;
|
|
2147
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
2148
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
2149
|
+
output += `├── content: ${this.content ? this.content.treeInspect() : "∅"}\n`;
|
|
2150
|
+
output += `├── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
2151
|
+
output += `├── statements: ${this.inspectArray(this.statements, "│ ")}`;
|
|
2152
|
+
output += `└── end_node: ${this.inspectNode(this.end_node, " ")}`;
|
|
2153
|
+
// output += "\n";
|
|
2154
|
+
return output;
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2157
|
+
class ERBForNode extends Node {
|
|
2158
|
+
tag_opening;
|
|
2159
|
+
content;
|
|
2160
|
+
tag_closing;
|
|
2161
|
+
statements;
|
|
2162
|
+
end_node;
|
|
2163
|
+
static from(data) {
|
|
2164
|
+
return new ERBForNode({
|
|
2165
|
+
type: data.type,
|
|
2166
|
+
location: Location.from(data.location),
|
|
2167
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
2168
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
2169
|
+
content: data.content ? Token.from(data.content) : null,
|
|
2170
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
2171
|
+
statements: (data.statements || []).map(node => fromSerializedNode(node)),
|
|
2172
|
+
end_node: data.end_node ? fromSerializedNode(data.end_node) : null,
|
|
2173
|
+
});
|
|
2174
|
+
}
|
|
2175
|
+
constructor(props) {
|
|
2176
|
+
super(props.type, props.location, props.errors);
|
|
2177
|
+
this.tag_opening = props.tag_opening;
|
|
2178
|
+
this.content = props.content;
|
|
2179
|
+
this.tag_closing = props.tag_closing;
|
|
2180
|
+
this.statements = props.statements;
|
|
2181
|
+
this.end_node = props.end_node;
|
|
2182
|
+
}
|
|
2183
|
+
childNodes() {
|
|
2184
|
+
return [
|
|
2185
|
+
...this.statements,
|
|
2186
|
+
this.end_node,
|
|
2187
|
+
].filter(node => node !== null && node !== undefined);
|
|
2188
|
+
}
|
|
2189
|
+
recursiveErrors() {
|
|
2190
|
+
return [
|
|
2191
|
+
...this.errors,
|
|
2192
|
+
...this.statements.map(node => node.recursiveErrors()),
|
|
2193
|
+
this.end_node ? this.end_node.recursiveErrors() : [],
|
|
2194
|
+
].flat();
|
|
2195
|
+
}
|
|
2196
|
+
toJSON() {
|
|
2197
|
+
return {
|
|
2198
|
+
...super.toJSON(),
|
|
2199
|
+
type: "AST_ERB_FOR_NODE",
|
|
2200
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
2201
|
+
content: this.content ? this.content.toJSON() : null,
|
|
2202
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
2203
|
+
statements: this.statements.map(node => node.toJSON()),
|
|
2204
|
+
end_node: this.end_node ? this.end_node.toJSON() : null,
|
|
2205
|
+
};
|
|
2206
|
+
}
|
|
2207
|
+
treeInspect() {
|
|
2208
|
+
let output = "";
|
|
2209
|
+
output += `@ ERBForNode ${this.location.treeInspectWithLabel()}\n`;
|
|
2210
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
2211
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
2212
|
+
output += `├── content: ${this.content ? this.content.treeInspect() : "∅"}\n`;
|
|
2213
|
+
output += `├── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
2214
|
+
output += `├── statements: ${this.inspectArray(this.statements, "│ ")}`;
|
|
2215
|
+
output += `└── end_node: ${this.inspectNode(this.end_node, " ")}`;
|
|
2216
|
+
// output += "\n";
|
|
2217
|
+
return output;
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
class ERBRescueNode extends Node {
|
|
2221
|
+
tag_opening;
|
|
2222
|
+
content;
|
|
2223
|
+
tag_closing;
|
|
2224
|
+
statements;
|
|
2225
|
+
subsequent;
|
|
2226
|
+
static from(data) {
|
|
2227
|
+
return new ERBRescueNode({
|
|
2228
|
+
type: data.type,
|
|
2229
|
+
location: Location.from(data.location),
|
|
2230
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
2231
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
2232
|
+
content: data.content ? Token.from(data.content) : null,
|
|
2233
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
2234
|
+
statements: (data.statements || []).map(node => fromSerializedNode(node)),
|
|
2235
|
+
subsequent: data.subsequent ? fromSerializedNode(data.subsequent) : null,
|
|
2236
|
+
});
|
|
2237
|
+
}
|
|
2238
|
+
constructor(props) {
|
|
2239
|
+
super(props.type, props.location, props.errors);
|
|
2240
|
+
this.tag_opening = props.tag_opening;
|
|
2241
|
+
this.content = props.content;
|
|
2242
|
+
this.tag_closing = props.tag_closing;
|
|
2243
|
+
this.statements = props.statements;
|
|
2244
|
+
this.subsequent = props.subsequent;
|
|
2245
|
+
}
|
|
2246
|
+
childNodes() {
|
|
2247
|
+
return [
|
|
2248
|
+
...this.statements,
|
|
2249
|
+
this.subsequent,
|
|
2250
|
+
].filter(node => node !== null && node !== undefined);
|
|
2251
|
+
}
|
|
2252
|
+
recursiveErrors() {
|
|
2253
|
+
return [
|
|
2254
|
+
...this.errors,
|
|
2255
|
+
...this.statements.map(node => node.recursiveErrors()),
|
|
2256
|
+
this.subsequent ? this.subsequent.recursiveErrors() : [],
|
|
2257
|
+
].flat();
|
|
2258
|
+
}
|
|
2259
|
+
toJSON() {
|
|
2260
|
+
return {
|
|
2261
|
+
...super.toJSON(),
|
|
2262
|
+
type: "AST_ERB_RESCUE_NODE",
|
|
2263
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
2264
|
+
content: this.content ? this.content.toJSON() : null,
|
|
2265
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
2266
|
+
statements: this.statements.map(node => node.toJSON()),
|
|
2267
|
+
subsequent: this.subsequent ? this.subsequent.toJSON() : null,
|
|
2268
|
+
};
|
|
2269
|
+
}
|
|
2270
|
+
treeInspect() {
|
|
2271
|
+
let output = "";
|
|
2272
|
+
output += `@ ERBRescueNode ${this.location.treeInspectWithLabel()}\n`;
|
|
2273
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
2274
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
2275
|
+
output += `├── content: ${this.content ? this.content.treeInspect() : "∅"}\n`;
|
|
2276
|
+
output += `├── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
2277
|
+
output += `├── statements: ${this.inspectArray(this.statements, "│ ")}`;
|
|
2278
|
+
output += `└── subsequent: ${this.inspectNode(this.subsequent, " ")}`;
|
|
2279
|
+
// output += "\n";
|
|
2280
|
+
return output;
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
class ERBEnsureNode extends Node {
|
|
2284
|
+
tag_opening;
|
|
2285
|
+
content;
|
|
2286
|
+
tag_closing;
|
|
2287
|
+
statements;
|
|
2288
|
+
static from(data) {
|
|
2289
|
+
return new ERBEnsureNode({
|
|
2290
|
+
type: data.type,
|
|
2291
|
+
location: Location.from(data.location),
|
|
2292
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
2293
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
2294
|
+
content: data.content ? Token.from(data.content) : null,
|
|
2295
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
2296
|
+
statements: (data.statements || []).map(node => fromSerializedNode(node)),
|
|
2297
|
+
});
|
|
2298
|
+
}
|
|
2299
|
+
constructor(props) {
|
|
2300
|
+
super(props.type, props.location, props.errors);
|
|
2301
|
+
this.tag_opening = props.tag_opening;
|
|
2302
|
+
this.content = props.content;
|
|
2303
|
+
this.tag_closing = props.tag_closing;
|
|
2304
|
+
this.statements = props.statements;
|
|
2305
|
+
}
|
|
2306
|
+
childNodes() {
|
|
2307
|
+
return [
|
|
2308
|
+
...this.statements,
|
|
2309
|
+
].filter(node => node !== null && node !== undefined);
|
|
2310
|
+
}
|
|
2311
|
+
recursiveErrors() {
|
|
2312
|
+
return [
|
|
2313
|
+
...this.errors,
|
|
2314
|
+
...this.statements.map(node => node.recursiveErrors()),
|
|
2315
|
+
].flat();
|
|
2316
|
+
}
|
|
2317
|
+
toJSON() {
|
|
2318
|
+
return {
|
|
2319
|
+
...super.toJSON(),
|
|
2320
|
+
type: "AST_ERB_ENSURE_NODE",
|
|
2321
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
2322
|
+
content: this.content ? this.content.toJSON() : null,
|
|
2323
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
2324
|
+
statements: this.statements.map(node => node.toJSON()),
|
|
2325
|
+
};
|
|
2326
|
+
}
|
|
2327
|
+
treeInspect() {
|
|
2328
|
+
let output = "";
|
|
2329
|
+
output += `@ ERBEnsureNode ${this.location.treeInspectWithLabel()}\n`;
|
|
2330
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
2331
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
2332
|
+
output += `├── content: ${this.content ? this.content.treeInspect() : "∅"}\n`;
|
|
2333
|
+
output += `├── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
2334
|
+
output += `└── statements: ${this.inspectArray(this.statements, " ")}`;
|
|
2335
|
+
// output += "\n";
|
|
2336
|
+
return output;
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
class ERBBeginNode extends Node {
|
|
2340
|
+
tag_opening;
|
|
2341
|
+
content;
|
|
2342
|
+
tag_closing;
|
|
2343
|
+
statements;
|
|
2344
|
+
rescue_clause;
|
|
2345
|
+
else_clause;
|
|
2346
|
+
ensure_clause;
|
|
2347
|
+
end_node;
|
|
2348
|
+
static from(data) {
|
|
2349
|
+
return new ERBBeginNode({
|
|
2350
|
+
type: data.type,
|
|
2351
|
+
location: Location.from(data.location),
|
|
2352
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
2353
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
2354
|
+
content: data.content ? Token.from(data.content) : null,
|
|
2355
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
2356
|
+
statements: (data.statements || []).map(node => fromSerializedNode(node)),
|
|
2357
|
+
rescue_clause: data.rescue_clause ? fromSerializedNode(data.rescue_clause) : null,
|
|
2358
|
+
else_clause: data.else_clause ? fromSerializedNode(data.else_clause) : null,
|
|
2359
|
+
ensure_clause: data.ensure_clause ? fromSerializedNode(data.ensure_clause) : null,
|
|
2360
|
+
end_node: data.end_node ? fromSerializedNode(data.end_node) : null,
|
|
2361
|
+
});
|
|
2362
|
+
}
|
|
2363
|
+
constructor(props) {
|
|
2364
|
+
super(props.type, props.location, props.errors);
|
|
2365
|
+
this.tag_opening = props.tag_opening;
|
|
2366
|
+
this.content = props.content;
|
|
2367
|
+
this.tag_closing = props.tag_closing;
|
|
2368
|
+
this.statements = props.statements;
|
|
2369
|
+
this.rescue_clause = props.rescue_clause;
|
|
2370
|
+
this.else_clause = props.else_clause;
|
|
2371
|
+
this.ensure_clause = props.ensure_clause;
|
|
2372
|
+
this.end_node = props.end_node;
|
|
2373
|
+
}
|
|
2374
|
+
childNodes() {
|
|
2375
|
+
return [
|
|
2376
|
+
...this.statements,
|
|
2377
|
+
this.rescue_clause,
|
|
2378
|
+
this.else_clause,
|
|
2379
|
+
this.ensure_clause,
|
|
2380
|
+
this.end_node,
|
|
2381
|
+
].filter(node => node !== null && node !== undefined);
|
|
2382
|
+
}
|
|
2383
|
+
recursiveErrors() {
|
|
2384
|
+
return [
|
|
2385
|
+
...this.errors,
|
|
2386
|
+
...this.statements.map(node => node.recursiveErrors()),
|
|
2387
|
+
this.rescue_clause ? this.rescue_clause.recursiveErrors() : [],
|
|
2388
|
+
this.else_clause ? this.else_clause.recursiveErrors() : [],
|
|
2389
|
+
this.ensure_clause ? this.ensure_clause.recursiveErrors() : [],
|
|
2390
|
+
this.end_node ? this.end_node.recursiveErrors() : [],
|
|
2391
|
+
].flat();
|
|
2392
|
+
}
|
|
2393
|
+
toJSON() {
|
|
2394
|
+
return {
|
|
2395
|
+
...super.toJSON(),
|
|
2396
|
+
type: "AST_ERB_BEGIN_NODE",
|
|
2397
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
2398
|
+
content: this.content ? this.content.toJSON() : null,
|
|
2399
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
2400
|
+
statements: this.statements.map(node => node.toJSON()),
|
|
2401
|
+
rescue_clause: this.rescue_clause ? this.rescue_clause.toJSON() : null,
|
|
2402
|
+
else_clause: this.else_clause ? this.else_clause.toJSON() : null,
|
|
2403
|
+
ensure_clause: this.ensure_clause ? this.ensure_clause.toJSON() : null,
|
|
2404
|
+
end_node: this.end_node ? this.end_node.toJSON() : null,
|
|
2405
|
+
};
|
|
2406
|
+
}
|
|
2407
|
+
treeInspect() {
|
|
2408
|
+
let output = "";
|
|
2409
|
+
output += `@ ERBBeginNode ${this.location.treeInspectWithLabel()}\n`;
|
|
2410
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
2411
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
2412
|
+
output += `├── content: ${this.content ? this.content.treeInspect() : "∅"}\n`;
|
|
2413
|
+
output += `├── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
2414
|
+
output += `├── statements: ${this.inspectArray(this.statements, "│ ")}`;
|
|
2415
|
+
output += `├── rescue_clause: ${this.inspectNode(this.rescue_clause, "│ ")}`;
|
|
2416
|
+
output += `├── else_clause: ${this.inspectNode(this.else_clause, "│ ")}`;
|
|
2417
|
+
output += `├── ensure_clause: ${this.inspectNode(this.ensure_clause, "│ ")}`;
|
|
2418
|
+
output += `└── end_node: ${this.inspectNode(this.end_node, " ")}`;
|
|
2419
|
+
// output += "\n";
|
|
2420
|
+
return output;
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
class ERBUnlessNode extends Node {
|
|
2424
|
+
tag_opening;
|
|
2425
|
+
content;
|
|
2426
|
+
tag_closing;
|
|
2427
|
+
statements;
|
|
2428
|
+
else_clause;
|
|
2429
|
+
end_node;
|
|
2430
|
+
static from(data) {
|
|
2431
|
+
return new ERBUnlessNode({
|
|
2432
|
+
type: data.type,
|
|
2433
|
+
location: Location.from(data.location),
|
|
2434
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
2435
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
2436
|
+
content: data.content ? Token.from(data.content) : null,
|
|
2437
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
2438
|
+
statements: (data.statements || []).map(node => fromSerializedNode(node)),
|
|
2439
|
+
else_clause: data.else_clause ? fromSerializedNode(data.else_clause) : null,
|
|
2440
|
+
end_node: data.end_node ? fromSerializedNode(data.end_node) : null,
|
|
2441
|
+
});
|
|
2442
|
+
}
|
|
2443
|
+
constructor(props) {
|
|
2444
|
+
super(props.type, props.location, props.errors);
|
|
2445
|
+
this.tag_opening = props.tag_opening;
|
|
2446
|
+
this.content = props.content;
|
|
2447
|
+
this.tag_closing = props.tag_closing;
|
|
2448
|
+
this.statements = props.statements;
|
|
2449
|
+
this.else_clause = props.else_clause;
|
|
2450
|
+
this.end_node = props.end_node;
|
|
2451
|
+
}
|
|
2452
|
+
childNodes() {
|
|
2453
|
+
return [
|
|
2454
|
+
...this.statements,
|
|
2455
|
+
this.else_clause,
|
|
2456
|
+
this.end_node,
|
|
2457
|
+
].filter(node => node !== null && node !== undefined);
|
|
2458
|
+
}
|
|
2459
|
+
recursiveErrors() {
|
|
2460
|
+
return [
|
|
2461
|
+
...this.errors,
|
|
2462
|
+
...this.statements.map(node => node.recursiveErrors()),
|
|
2463
|
+
this.else_clause ? this.else_clause.recursiveErrors() : [],
|
|
2464
|
+
this.end_node ? this.end_node.recursiveErrors() : [],
|
|
2465
|
+
].flat();
|
|
2466
|
+
}
|
|
2467
|
+
toJSON() {
|
|
2468
|
+
return {
|
|
2469
|
+
...super.toJSON(),
|
|
2470
|
+
type: "AST_ERB_UNLESS_NODE",
|
|
2471
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
2472
|
+
content: this.content ? this.content.toJSON() : null,
|
|
2473
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
2474
|
+
statements: this.statements.map(node => node.toJSON()),
|
|
2475
|
+
else_clause: this.else_clause ? this.else_clause.toJSON() : null,
|
|
2476
|
+
end_node: this.end_node ? this.end_node.toJSON() : null,
|
|
2477
|
+
};
|
|
2478
|
+
}
|
|
2479
|
+
treeInspect() {
|
|
2480
|
+
let output = "";
|
|
2481
|
+
output += `@ ERBUnlessNode ${this.location.treeInspectWithLabel()}\n`;
|
|
2482
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
2483
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
2484
|
+
output += `├── content: ${this.content ? this.content.treeInspect() : "∅"}\n`;
|
|
2485
|
+
output += `├── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
2486
|
+
output += `├── statements: ${this.inspectArray(this.statements, "│ ")}`;
|
|
2487
|
+
output += `├── else_clause: ${this.inspectNode(this.else_clause, "│ ")}`;
|
|
2488
|
+
output += `└── end_node: ${this.inspectNode(this.end_node, " ")}`;
|
|
2489
|
+
// output += "\n";
|
|
2490
|
+
return output;
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2493
|
+
|
|
2494
|
+
class HerbWarning {
|
|
2495
|
+
message;
|
|
2496
|
+
location;
|
|
2497
|
+
static from(warning) {
|
|
2498
|
+
return new HerbWarning(warning.message, Location.from(warning.location));
|
|
2499
|
+
}
|
|
2500
|
+
constructor(message, location) {
|
|
2501
|
+
this.message = message;
|
|
2502
|
+
this.location = location;
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2505
|
+
|
|
2506
|
+
/**
|
|
2507
|
+
* Represents the result of a parsing operation, extending the base `Result` class.
|
|
2508
|
+
* It contains the parsed document node, source code, warnings, and errors.
|
|
2509
|
+
*/
|
|
2510
|
+
class ParseResult extends Result {
|
|
2511
|
+
/** The document node generated from the source code. */
|
|
2512
|
+
value;
|
|
2513
|
+
/**
|
|
2514
|
+
* Creates a `ParseResult` instance from a serialized result.
|
|
2515
|
+
* @param result - The serialized parse result containing the value and source.
|
|
2516
|
+
* @returns A new `ParseResult` instance.
|
|
2517
|
+
*/
|
|
2518
|
+
static from(result) {
|
|
2519
|
+
return new ParseResult(DocumentNode.from(result.value), result.source, result.warnings.map((warning) => HerbWarning.from(warning)), result.errors.map((error) => HerbError.from(error)));
|
|
2520
|
+
}
|
|
2521
|
+
/**
|
|
2522
|
+
* Constructs a new `ParseResult`.
|
|
2523
|
+
* @param value - The document node.
|
|
2524
|
+
* @param source - The source code that was parsed.
|
|
2525
|
+
* @param warnings - An array of warnings encountered during parsing.
|
|
2526
|
+
* @param errors - An array of errors encountered during parsing.
|
|
2527
|
+
*/
|
|
2528
|
+
constructor(value, source, warnings = [], errors = []) {
|
|
2529
|
+
super(source, warnings, errors);
|
|
2530
|
+
this.value = value;
|
|
2531
|
+
}
|
|
2532
|
+
/**
|
|
2533
|
+
* Determines if the parsing failed.
|
|
2534
|
+
* @returns `true` if there are errors, otherwise `false`.
|
|
2535
|
+
*/
|
|
2536
|
+
failed() {
|
|
2537
|
+
// TODO: this should probably be recursive as noted in the Ruby version
|
|
2538
|
+
return this.errors.length > 0 || this.value.errors.length > 0;
|
|
2539
|
+
}
|
|
2540
|
+
/**
|
|
2541
|
+
* Determines if the parsing was successful.
|
|
2542
|
+
* @returns `true` if there are no errors, otherwise `false`.
|
|
2543
|
+
*/
|
|
2544
|
+
success() {
|
|
2545
|
+
return !this.failed();
|
|
2546
|
+
}
|
|
2547
|
+
/**
|
|
2548
|
+
* Returns a pretty-printed JSON string of the errors.
|
|
2549
|
+
* @returns A string representation of the errors.
|
|
2550
|
+
*/
|
|
2551
|
+
prettyErrors() {
|
|
2552
|
+
return JSON.stringify([...this.errors, ...this.value.errors], null, 2);
|
|
2553
|
+
}
|
|
2554
|
+
recursiveErrors() {
|
|
2555
|
+
return [...this.errors, ...this.value.recursiveErrors()];
|
|
2556
|
+
}
|
|
2557
|
+
/**
|
|
2558
|
+
* Returns a pretty-printed string of the parse result.
|
|
2559
|
+
* @returns A string representation of the parse result.
|
|
2560
|
+
*/
|
|
2561
|
+
inspect() {
|
|
2562
|
+
return this.value.inspect();
|
|
2563
|
+
}
|
|
2564
|
+
/**
|
|
2565
|
+
* Accepts a visitor to traverse the document node.
|
|
2566
|
+
* @param visitor - The visitor instance.
|
|
2567
|
+
*/
|
|
2568
|
+
visit(visitor) {
|
|
2569
|
+
visitor.visit(this.value);
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
|
|
2573
|
+
/**
|
|
2574
|
+
* The main Herb parser interface, providing methods to lex and parse input.
|
|
2575
|
+
*/
|
|
2576
|
+
class HerbBackend {
|
|
2577
|
+
/** The backend instance handling lexing and parsing. */
|
|
2578
|
+
backend = undefined;
|
|
2579
|
+
backendPromise;
|
|
2580
|
+
/**
|
|
2581
|
+
* Creates a new Herb instance.
|
|
2582
|
+
* @param backendPromise - A promise resolving to a `LibHerbBackend` implementation for lexing and parsing.
|
|
2583
|
+
* @throws Error if no valid backend is provided.
|
|
2584
|
+
*/
|
|
2585
|
+
constructor(backendPromise) {
|
|
2586
|
+
if (!backendPromise) {
|
|
2587
|
+
throw new Error("No LibHerb backend provided");
|
|
2588
|
+
}
|
|
2589
|
+
this.backendPromise = backendPromise;
|
|
2590
|
+
}
|
|
2591
|
+
/**
|
|
2592
|
+
* Loads the backend by resolving the backend promise.
|
|
2593
|
+
* @returns A promise containing the resolved `HerbBackend` instance after loading it.
|
|
2594
|
+
*/
|
|
2595
|
+
async load() {
|
|
2596
|
+
const backend = await this.backendPromise();
|
|
2597
|
+
this.backend = backend;
|
|
2598
|
+
return this;
|
|
2599
|
+
}
|
|
2600
|
+
/**
|
|
2601
|
+
* Lexes the given source string into a `LexResult`.
|
|
2602
|
+
* @param source - The source code to lex.
|
|
2603
|
+
* @returns A `LexResult` instance.
|
|
2604
|
+
* @throws Error if the backend is not loaded.
|
|
2605
|
+
*/
|
|
2606
|
+
lex(source) {
|
|
2607
|
+
this.ensureBackend();
|
|
2608
|
+
return LexResult.from(this.backend.lex(ensureString(source)));
|
|
2609
|
+
}
|
|
2610
|
+
/**
|
|
2611
|
+
* Lexes a file.
|
|
2612
|
+
* @param path - The file path to lex.
|
|
2613
|
+
* @returns A `LexResult` instance.
|
|
2614
|
+
* @throws Error if the backend is not loaded.
|
|
2615
|
+
*/
|
|
2616
|
+
lexFile(path) {
|
|
2617
|
+
this.ensureBackend();
|
|
2618
|
+
return LexResult.from(this.backend.lexFile(ensureString(path)));
|
|
2619
|
+
}
|
|
2620
|
+
/**
|
|
2621
|
+
* Parses the given source string into a `ParseResult`.
|
|
2622
|
+
* @param source - The source code to parse.
|
|
2623
|
+
* @returns A `ParseResult` instance.
|
|
2624
|
+
* @throws Error if the backend is not loaded.
|
|
2625
|
+
*/
|
|
2626
|
+
parse(source) {
|
|
2627
|
+
this.ensureBackend();
|
|
2628
|
+
return ParseResult.from(this.backend.parse(ensureString(source)));
|
|
2629
|
+
}
|
|
2630
|
+
/**
|
|
2631
|
+
* Parses a file.
|
|
2632
|
+
* @param path - The file path to parse.
|
|
2633
|
+
* @returns A `ParseResult` instance.
|
|
2634
|
+
* @throws Error if the backend is not loaded.
|
|
2635
|
+
*/
|
|
2636
|
+
parseFile(path) {
|
|
2637
|
+
this.ensureBackend();
|
|
2638
|
+
return ParseResult.from(this.backend.parseFile(ensureString(path)));
|
|
2639
|
+
}
|
|
2640
|
+
/**
|
|
2641
|
+
* Extracts embedded Ruby code from the given source.
|
|
2642
|
+
* @param source - The source code to extract Ruby from.
|
|
2643
|
+
* @returns The extracted Ruby code as a string.
|
|
2644
|
+
* @throws Error if the backend is not loaded.
|
|
2645
|
+
*/
|
|
2646
|
+
extractRuby(source) {
|
|
2647
|
+
this.ensureBackend();
|
|
2648
|
+
return this.backend.extractRuby(ensureString(source));
|
|
2649
|
+
}
|
|
2650
|
+
/**
|
|
2651
|
+
* Extracts HTML from the given source.
|
|
2652
|
+
* @param source - The source code to extract HTML from.
|
|
2653
|
+
* @returns The extracted HTML as a string.
|
|
2654
|
+
* @throws Error if the backend is not loaded.
|
|
2655
|
+
*/
|
|
2656
|
+
extractHTML(source) {
|
|
2657
|
+
this.ensureBackend();
|
|
2658
|
+
return this.backend.extractHTML(ensureString(source));
|
|
2659
|
+
}
|
|
2660
|
+
/**
|
|
2661
|
+
* Gets the Herb version information, including the core and backend versions.
|
|
2662
|
+
* @returns A version string containing backend, core, and libherb versions.
|
|
2663
|
+
* @throws Error if the backend is not loaded.
|
|
2664
|
+
*/
|
|
2665
|
+
get version() {
|
|
2666
|
+
this.ensureBackend();
|
|
2667
|
+
const backend = this.backendVersion();
|
|
2668
|
+
const core = `${packageJSON.name}@${packageJSON.version}`;
|
|
2669
|
+
const libherb = this.backend.version();
|
|
2670
|
+
return `${backend}, ${core}, ${libherb}`;
|
|
2671
|
+
}
|
|
2672
|
+
/**
|
|
2673
|
+
* Ensures that the backend is loaded.
|
|
2674
|
+
* @throws Error if the backend is not loaded.
|
|
2675
|
+
*/
|
|
2676
|
+
ensureBackend() {
|
|
2677
|
+
if (!this.isLoaded) {
|
|
2678
|
+
throw new Error("Herb backend is not loaded. Call `await Herb.load()` first.");
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
/**
|
|
2682
|
+
* Checks if the backend is loaded.
|
|
2683
|
+
* @returns True if the backend is loaded, false otherwise.
|
|
2684
|
+
*/
|
|
2685
|
+
get isLoaded() {
|
|
2686
|
+
return this.backend !== undefined;
|
|
2687
|
+
}
|
|
2688
|
+
}
|
|
2689
|
+
|
|
2690
|
+
/**
|
|
2691
|
+
* Represents a visitor that can traverse nodes.
|
|
2692
|
+
*/
|
|
2693
|
+
class Visitor {
|
|
2694
|
+
/**
|
|
2695
|
+
* Visits a node and performs an action.
|
|
2696
|
+
* @param node - The node to visit.
|
|
2697
|
+
*/
|
|
2698
|
+
visit(node) {
|
|
2699
|
+
console.log("Node", node); // TODO: implement
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
|
|
2703
|
+
export { ASTNode, DocumentNode, ERBBeginNode, ERBBlockNode, ERBCaseNode, ERBContentNode, ERBElseNode, ERBEndNode, ERBEnsureNode, ERBForNode, ERBIfNode, ERBRescueNode, ERBUnlessNode, ERBUntilNode, ERBWhenNode, ERBWhileNode, HTMLAttributeNameNode, HTMLAttributeNode, HTMLAttributeValueNode, HTMLCloseTagNode, HTMLCommentNode, HTMLDoctypeNode, HTMLElementNode, HTMLOpenTagNode, HTMLSelfCloseTagNode, HTMLTextNode, HerbBackend, LexResult, LiteralNode, Location, MissingClosingTagError, MissingOpeningTagError, ParseResult, Position, QuotesMismatchError, Range, Result, RubyParseError, TagNamesMismatchError, Token, TokenList, UnclosedElementError, UnexpectedError, UnexpectedTokenError, Visitor, VoidElementClosingTagError, WhitespaceNode, _TYPECHECK, convertToUTF8, ensureLibHerbBackend, ensureString, fromSerializedError, fromSerializedNode, isLibHerbBackend };
|
|
2704
|
+
//# sourceMappingURL=herb-core.esm.js.map
|