@herb-tools/core 0.3.1 → 0.4.1

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.
@@ -38,6 +38,22 @@
38
38
  return object;
39
39
  }
40
40
 
41
+ /**
42
+ * Converts a Diagnostic to Monaco/VSCode-compatible MonacoDiagnostic format
43
+ */
44
+ function toMonacoDiagnostic(diagnostic) {
45
+ const { message, location } = diagnostic;
46
+ const severity = diagnostic.severity === "hint" ? "info" : diagnostic.severity;
47
+ return {
48
+ line: location.start.line,
49
+ column: location.start.column,
50
+ endLine: location.end.line,
51
+ endColumn: location.end.column,
52
+ message,
53
+ severity
54
+ };
55
+ }
56
+
41
57
  class Position {
42
58
  line;
43
59
  column;
@@ -169,11 +185,16 @@
169
185
  }
170
186
 
171
187
  // NOTE: This file is generated by the templates/template.rb script and should not
172
- // be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/errors.ts.erb
188
+ // be modified manually. See /Users/marcoroth/Development/herb-release-4/templates/javascript/packages/core/src/errors.ts.erb
173
189
  class HerbError {
174
190
  type;
175
191
  message;
176
192
  location;
193
+ severity = "error";
194
+ source = "parser";
195
+ get code() {
196
+ return this.type;
197
+ }
177
198
  static from(error) {
178
199
  return fromSerializedError(error);
179
200
  }
@@ -222,21 +243,15 @@
222
243
  found: this.found,
223
244
  };
224
245
  }
225
- toDiagnostics() {
226
- const diagnostics = [
227
- {
228
- line: this.location.start.line,
229
- column: this.location.start.column,
230
- endLine: this.location.end.line,
231
- endColumn: this.location.end.column,
232
- message: this.message,
233
- severity: 'error'
234
- }
235
- ];
236
- // no-op for description
237
- // no-op for expected
238
- // no-op for found
239
- return diagnostics;
246
+ toMonacoDiagnostic() {
247
+ return {
248
+ line: this.location.start.line,
249
+ column: this.location.start.column,
250
+ endLine: this.location.end.line,
251
+ endColumn: this.location.end.column,
252
+ message: this.message,
253
+ severity: 'error'
254
+ };
240
255
  }
241
256
  treeInspect() {
242
257
  let output = "";
@@ -273,29 +288,15 @@
273
288
  found: this.found ? this.found.toJSON() : null,
274
289
  };
275
290
  }
276
- toDiagnostics() {
277
- const diagnostics = [
278
- {
279
- line: this.location.start.line,
280
- column: this.location.start.column,
281
- endLine: this.location.end.line,
282
- endColumn: this.location.end.column,
283
- message: this.message,
284
- severity: 'error'
285
- }
286
- ];
287
- // no-op for expected_type
288
- if (this.found) {
289
- diagnostics.push({
290
- line: this.found.location.start.line,
291
- column: this.found.location.start.column,
292
- endLine: this.found.location.end.line,
293
- endColumn: this.found.location.end.column,
294
- message: `found "${(this.found.value)}" is here`,
295
- severity: 'info'
296
- });
297
- }
298
- return diagnostics;
291
+ toMonacoDiagnostic() {
292
+ return {
293
+ line: this.location.start.line,
294
+ column: this.location.start.column,
295
+ endLine: this.location.end.line,
296
+ endColumn: this.location.end.column,
297
+ message: this.message,
298
+ severity: 'error'
299
+ };
299
300
  }
300
301
  treeInspect() {
301
302
  let output = "";
@@ -327,28 +328,15 @@
327
328
  closing_tag: this.closing_tag ? this.closing_tag.toJSON() : null,
328
329
  };
329
330
  }
330
- toDiagnostics() {
331
- const diagnostics = [
332
- {
333
- line: this.location.start.line,
334
- column: this.location.start.column,
335
- endLine: this.location.end.line,
336
- endColumn: this.location.end.column,
337
- message: this.message,
338
- severity: 'error'
339
- }
340
- ];
341
- if (this.closing_tag) {
342
- diagnostics.push({
343
- line: this.closing_tag.location.start.line,
344
- column: this.closing_tag.location.start.column,
345
- endLine: this.closing_tag.location.end.line,
346
- endColumn: this.closing_tag.location.end.column,
347
- message: `closing_tag "${(this.closing_tag.value)}" is here`,
348
- severity: 'info'
349
- });
350
- }
351
- return diagnostics;
331
+ toMonacoDiagnostic() {
332
+ return {
333
+ line: this.location.start.line,
334
+ column: this.location.start.column,
335
+ endLine: this.location.end.line,
336
+ endColumn: this.location.end.column,
337
+ message: this.message,
338
+ severity: 'error'
339
+ };
352
340
  }
353
341
  treeInspect() {
354
342
  let output = "";
@@ -379,28 +367,15 @@
379
367
  opening_tag: this.opening_tag ? this.opening_tag.toJSON() : null,
380
368
  };
381
369
  }
