@herb-tools/core 0.3.1 → 0.4.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/README.md +18 -6
- package/dist/herb-core.browser.js +132 -212
- package/dist/herb-core.browser.js.map +1 -1
- package/dist/herb-core.cjs +134 -211
- package/dist/herb-core.cjs.map +1 -1
- package/dist/herb-core.esm.js +132 -212
- package/dist/herb-core.esm.js.map +1 -1
- package/dist/herb-core.umd.js +134 -211
- package/dist/herb-core.umd.js.map +1 -1
- package/dist/types/diagnostic.d.ts +55 -0
- package/dist/types/errors.d.ts +14 -19
- package/dist/types/index.d.ts +1 -0
- package/dist/types/nodes.d.ts +5 -1
- package/dist/types/token-list.d.ts +1 -0
- package/package.json +1 -2
- package/src/diagnostic.ts +78 -0
- package/src/errors.ts +82 -237
- package/src/index.ts +1 -0
- package/src/nodes.ts +78 -32
- package/src/parse-result.ts +3 -3
- package/src/token-list.ts +4 -0
package/dist/herb-core.esm.js
CHANGED
|
@@ -32,6 +32,22 @@ function ensureLibHerbBackend(object, libherbpath = "unknown") {
|
|
|
32
32
|
return object;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Converts a Diagnostic to Monaco/VSCode-compatible MonacoDiagnostic format
|
|
37
|
+
*/
|
|
38
|
+
function toMonacoDiagnostic(diagnostic) {
|
|
39
|
+
const { message, location } = diagnostic;
|
|
40
|
+
const severity = diagnostic.severity === "hint" ? "info" : diagnostic.severity;
|
|
41
|
+
return {
|
|
42
|
+
line: location.start.line,
|
|
43
|
+
column: location.start.column,
|
|
44
|
+
endLine: location.end.line,
|
|
45
|
+
endColumn: location.end.column,
|
|
46
|
+
message,
|
|
47
|
+
severity
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
35
51
|
class Position {
|
|
36
52
|
line;
|
|
37
53
|
column;
|
|
@@ -168,6 +184,11 @@ class HerbError {
|
|
|
168
184
|
type;
|
|
169
185
|
message;
|
|
170
186
|
location;
|
|
187
|
+
severity = "error";
|
|
188
|
+
source = "parser";
|
|
189
|
+
get code() {
|
|
190
|
+
return this.type;
|
|
191
|
+
}
|
|
171
192
|
static from(error) {
|
|
172
193
|
return fromSerializedError(error);
|
|
173
194
|
}
|
|
@@ -216,21 +237,15 @@ class UnexpectedError extends HerbError {
|
|
|
216
237
|
found: this.found,
|
|
217
238
|
};
|
|
218
239
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
];
|
|
230
|
-
// no-op for description
|
|
231
|
-
// no-op for expected
|
|
232
|
-
// no-op for found
|
|
233
|
-
return diagnostics;
|
|
240
|
+
toMonacoDiagnostic() {
|
|
241
|
+
return {
|
|
242
|
+
line: this.location.start.line,
|
|
243
|
+
column: this.location.start.column,
|
|
244
|
+
endLine: this.location.end.line,
|
|
245
|
+
endColumn: this.location.end.column,
|
|
246
|
+
message: this.message,
|
|
247
|
+
severity: 'error'
|
|
248
|
+
};
|
|
234
249
|
}
|
|
235
250
|
treeInspect() {
|
|
236
251
|
let output = "";
|
|
@@ -267,29 +282,15 @@ class UnexpectedTokenError extends HerbError {
|
|
|
267
282
|
found: this.found ? this.found.toJSON() : null,
|
|
268
283
|
};
|
|
269
284
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
];
|
|
281
|
-
// no-op for expected_type
|
|
282
|
-
if (this.found) {
|
|
283
|
-
diagnostics.push({
|
|
284
|
-
line: this.found.location.start.line,
|
|
285
|
-
column: this.found.location.start.column,
|
|
286
|
-
endLine: this.found.location.end.line,
|
|
287
|
-
endColumn: this.found.location.end.column,
|
|
288
|
-
message: `found "${(this.found.value)}" is here`,
|
|
289
|
-
severity: 'info'
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
return diagnostics;
|
|
285
|
+
toMonacoDiagnostic() {
|
|
286
|
+
return {
|
|
287
|
+
line: this.location.start.line,
|
|
288
|
+
column: this.location.start.column,
|
|
289
|
+
endLine: this.location.end.line,
|
|
290
|
+
endColumn: this.location.end.column,
|
|
291
|
+
message: this.message,
|
|
292
|
+
severity: 'error'
|
|
293
|
+
};
|
|
293
294
|
}
|
|
294
295
|
treeInspect() {
|
|
295
296
|
let output = "";
|
|
@@ -321,28 +322,15 @@ class MissingOpeningTagError extends HerbError {
|
|
|
321
322
|
closing_tag: this.closing_tag ? this.closing_tag.toJSON() : null,
|
|
322
323
|
};
|
|
323
324
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
}
|
|
334
|
-
];
|
|
335
|
-
if (this.closing_tag) {
|
|
336
|
-
diagnostics.push({
|
|
337
|
-
line: this.closing_tag.location.start.line,
|
|
338
|
-
column: this.closing_tag.location.start.column,
|
|
339
|
-
endLine: this.closing_tag.location.end.line,
|
|
340
|
-
endColumn: this.closing_tag.location.end.column,
|
|
341
|
-
message: `closing_tag "${(this.closing_tag.value)}" is here`,
|
|
342
|
-
severity: 'info'
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
return diagnostics;
|
|
325
|
+
toMonacoDiagnostic() {
|
|
326
|
+
return {
|
|
327
|
+
line: this.location.start.line,
|
|
328
|
+
column: this.location.start.column,
|
|
329
|
+
endLine: this.location.end.line,
|
|
330
|
+
endColumn: this.location.end.column,
|
|
331
|
+
message: this.message,
|
|
332
|
+
severity: 'error'
|
|
333
|
+
};
|
|
346
334
|
}
|
|
347
335
|
treeInspect() {
|
|
348
336
|
let output = "";
|
|
@@ -373,28 +361,15 @@ class MissingClosingTagError extends HerbError {
|
|
|
373
361
|
opening_tag: this.opening_tag ? this.opening_tag.toJSON() : null,
|
|
374
362
|
};
|
|
375
363
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
}
|
|
386
|
-
];
|
|
387
|
-
if (this.opening_tag) {
|
|
388
|
-
diagnostics.push({
|
|
389
|
-
line: this.opening_tag.location.start.line,
|
|
390
|
-
column: this.opening_tag.location.start.column,
|
|
391
|
-
endLine: this.opening_tag.location.end.line,
|
|
392
|
-
endColumn: this.opening_tag.location.end.column,
|
|
393
|
-
message: `opening_tag "${(this.opening_tag.value)}" is here`,
|
|
394
|
-
severity: 'info'
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
return diagnostics;
|
|
364
|
+
toMonacoDiagnostic() {
|
|
365
|
+
return {
|
|
366
|
+
line: this.location.start.line,
|
|
367
|
+
column: this.location.start.column,
|
|
368
|
+
endLine: this.location.end.line,
|
|
369
|
+
endColumn: this.location.end.column,
|
|
370
|
+
message: this.message,
|
|
371
|
+
severity: 'error'
|
|
372
|
+
};
|
|
398
373
|
}
|
|
399
374
|
treeInspect() {
|
|
400
375
|
let output = "";
|
|
@@ -429,38 +404,15 @@ class TagNamesMismatchError extends HerbError {
|
|
|
429
404
|
closing_tag: this.closing_tag ? this.closing_tag.toJSON() : null,
|
|
430
405
|
};
|
|
431
406
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
}
|
|
442
|
-
];
|
|
443
|
-
if (this.opening_tag) {
|
|
444
|
-
diagnostics.push({
|
|
445
|
-
line: this.opening_tag.location.start.line,
|
|
446
|
-
column: this.opening_tag.location.start.column,
|
|
447
|
-
endLine: this.opening_tag.location.end.line,
|
|
448
|
-
endColumn: this.opening_tag.location.end.column,
|
|
449
|
-
message: `opening_tag "${(this.opening_tag.value)}" is here`,
|
|
450
|
-
severity: 'info'
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
if (this.closing_tag) {
|
|
454
|
-
diagnostics.push({
|
|
455
|
-
line: this.closing_tag.location.start.line,
|
|
456
|
-
column: this.closing_tag.location.start.column,
|
|
457
|
-
endLine: this.closing_tag.location.end.line,
|
|
458
|
-
endColumn: this.closing_tag.location.end.column,
|
|
459
|
-
message: `closing_tag "${(this.closing_tag.value)}" is here`,
|
|
460
|
-
severity: 'info'
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
|
-
return diagnostics;
|
|
407
|
+
toMonacoDiagnostic() {
|
|
408
|
+
return {
|
|
409
|
+
line: this.location.start.line,
|
|
410
|
+
column: this.location.start.column,
|
|
411
|
+
endLine: this.location.end.line,
|
|
412
|
+
endColumn: this.location.end.column,
|
|
413
|
+
message: this.message,
|
|
414
|
+
severity: 'error'
|
|
415
|
+
};
|
|
464
416
|
}
|
|
465
417
|
treeInspect() {
|
|
466
418
|
let output = "";
|
|
@@ -496,38 +448,15 @@ class QuotesMismatchError extends HerbError {
|
|
|
496
448
|
closing_quote: this.closing_quote ? this.closing_quote.toJSON() : null,
|
|
497
449
|
};
|
|
498
450
|
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
}
|
|
509
|
-
];
|
|
510
|
-
if (this.opening_quote) {
|
|
511
|
-
diagnostics.push({
|
|
512
|
-
line: this.opening_quote.location.start.line,
|
|
513
|
-
column: this.opening_quote.location.start.column,
|
|
514
|
-
endLine: this.opening_quote.location.end.line,
|
|
515
|
-
endColumn: this.opening_quote.location.end.column,
|
|
516
|
-
message: `opening_quote "${(this.opening_quote.value)}" is here`,
|
|
517
|
-
severity: 'info'
|
|
518
|
-
});
|
|
519
|
-
}
|
|
520
|
-
if (this.closing_quote) {
|
|
521
|
-
diagnostics.push({
|
|
522
|
-
line: this.closing_quote.location.start.line,
|
|
523
|
-
column: this.closing_quote.location.start.column,
|
|
524
|
-
endLine: this.closing_quote.location.end.line,
|
|
525
|
-
endColumn: this.closing_quote.location.end.column,
|
|
526
|
-
message: `closing_quote "${(this.closing_quote.value)}" is here`,
|
|
527
|
-
severity: 'info'
|
|
528
|
-
});
|
|
529
|
-
}
|
|
530
|
-
return diagnostics;
|
|
451
|
+
toMonacoDiagnostic() {
|
|
452
|
+
return {
|
|
453
|
+
line: this.location.start.line,
|
|
454
|
+
column: this.location.start.column,
|
|
455
|
+
endLine: this.location.end.line,
|
|
456
|
+
endColumn: this.location.end.column,
|
|
457
|
+
message: this.message,
|
|
458
|
+
severity: 'error'
|
|
459
|
+
};
|
|
531
460
|
}
|
|
532
461
|
treeInspect() {
|
|
533
462
|
let output = "";
|
|
@@ -567,30 +496,15 @@ class VoidElementClosingTagError extends HerbError {
|
|
|
567
496
|
found: this.found,
|
|
568
497
|
};
|
|
569
498
|
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
}
|
|
580
|
-
];
|
|
581
|
-
if (this.tag_name) {
|
|
582
|
-
diagnostics.push({
|
|
583
|
-
line: this.tag_name.location.start.line,
|
|
584
|
-
column: this.tag_name.location.start.column,
|
|
585
|
-
endLine: this.tag_name.location.end.line,
|
|
586
|
-
endColumn: this.tag_name.location.end.column,
|
|
587
|
-
message: `tag_name "${(this.tag_name.value)}" is here`,
|
|
588
|
-
severity: 'info'
|
|
589
|
-
});
|
|
590
|
-
}
|
|
591
|
-
// no-op for expected
|
|
592
|
-
// no-op for found
|
|
593
|
-
return diagnostics;
|
|
499
|
+
toMonacoDiagnostic() {
|
|
500
|
+
return {
|
|
501
|
+
line: this.location.start.line,
|
|
502
|
+
column: this.location.start.column,
|
|
503
|
+
endLine: this.location.end.line,
|
|
504
|
+
endColumn: this.location.end.column,
|
|
505
|
+
message: this.message,
|
|
506
|
+
severity: 'error'
|
|
507
|
+
};
|
|
594
508
|
}
|
|
595
509
|
treeInspect() {
|
|
596
510
|
let output = "";
|
|
@@ -623,28 +537,15 @@ class UnclosedElementError extends HerbError {
|
|
|
623
537
|
opening_tag: this.opening_tag ? this.opening_tag.toJSON() : null,
|
|
624
538
|
};
|
|
625
539
|
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
}
|
|
636
|
-
];
|
|
637
|
-
if (this.opening_tag) {
|
|
638
|
-
diagnostics.push({
|
|
639
|
-
line: this.opening_tag.location.start.line,
|
|
640
|
-
column: this.opening_tag.location.start.column,
|
|
641
|
-
endLine: this.opening_tag.location.end.line,
|
|
642
|
-
endColumn: this.opening_tag.location.end.column,
|
|
643
|
-
message: `opening_tag "${(this.opening_tag.value)}" is here`,
|
|
644
|
-
severity: 'info'
|
|
645
|
-
});
|
|
646
|
-
}
|
|
647
|
-
return diagnostics;
|
|
540
|
+
toMonacoDiagnostic() {
|
|
541
|
+
return {
|
|
542
|
+
line: this.location.start.line,
|
|
543
|
+
column: this.location.start.column,
|
|
544
|
+
endLine: this.location.end.line,
|
|
545
|
+
endColumn: this.location.end.column,
|
|
546
|
+
message: this.message,
|
|
547
|
+
severity: 'error'
|
|
548
|
+
};
|
|
648
549
|
}
|
|
649
550
|
treeInspect() {
|
|
650
551
|
let output = "";
|
|
@@ -683,21 +584,15 @@ class RubyParseError extends HerbError {
|
|
|
683
584
|
level: this.level,
|
|
684
585
|
};
|
|
685
586
|
}
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
}
|
|
696
|
-
];
|
|
697
|
-
// no-op for error_message
|
|
698
|
-
// no-op for diagnostic_id
|
|
699
|
-
// no-op for level
|
|
700
|
-
return diagnostics;
|
|
587
|
+
toMonacoDiagnostic() {
|
|
588
|
+
return {
|
|
589
|
+
line: this.location.start.line,
|
|
590
|
+
column: this.location.start.column,
|
|
591
|
+
endLine: this.location.end.line,
|
|
592
|
+
endColumn: this.location.end.column,
|
|
593
|
+
message: this.message,
|
|
594
|
+
severity: 'error'
|
|
595
|
+
};
|
|
701
596
|
}
|
|
702
597
|
treeInspect() {
|
|
703
598
|
let output = "";
|
|
@@ -726,7 +621,7 @@ function fromSerializedError(error) {
|
|
|
726
621
|
}
|
|
727
622
|
|
|
728
623
|
var name = "@herb-tools/core";
|
|
729
|
-
var version = "0.
|
|
624
|
+
var version = "0.4.0";
|
|
730
625
|
var packageJSON = {
|
|
731
626
|
name: name,
|
|
732
627
|
version: version};
|
|
@@ -782,6 +677,9 @@ class TokenList {
|
|
|
782
677
|
get length() {
|
|
783
678
|
return this.list.length;
|
|
784
679
|
}
|
|
680
|
+
get tokens() {
|
|
681
|
+
return this.list;
|
|
682
|
+
}
|
|
785
683
|
[Symbol.iterator]() {
|
|
786
684
|
return this.list[Symbol.iterator]();
|
|
787
685
|
}
|
|
@@ -2868,6 +2766,28 @@ function fromSerializedNode(node) {
|
|
|
2868
2766
|
throw new Error(`Unknown node type: ${node.type}`);
|
|
2869
2767
|
}
|
|
2870
2768
|
}
|
|
2769
|
+
const ERBNodeClasses = [
|
|
2770
|
+
ERBContentNode,
|
|
2771
|
+
ERBEndNode,
|
|
2772
|
+
ERBElseNode,
|
|
2773
|
+
ERBIfNode,
|
|
2774
|
+
ERBBlockNode,
|
|
2775
|
+
ERBWhenNode,
|
|
2776
|
+
ERBCaseNode,
|
|
2777
|
+
ERBCaseMatchNode,
|
|
2778
|
+
ERBWhileNode,
|
|
2779
|
+
ERBUntilNode,
|
|
2780
|
+
ERBForNode,
|
|
2781
|
+
ERBRescueNode,
|
|
2782
|
+
ERBEnsureNode,
|
|
2783
|
+
ERBBeginNode,
|
|
2784
|
+
ERBUnlessNode,
|
|
2785
|
+
ERBYieldNode,
|
|
2786
|
+
ERBInNode,
|
|
2787
|
+
];
|
|
2788
|
+
function isERBNode(node) {
|
|
2789
|
+
return node.constructor.name.startsWith("ERB");
|
|
2790
|
+
}
|
|
2871
2791
|
|
|
2872
2792
|
/**
|
|
2873
2793
|
* Represents the result of a parsing operation, extending the base `Result` class.
|
|
@@ -2900,15 +2820,15 @@ class ParseResult extends Result {
|
|
|
2900
2820
|
* @returns `true` if there are errors, otherwise `false`.
|
|
2901
2821
|
*/
|
|
2902
2822
|
get failed() {
|
|
2903
|
-
//
|
|
2904
|
-
return this.
|
|
2823
|
+
// Consider errors on this result and recursively in the document tree
|
|
2824
|
+
return this.recursiveErrors().length > 0;
|
|
2905
2825
|
}
|
|
2906
2826
|
/**
|
|
2907
2827
|
* Determines if the parsing was successful.
|
|
2908
2828
|
* @returns `true` if there are no errors, otherwise `false`.
|
|
2909
2829
|
*/
|
|
2910
2830
|
get successful() {
|
|
2911
|
-
return this.
|
|
2831
|
+
return !this.failed;
|
|
2912
2832
|
}
|
|
2913
2833
|
/**
|
|
2914
2834
|
* Returns a pretty-printed JSON string of the errors.
|
|
@@ -3159,5 +3079,5 @@ class Visitor {
|
|
|
3159
3079
|
}
|
|
3160
3080
|
}
|
|
3161
3081
|
|
|
3162
|
-
export { DocumentNode, ERBBeginNode, ERBBlockNode, ERBCaseMatchNode, ERBCaseNode, ERBContentNode, ERBElseNode, ERBEndNode, ERBEnsureNode, ERBForNode, ERBIfNode, ERBInNode, ERBRescueNode, ERBUnlessNode, ERBUntilNode, ERBWhenNode, ERBWhileNode, ERBYieldNode, HTMLAttributeNameNode, HTMLAttributeNode, HTMLAttributeValueNode, HTMLCloseTagNode, HTMLCommentNode, HTMLDoctypeNode, HTMLElementNode, HTMLOpenTagNode, HTMLSelfCloseTagNode, HTMLTextNode, HerbBackend, HerbError, HerbWarning, LexResult, LiteralNode, Location, MissingClosingTagError, MissingOpeningTagError, Node, ParseResult, Position, QuotesMismatchError, Range, Result, RubyParseError, TagNamesMismatchError, Token, TokenList, UnclosedElementError, UnexpectedError, UnexpectedTokenError, Visitor, VoidElementClosingTagError, WhitespaceNode, _TYPECHECK, convertToUTF8, ensureLibHerbBackend, ensureString, fromSerializedError, fromSerializedNode, isLibHerbBackend };
|
|
3082
|
+
export { DocumentNode, ERBBeginNode, ERBBlockNode, ERBCaseMatchNode, ERBCaseNode, ERBContentNode, ERBElseNode, ERBEndNode, ERBEnsureNode, ERBForNode, ERBIfNode, ERBInNode, ERBNodeClasses, ERBRescueNode, ERBUnlessNode, ERBUntilNode, ERBWhenNode, ERBWhileNode, ERBYieldNode, HTMLAttributeNameNode, HTMLAttributeNode, HTMLAttributeValueNode, HTMLCloseTagNode, HTMLCommentNode, HTMLDoctypeNode, HTMLElementNode, HTMLOpenTagNode, HTMLSelfCloseTagNode, HTMLTextNode, HerbBackend, HerbError, HerbWarning, LexResult, LiteralNode, Location, MissingClosingTagError, MissingOpeningTagError, Node, ParseResult, Position, QuotesMismatchError, Range, Result, RubyParseError, TagNamesMismatchError, Token, TokenList, UnclosedElementError, UnexpectedError, UnexpectedTokenError, Visitor, VoidElementClosingTagError, WhitespaceNode, _TYPECHECK, convertToUTF8, ensureLibHerbBackend, ensureString, fromSerializedError, fromSerializedNode, isERBNode, isLibHerbBackend, toMonacoDiagnostic };
|
|
3163
3083
|
//# sourceMappingURL=herb-core.esm.js.map
|