382
- toDiagnostics() {
383
- const diagnostics = [
384
- {
385
- line: this.location.start.line,
386
- column: this.location.start.column,
387
- endLine: this.location.end.line,
388
- endColumn: this.location.end.column,
389
- message: this.message,
390
- severity: 'error'
391
- }
392
- ];
393
- if (this.opening_tag) {
394
- diagnostics.push({
395
- line: this.opening_tag.location.start.line,
396
- column: this.opening_tag.location.start.column,
397
- endLine: this.opening_tag.location.end.line,
398
- endColumn: this.opening_tag.location.end.column,
399
- message: `opening_tag "${(this.opening_tag.value)}" is here`,
400
- severity: 'info'
401
- });
402
- }
403
- return diagnostics;
370
+ toMonacoDiagnostic() {
371
+ return {
372
+ line: this.location.start.line,
373
+ column: this.location.start.column,
374
+ endLine: this.location.end.line,
375
+ endColumn: this.location.end.column,
376
+ message: this.message,
377
+ severity: 'error'
378
+ };
404
379
  }
405
380
  treeInspect() {
406
381
  let output = "";
@@ -435,38 +410,15 @@
435
410
  closing_tag: this.closing_tag ? this.closing_tag.toJSON() : null,
436
411
  };
437
412
  }
438
- toDiagnostics() {
439
- const diagnostics = [
440
- {
441
- line: this.location.start.line,
442
- column: this.location.start.column,
443
- endLine: this.location.end.line,
444
- endColumn: this.location.end.column,
445
- message: this.message,
446
- severity: 'error'
447
- }
448
- ];
449
- if (this.opening_tag) {
450
- diagnostics.push({
451
- line: this.opening_tag.location.start.line,
452
- column: this.opening_tag.location.start.column,
453
- endLine: this.opening_tag.location.end.line,
454
- endColumn: this.opening_tag.location.end.column,
455
- message: `opening_tag "${(this.opening_tag.value)}" is here`,
456
- severity: 'info'
457
- });
458
- }
459
- if (this.closing_tag) {
460
- diagnostics.push({
461
- line: this.closing_tag.location.start.line,
462
- column: this.closing_tag.location.start.column,
463
- endLine: this.closing_tag.location.end.line,
464
- endColumn: this.closing_tag.location.end.column,
465
- message: `closing_tag "${(this.closing_tag.value)}" is here`,
466
- severity: 'info'
467
- });
468
- }
469
- return diagnostics;
413
+ toMonacoDiagnostic() {
414
+ return {
415
+ line: this.location.start.line,
416
+ column: this.location.start.column,
417
+ endLine: this.location.end.line,
418
+ endColumn: this.location.end.column,
419
+ message: this.message,
420
+ severity: 'error'
421
+ };
470
422
  }
471
423
  treeInspect() {
472
424
  let output = "";
@@ -502,38 +454,15 @@
502
454
  closing_quote: this.closing_quote ? this.closing_quote.toJSON() : null,
503
455
  };
504
456
  }
505
- toDiagnostics() {
506
- const diagnostics = [
507
- {
508
- line: this.location.start.line,
509
- column: this.location.start.column,
510
- endLine: this.location.end.line,
511
- endColumn: this.location.end.column,
512
- message: this.message,
513
- severity: 'error'
514
- }
515
- ];
516
- if (this.opening_quote) {
517
- diagnostics.push({
518
- line: this.opening_quote.location.start.line,
519
- column: this.opening_quote.location.start.column,
520
- endLine: this.opening_quote.location.end.line,
521
- endColumn: this.opening_quote.location.end.column,
522
- message: `opening_quote "${(this.opening_quote.value)}" is here`,
523
- severity: 'info'
524
- });
525
- }
526
- if (this.closing_quote) {
527
- diagnostics.push({
528
- line: this.closing_quote.location.start.line,
529
- column: this.closing_quote.location.start.column,
530
- endLine: this.closing_quote.location.end.line,
531
- endColumn: this.closing_quote.location.end.column,
532
- message: `closing_quote "${(this.closing_quote.value)}" is here`,
533
- severity: 'info'
534
- });
535
- }
536
- return diagnostics;
457
+ toMonacoDiagnostic() {
458
+ return {
459
+ line: this.location.start.line,
460
+ column: this.location.start.column,
461
+ endLine: this.location.end.line,
462
+ endColumn: this.location.end.column,
463
+ message: this.message,
464
+ severity: 'error'
465
+ };
537
466
  }
538
467
  treeInspect() {
539
468
  let output = "";
@@ -573,30 +502,15 @@
573
502
  found: this.found,
574
503
  };
575
504
  }
576
- toDiagnostics() {
577
- const diagnostics = [
578
- {
579
- line: this.location.start.line,
580
- column: this.location.start.column,
581
- endLine: this.location.end.line,
582
- endColumn: this.location.end.column,
583
- message: this.message,
584
- severity: 'error'
585
- }
586
- ];
587
- if (this.tag_name) {
588
- diagnostics.push({
589
- line: this.tag_name.location.start.line,
590
- column: this.tag_name.location.start.column,
591
- endLine: this.tag_name.location.end.line,
592
- endColumn: this.tag_name.location.end.column,
593
- message: `tag_name "${(this.tag_name.value)}" is here`,
594
- severity: 'info'
595
- });
596
- }
597
- // no-op for expected
598
- // no-op for found
599
- return diagnostics;
505
+ toMonacoDiagnostic() {
506
+ return {
507
+ line: this.location.start.line,
508
+ column: this.location.start.column,
509
+ endLine: this.location.end.line,
510
+ endColumn: this.location.end.column,
511
+ message: this.message,
512
+ severity: 'error'
513
+ };
600
514
  }
601
515
  treeInspect() {
602
516
  let output = "";
@@ -629,28 +543,15 @@
629
543
  opening_tag: this.opening_tag ? this.opening_tag.toJSON() : null,
630
544
  };
631
545
  }
632
- toDiagnostics() {
633
- const diagnostics = [
634
- {
635
- line: this.location.start.line,
636
- column: this.location.start.column,
637
- endLine: this.location.end.line,
638
- endColumn: this.location.end.column,
639
- message: this.message,
640
- severity: 'error'
641
- }
642
- ];
643
- if (this.opening_tag) {
644
- diagnostics.push({
645
- line: this.opening_tag.location.start.line,
646
- column: this.opening_tag.location.start.column,
647
- endLine: this.opening_tag.location.end.line,
648
- endColumn: this.opening_tag.location.end.column,
649
- message: `opening_tag "${(this.opening_tag.value)}" is here`,
650
- severity: 'info'
651
- });
652
- }
653
- return diagnostics;
546
+ toMonacoDiagnostic() {
547
+ return {
548
+ line: this.location.start.line,
549
+ column: this.location.start.column,
550
+ endLine: this.location.end.line,
551
+ endColumn: this.location.end.column,
552
+ message: this.message,
553
+ severity: 'error'
554
+ };
654
555
  }
655
556
  treeInspect() {
656
557
  let output = "";
@@ -689,21 +590,15 @@
689
590
  level: this.level,
690
591
  };
691
592
  }
692
- toDiagnostics() {
693
- const diagnostics = [
694
- {
695
- line: this.location.start.line,
696
- column: this.location.start.column,
697
- endLine: this.location.end.line,
698
- endColumn: this.location.end.column,
699
- message: this.message,
700
- severity: 'error'
701
- }
702
- ];
703
- // no-op for error_message
704
- // no-op for diagnostic_id
705
- // no-op for level
706
- return diagnostics;
593
+ toMonacoDiagnostic() {
594
+ return {
595
+ line: this.location.start.line,
596
+ column: this.location.start.column,
597
+ endLine: this.location.end.line,
598
+ endColumn: this.location.end.column,
599
+ message: this.message,
600
+ severity: 'error'
601
+ };
707
602
  }
708
603
  treeInspect() {
709
604
  let output = "";
@@ -732,7 +627,7 @@
732
627
  }
733
628
 
734
629
  var name = "@herb-tools/core";
735
- var version = "0.3.1";
630
+ var version = "0.4.1";
736
631
  var packageJSON = {
737
632
  name: name,
738
633
  version: version};
@@ -788,6 +683,9 @@
788
683
  get length() {
789
684
  return this.list.length;
790
685
  }
686
+ get tokens() {
687
+ return this.list;
688
+ }
791
689
  [Symbol.iterator]() {
792
690
  return this.list[Symbol.iterator]();
793
691
  }
@@ -881,7 +779,7 @@
881
779
  }
882
780
 
883
781
  // NOTE: This file is generated by the templates/template.rb script and should not
884
- // be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/nodes.ts.erb
782
+ // be modified manually. See /Users/marcoroth/Development/herb-release-4/templates/javascript/packages/core/src/nodes.ts.erb
885
783
  class Node {
886
784
  type;
887
785
  location;
@@ -2874,6 +2772,28 @@
2874
2772
  throw new Error(`Unknown node type: ${node.type}`);
2875
2773
  }
2876
2774
  }
2775
+ const ERBNodeClasses = [
2776
+ ERBContentNode,
2777
+ ERBEndNode,
2778
+ ERBElseNode,
2779
+ ERBIfNode,
2780
+ ERBBlockNode,
2781
+ ERBWhenNode,
2782
+ ERBCaseNode,
2783
+ ERBCaseMatchNode,
2784
+ ERBWhileNode,
2785
+ ERBUntilNode,
2786
+ ERBForNode,
2787
+ ERBRescueNode,
2788
+ ERBEnsureNode,
2789
+ ERBBeginNode,
2790
+ ERBUnlessNode,
2791
+ ERBYieldNode,
2792
+ ERBInNode,
2793
+ ];
2794
+ function isERBNode(node) {
2795
+ return node.constructor.name.startsWith("ERB");
2796
+ }
2877
2797
 
2878
2798
  /**
2879
2799
  * Represents the result of a parsing operation, extending the base `Result` class.
@@ -2906,15 +2826,15 @@
2906
2826
  * @returns `true` if there are errors, otherwise `false`.
2907
2827
  */
2908
2828
  get failed() {
2909
- // TODO: this should probably be recursive as noted in the Ruby version
2910
- return this.errors.length > 0 || this.value.errors.length > 0;
2829
+ // Consider errors on this result and recursively in the document tree
2830
+ return this.recursiveErrors().length > 0;
2911
2831
  }
2912
2832
  /**
2913
2833
  * Determines if the parsing was successful.
2914
2834
  * @returns `true` if there are no errors, otherwise `false`.
2915
2835
  */
2916
2836
  get successful() {
2917
- return this.errors.length === 0;
2837
+ return !this.failed;
2918
2838
  }
2919
2839
  /**
2920
2840
  * Returns a pretty-printed JSON string of the errors.
@@ -3060,7 +2980,7 @@
3060
2980
  }
3061
2981
 
3062
2982
  // NOTE: This file is generated by the templates/template.rb script and should not
3063
- // be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/visitor.ts.erb
2983
+ // be modified manually. See /Users/marcoroth/Development/herb-release-4/templates/javascript/packages/core/src/visitor.ts.erb
3064
2984
  class Visitor {
3065
2985
  visit(node) {
3066
2986
  if (!node)
@@ -3177,6 +3097,7 @@
3177
3097
  exports.ERBForNode = ERBForNode;
3178
3098
  exports.ERBIfNode = ERBIfNode;
3179
3099
  exports.ERBInNode = ERBInNode;
3100
+ exports.ERBNodeClasses = ERBNodeClasses;
3180
3101
  exports.ERBRescueNode = ERBRescueNode;
3181
3102
  exports.ERBUnlessNode = ERBUnlessNode;
3182
3103
  exports.ERBUntilNode = ERBUntilNode;
@@ -3223,7 +3144,9 @@
3223
3144
  exports.ensureString = ensureString;
3224
3145
  exports.fromSerializedError = fromSerializedError;
3225
3146
  exports.fromSerializedNode = fromSerializedNode;
3147
+ exports.isERBNode = isERBNode;
3226
3148
  exports.isLibHerbBackend = isLibHerbBackend;
3149
+ exports.toMonacoDiagnostic = toMonacoDiagnostic;
3227
3150
 
3228
3151
  }));
3229
3152
  //# sourceMappingURL=herb-core.umd.js.map