@herb-tools/core 0.6.0 → 0.7.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.
@@ -135,7 +135,7 @@
135
135
  }
136
136
 
137
137
  // NOTE: This file is generated by the templates/template.rb script and should not
138
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/javascript/packages/core/src/errors.ts.erb
138
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.0/templates/javascript/packages/core/src/errors.ts.erb
139
139
  class HerbError {
140
140
  type;
141
141
  message;
@@ -592,7 +592,7 @@
592
592
  }
593
593
 
594
594
  // NOTE: This file is generated by the templates/template.rb script and should not
595
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/javascript/packages/core/src/nodes.ts.erb
595
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.0/templates/javascript/packages/core/src/nodes.ts.erb
596
596
  class Node {
597
597
  type;
598
598
  location;
@@ -600,6 +600,9 @@
600
600
  static from(node) {
601
601
  return fromSerializedNode(node);
602
602
  }
603
+ static get type() {
604
+ throw new Error("AST_NODE");
605
+ }
603
606
  constructor(type, location, errors) {
604
607
  this.type = type;
605
608
  this.location = location;
@@ -615,6 +618,12 @@
615
618
  inspect() {
616
619
  return this.treeInspect(0);
617
620
  }
621
+ is(nodeClass) {
622
+ return this.type === nodeClass.type;
623
+ }
624
+ isOfType(type) {
625
+ return this.type === type;
626
+ }
618
627
  get isSingleLine() {
619
628
  return this.location.start.line === this.location.end.line;
620
629
  }
@@ -623,7 +632,7 @@
623
632
  return "∅\n";
624
633
  if (array.length === 0)
625
634
  return "[]\n";
626
- let output = `(${array.length} item${array.length == 1 ? "" : "s"})\n`;
635
+ let output = `(${array.length} item${array.length === 1 ? "" : "s"})\n`;
627
636
  array.forEach((item, index) => {
628
637
  const isLast = index === array.length - 1;
629
638
  if (item instanceof Node || item instanceof HerbError) {
@@ -647,7 +656,7 @@
647
656
  .treeInspect()
648
657
  .trimStart()
649
658
  .split("\n")
650
- .map((line, index) => index == 0 ? line.trimStart() : `${prefix}${prefix2}${line}`)
659
+ .map((line, index) => index === 0 ? line.trimStart() : `${prefix}${prefix2}${line}`)
651
660
  .join("\n")
652
661
  .trimStart();
653
662
  output += `\n`;
@@ -656,6 +665,9 @@
656
665
  }
657
666
  class DocumentNode extends Node {
658
667
  children;
668
+ static get type() {
669
+ return "AST_DOCUMENT_NODE";
670
+ }
659
671
  static from(data) {
660
672
  return new DocumentNode({
661
673
  type: data.type,
@@ -702,6 +714,9 @@
702
714
  }
703
715
  class LiteralNode extends Node {
704
716
  content;
717
+ static get type() {
718
+ return "AST_LITERAL_NODE";
719
+ }
705
720
  static from(data) {
706
721
  return new LiteralNode({
707
722
  type: data.type,
@@ -749,6 +764,9 @@
749
764
  tag_closing;
750
765
  children;
751
766
  is_void;
767
+ static get type() {
768
+ return "AST_HTML_OPEN_TAG_NODE";
769
+ }
752
770
  static from(data) {
753
771
  return new HTMLOpenTagNode({
754
772
  type: data.type,
@@ -814,6 +832,9 @@
814
832
  tag_name;
815
833
  children;
816
834
  tag_closing;
835
+ static get type() {
836
+ return "AST_HTML_CLOSE_TAG_NODE";
837
+ }
817
838
  static from(data) {
818
839
  return new HTMLCloseTagNode({
819
840
  type: data.type,
@@ -876,6 +897,10 @@
876
897
  body;
877
898
  close_tag;
878
899
  is_void;
900
+ source;
901
+ static get type() {
902
+ return "AST_HTML_ELEMENT_NODE";
903
+ }
879
904
  static from(data) {
880
905
  return new HTMLElementNode({
881
906
  type: data.type,
@@ -886,6 +911,7 @@
886
911
  body: (data.body || []).map(node => fromSerializedNode(node)),
887
912
  close_tag: data.close_tag ? fromSerializedNode((data.close_tag)) : null,
888
913
  is_void: data.is_void,
914
+ source: data.source,
889
915
  });
890
916
  }
891
917
  constructor(props) {
@@ -895,6 +921,7 @@
895
921
  this.body = props.body;
896
922
  this.close_tag = props.close_tag;
897
923
  this.is_void = props.is_void;
924
+ this.source = props.source;
898
925
  }
899
926
  accept(visitor) {
900
927
  visitor.visitHTMLElementNode(this);
@@ -926,6 +953,7 @@
926
953
  body: this.body.map(node => node.toJSON()),
927
954
  close_tag: this.close_tag ? this.close_tag.toJSON() : null,
928
955
  is_void: this.is_void,
956
+ source: this.source,
929
957
  };
930
958
  }
931
959
  treeInspect() {
@@ -936,7 +964,8 @@
936
964
  output += `├── tag_name: ${this.tag_name ? this.tag_name.treeInspect() : "∅"}\n`;
937
965
  output += `├── body: ${this.inspectArray(this.body, "│ ")}`;
938
966
  output += `├── close_tag: ${this.inspectNode(this.close_tag, "│ ")}`;
939
- output += `└── is_void: ${typeof this.is_void === 'boolean' ? String(this.is_void) : "∅"}\n`;
967
+ output += `├── is_void: ${typeof this.is_void === 'boolean' ? String(this.is_void) : "∅"}\n`;
968
+ output += `└── source: ${this.source ? JSON.stringify(this.source) : "∅"}\n`;
940
969
  return output;
941
970
  }
942
971
  }
@@ -945,6 +974,9 @@
945
974
  children;
946
975
  close_quote;
947
976
  quoted;
977
+ static get type() {
978
+ return "AST_HTML_ATTRIBUTE_VALUE_NODE";
979
+ }
948
980
  static from(data) {
949
981
  return new HTMLAttributeValueNode({
950
982
  type: data.type,
@@ -1003,6 +1035,9 @@
1003
1035
  }
1004
1036
  class HTMLAttributeNameNode extends Node {
1005
1037
  children;
1038
+ static get type() {
1039
+ return "AST_HTML_ATTRIBUTE_NAME_NODE";
1040
+ }
1006
1041
  static from(data) {
1007
1042
  return new HTMLAttributeNameNode({
1008
1043
  type: data.type,
@@ -1051,6 +1086,9 @@
1051
1086
  name;
1052
1087
  equals;
1053
1088
  value;
1089
+ static get type() {
1090
+ return "AST_HTML_ATTRIBUTE_NODE";
1091
+ }
1054
1092
  static from(data) {
1055
1093
  return new HTMLAttributeNode({
1056
1094
  type: data.type,
@@ -1107,6 +1145,9 @@
1107
1145
  }
1108
1146
  class HTMLTextNode extends Node {
1109
1147
  content;
1148
+ static get type() {
1149
+ return "AST_HTML_TEXT_NODE";
1150
+ }
1110
1151
  static from(data) {
1111
1152
  return new HTMLTextNode({
1112
1153
  type: data.type,
@@ -1152,6 +1193,9 @@
1152
1193
  comment_start;
1153
1194
  children;
1154
1195
  comment_end;
1196
+ static get type() {
1197
+ return "AST_HTML_COMMENT_NODE";
1198
+ }
1155
1199
  static from(data) {
1156
1200
  return new HTMLCommentNode({
1157
1201
  type: data.type,
@@ -1208,6 +1252,9 @@
1208
1252
  tag_opening;
1209
1253
  children;
1210
1254
  tag_closing;
1255
+ static get type() {
1256
+ return "AST_HTML_DOCTYPE_NODE";
1257
+ }
1211
1258
  static from(data) {
1212
1259
  return new HTMLDoctypeNode({
1213
1260
  type: data.type,
@@ -1264,6 +1311,9 @@
1264
1311
  tag_opening;
1265
1312
  children;
1266
1313
  tag_closing;
1314
+ static get type() {
1315
+ return "AST_XML_DECLARATION_NODE";
1316
+ }
1267
1317
  static from(data) {
1268
1318
  return new XMLDeclarationNode({
1269
1319
  type: data.type,
@@ -1320,6 +1370,9 @@
1320
1370
  tag_opening;
1321
1371
  children;
1322
1372
  tag_closing;
1373
+ static get type() {
1374
+ return "AST_CDATA_NODE";
1375
+ }
1323
1376
  static from(data) {
1324
1377
  return new CDATANode({
1325
1378
  type: data.type,
@@ -1374,6 +1427,9 @@
1374
1427
  }
1375
1428
  class WhitespaceNode extends Node {
1376
1429
  value;
1430
+ static get type() {
1431
+ return "AST_WHITESPACE_NODE";
1432
+ }
1377
1433
  static from(data) {
1378
1434
  return new WhitespaceNode({
1379
1435
  type: data.type,
@@ -1422,6 +1478,9 @@
1422
1478
  // no-op for analyzed_ruby
1423
1479
  parsed;
1424
1480
  valid;
1481
+ static get type() {
1482
+ return "AST_ERB_CONTENT_NODE";
1483
+ }
1425
1484
  static from(data) {
1426
1485
  return new ERBContentNode({
1427
1486
  type: data.type,
@@ -1487,6 +1546,9 @@
1487
1546
  tag_opening;
1488
1547
  content;
1489
1548
  tag_closing;
1549
+ static get type() {
1550
+ return "AST_ERB_END_NODE";
1551
+ }
1490
1552
  static from(data) {
1491
1553
  return new ERBEndNode({
1492
1554
  type: data.type,
@@ -1541,6 +1603,9 @@
1541
1603
  content;
1542
1604
  tag_closing;
1543
1605
  statements;
1606
+ static get type() {
1607
+ return "AST_ERB_ELSE_NODE";
1608
+ }
1544
1609
  static from(data) {
1545
1610
  return new ERBElseNode({
1546
1611
  type: data.type,
@@ -1604,6 +1669,9 @@
1604
1669
  statements;
1605
1670
  subsequent;
1606
1671
  end_node;
1672
+ static get type() {
1673
+ return "AST_ERB_IF_NODE";
1674
+ }
1607
1675
  static from(data) {
1608
1676
  return new ERBIfNode({
1609
1677
  type: data.type,
@@ -1678,6 +1746,9 @@
1678
1746
  tag_closing;
1679
1747
  body;
1680
1748
  end_node;
1749
+ static get type() {
1750
+ return "AST_ERB_BLOCK_NODE";
1751
+ }
1681
1752
  static from(data) {
1682
1753
  return new ERBBlockNode({
1683
1754
  type: data.type,
@@ -1745,6 +1816,9 @@
1745
1816
  content;
1746
1817
  tag_closing;
1747
1818
  statements;
1819
+ static get type() {
1820
+ return "AST_ERB_WHEN_NODE";
1821
+ }
1748
1822
  static from(data) {
1749
1823
  return new ERBWhenNode({
1750
1824
  type: data.type,
@@ -1809,6 +1883,9 @@
1809
1883
  conditions;
1810
1884
  else_clause;
1811
1885
  end_node;
1886
+ static get type() {
1887
+ return "AST_ERB_CASE_NODE";
1888
+ }
1812
1889
  static from(data) {
1813
1890
  return new ERBCaseNode({
1814
1891
  type: data.type,
@@ -1891,6 +1968,9 @@
1891
1968
  conditions;
1892
1969
  else_clause;
1893
1970
  end_node;
1971
+ static get type() {
1972
+ return "AST_ERB_CASE_MATCH_NODE";
1973
+ }
1894
1974
  static from(data) {
1895
1975
  return new ERBCaseMatchNode({
1896
1976
  type: data.type,
@@ -1971,6 +2051,9 @@
1971
2051
  tag_closing;
1972
2052
  statements;
1973
2053
  end_node;
2054
+ static get type() {
2055
+ return "AST_ERB_WHILE_NODE";
2056
+ }
1974
2057
  static from(data) {
1975
2058
  return new ERBWhileNode({
1976
2059
  type: data.type,
@@ -2039,6 +2122,9 @@
2039
2122
  tag_closing;
2040
2123
  statements;
2041
2124
  end_node;
2125
+ static get type() {
2126
+ return "AST_ERB_UNTIL_NODE";
2127
+ }
2042
2128
  static from(data) {
2043
2129
  return new ERBUntilNode({
2044
2130
  type: data.type,
@@ -2107,6 +2193,9 @@
2107
2193
  tag_closing;
2108
2194
  statements;
2109
2195
  end_node;
2196
+ static get type() {
2197
+ return "AST_ERB_FOR_NODE";
2198
+ }
2110
2199
  static from(data) {
2111
2200
  return new ERBForNode({
2112
2201
  type: data.type,
@@ -2175,6 +2264,9 @@
2175
2264
  tag_closing;
2176
2265
  statements;
2177
2266
  subsequent;
2267
+ static get type() {
2268
+ return "AST_ERB_RESCUE_NODE";
2269
+ }
2178
2270
  static from(data) {
2179
2271
  return new ERBRescueNode({
2180
2272
  type: data.type,
@@ -2242,6 +2334,9 @@
2242
2334
  content;
2243
2335
  tag_closing;
2244
2336
  statements;
2337
+ static get type() {
2338
+ return "AST_ERB_ENSURE_NODE";
2339
+ }
2245
2340
  static from(data) {
2246
2341
  return new ERBEnsureNode({
2247
2342
  type: data.type,
@@ -2307,6 +2402,9 @@
2307
2402
  else_clause;
2308
2403
  ensure_clause;
2309
2404
  end_node;
2405
+ static get type() {
2406
+ return "AST_ERB_BEGIN_NODE";
2407
+ }
2310
2408
  static from(data) {
2311
2409
  return new ERBBeginNode({
2312
2410
  type: data.type,
@@ -2394,6 +2492,9 @@
2394
2492
  statements;
2395
2493
  else_clause;
2396
2494
  end_node;
2495
+ static get type() {
2496
+ return "AST_ERB_UNLESS_NODE";
2497
+ }
2397
2498
  static from(data) {
2398
2499
  return new ERBUnlessNode({
2399
2500
  type: data.type,
@@ -2466,6 +2567,9 @@
2466
2567
  tag_opening;
2467
2568
  content;
2468
2569
  tag_closing;
2570
+ static get type() {
2571
+ return "AST_ERB_YIELD_NODE";
2572
+ }
2469
2573
  static from(data) {
2470
2574
  return new ERBYieldNode({
2471
2575
  type: data.type,
@@ -2520,6 +2624,9 @@
2520
2624
  content;
2521
2625
  tag_closing;
2522
2626
  statements;
2627
+ static get type() {
2628
+ return "AST_ERB_IN_NODE";
2629
+ }
2523
2630
  static from(data) {
2524
2631
  return new ERBInNode({
2525
2632
  type: data.type,
@@ -2738,7 +2845,7 @@
2738
2845
  }
2739
2846
 
2740
2847
  // NOTE: This file is generated by the templates/template.rb script and should not
2741
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/javascript/packages/core/src/node-type-guards.ts.erb
2848
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.0/templates/javascript/packages/core/src/node-type-guards.ts.erb
2742
2849
  /**
2743
2850
  * Type guard functions for AST nodes.
2744
2851
  * These functions provide type checking by combining both instanceof
@@ -2749,187 +2856,187 @@
2749
2856
  * Checks if a node is a DocumentNode
2750
2857
  */
2751
2858
  function isDocumentNode(node) {
2752
- return node instanceof DocumentNode || node.type === "AST_DOCUMENT_NODE";
2859
+ return node instanceof DocumentNode || node.type === "AST_DOCUMENT_NODE" || node.constructor.type === "AST_DOCUMENT_NODE";
2753
2860
  }
2754
2861
  /**
2755
2862
  * Checks if a node is a LiteralNode
2756
2863
  */
2757
2864
  function isLiteralNode(node) {
2758
- return node instanceof LiteralNode || node.type === "AST_LITERAL_NODE";
2865
+ return node instanceof LiteralNode || node.type === "AST_LITERAL_NODE" || node.constructor.type === "AST_LITERAL_NODE";
2759
2866
  }
2760
2867
  /**
2761
2868
  * Checks if a node is a HTMLOpenTagNode
2762
2869
  */
2763
2870
  function isHTMLOpenTagNode(node) {
2764
- return node instanceof HTMLOpenTagNode || node.type === "AST_HTML_OPEN_TAG_NODE";
2871
+ return node instanceof HTMLOpenTagNode || node.type === "AST_HTML_OPEN_TAG_NODE" || node.constructor.type === "AST_HTML_OPEN_TAG_NODE";
2765
2872
  }
2766
2873
  /**
2767
2874
  * Checks if a node is a HTMLCloseTagNode
2768
2875
  */
2769
2876
  function isHTMLCloseTagNode(node) {
2770
- return node instanceof HTMLCloseTagNode || node.type === "AST_HTML_CLOSE_TAG_NODE";
2877
+ return node instanceof HTMLCloseTagNode || node.type === "AST_HTML_CLOSE_TAG_NODE" || node.constructor.type === "AST_HTML_CLOSE_TAG_NODE";
2771
2878
  }
2772
2879
  /**
2773
2880
  * Checks if a node is a HTMLElementNode
2774
2881
  */
2775
2882
  function isHTMLElementNode(node) {
2776
- return node instanceof HTMLElementNode || node.type === "AST_HTML_ELEMENT_NODE";
2883
+ return node instanceof HTMLElementNode || node.type === "AST_HTML_ELEMENT_NODE" || node.constructor.type === "AST_HTML_ELEMENT_NODE";
2777
2884
  }
2778
2885
  /**
2779
2886
  * Checks if a node is a HTMLAttributeValueNode
2780
2887
  */
2781
2888
  function isHTMLAttributeValueNode(node) {
2782
- return node instanceof HTMLAttributeValueNode || node.type === "AST_HTML_ATTRIBUTE_VALUE_NODE";
2889
+ return node instanceof HTMLAttributeValueNode || node.type === "AST_HTML_ATTRIBUTE_VALUE_NODE" || node.constructor.type === "AST_HTML_ATTRIBUTE_VALUE_NODE";
2783
2890
  }
2784
2891
  /**
2785
2892
  * Checks if a node is a HTMLAttributeNameNode
2786
2893
  */
2787
2894
  function isHTMLAttributeNameNode(node) {
2788
- return node instanceof HTMLAttributeNameNode || node.type === "AST_HTML_ATTRIBUTE_NAME_NODE";
2895
+ return node instanceof HTMLAttributeNameNode || node.type === "AST_HTML_ATTRIBUTE_NAME_NODE" || node.constructor.type === "AST_HTML_ATTRIBUTE_NAME_NODE";
2789
2896
  }
2790
2897
  /**
2791
2898
  * Checks if a node is a HTMLAttributeNode
2792
2899
  */
2793
2900
  function isHTMLAttributeNode(node) {
2794
- return node instanceof HTMLAttributeNode || node.type === "AST_HTML_ATTRIBUTE_NODE";
2901
+ return node instanceof HTMLAttributeNode || node.type === "AST_HTML_ATTRIBUTE_NODE" || node.constructor.type === "AST_HTML_ATTRIBUTE_NODE";
2795
2902
  }
2796
2903
  /**
2797
2904
  * Checks if a node is a HTMLTextNode
2798
2905
  */
2799
2906
  function isHTMLTextNode(node) {
2800
- return node instanceof HTMLTextNode || node.type === "AST_HTML_TEXT_NODE";
2907
+ return node instanceof HTMLTextNode || node.type === "AST_HTML_TEXT_NODE" || node.constructor.type === "AST_HTML_TEXT_NODE";
2801
2908
  }
2802
2909
  /**
2803
2910
  * Checks if a node is a HTMLCommentNode
2804
2911
  */
2805
2912
  function isHTMLCommentNode(node) {
2806
- return node instanceof HTMLCommentNode || node.type === "AST_HTML_COMMENT_NODE";
2913
+ return node instanceof HTMLCommentNode || node.type === "AST_HTML_COMMENT_NODE" || node.constructor.type === "AST_HTML_COMMENT_NODE";
2807
2914
  }
2808
2915
  /**
2809
2916
  * Checks if a node is a HTMLDoctypeNode
2810
2917
  */
2811
2918
  function isHTMLDoctypeNode(node) {
2812
- return node instanceof HTMLDoctypeNode || node.type === "AST_HTML_DOCTYPE_NODE";
2919
+ return node instanceof HTMLDoctypeNode || node.type === "AST_HTML_DOCTYPE_NODE" || node.constructor.type === "AST_HTML_DOCTYPE_NODE";
2813
2920
  }
2814
2921
  /**
2815
2922
  * Checks if a node is a XMLDeclarationNode
2816
2923
  */
2817
2924
  function isXMLDeclarationNode(node) {
2818
- return node instanceof XMLDeclarationNode || node.type === "AST_XML_DECLARATION_NODE";
2925
+ return node instanceof XMLDeclarationNode || node.type === "AST_XML_DECLARATION_NODE" || node.constructor.type === "AST_XML_DECLARATION_NODE";
2819
2926
  }
2820
2927
  /**
2821
2928
  * Checks if a node is a CDATANode
2822
2929
  */
2823
2930
  function isCDATANode(node) {
2824
- return node instanceof CDATANode || node.type === "AST_CDATA_NODE";
2931
+ return node instanceof CDATANode || node.type === "AST_CDATA_NODE" || node.constructor.type === "AST_CDATA_NODE";
2825
2932
  }
2826
2933
  /**
2827
2934
  * Checks if a node is a WhitespaceNode
2828
2935
  */
2829
2936
  function isWhitespaceNode(node) {
2830
- return node instanceof WhitespaceNode || node.type === "AST_WHITESPACE_NODE";
2937
+ return node instanceof WhitespaceNode || node.type === "AST_WHITESPACE_NODE" || node.constructor.type === "AST_WHITESPACE_NODE";
2831
2938
  }
2832
2939
  /**
2833
2940
  * Checks if a node is a ERBContentNode
2834
2941
  */
2835
2942
  function isERBContentNode(node) {
2836
- return node instanceof ERBContentNode || node.type === "AST_ERB_CONTENT_NODE";
2943
+ return node instanceof ERBContentNode || node.type === "AST_ERB_CONTENT_NODE" || node.constructor.type === "AST_ERB_CONTENT_NODE";
2837
2944
  }
2838
2945
  /**
2839
2946
  * Checks if a node is a ERBEndNode
2840
2947
  */
2841
2948
  function isERBEndNode(node) {
2842
- return node instanceof ERBEndNode || node.type === "AST_ERB_END_NODE";
2949
+ return node instanceof ERBEndNode || node.type === "AST_ERB_END_NODE" || node.constructor.type === "AST_ERB_END_NODE";
2843
2950
  }
2844
2951
  /**
2845
2952
  * Checks if a node is a ERBElseNode
2846
2953
  */
2847
2954
  function isERBElseNode(node) {
2848
- return node instanceof ERBElseNode || node.type === "AST_ERB_ELSE_NODE";
2955
+ return node instanceof ERBElseNode || node.type === "AST_ERB_ELSE_NODE" || node.constructor.type === "AST_ERB_ELSE_NODE";
2849
2956
  }
2850
2957
  /**
2851
2958
  * Checks if a node is a ERBIfNode
2852
2959
  */
2853
2960
  function isERBIfNode(node) {
2854
- return node instanceof ERBIfNode || node.type === "AST_ERB_IF_NODE";
2961
+ return node instanceof ERBIfNode || node.type === "AST_ERB_IF_NODE" || node.constructor.type === "AST_ERB_IF_NODE";
2855
2962
  }
2856
2963
  /**
2857
2964
  * Checks if a node is a ERBBlockNode
2858
2965
  */
2859
2966
  function isERBBlockNode(node) {
2860
- return node instanceof ERBBlockNode || node.type === "AST_ERB_BLOCK_NODE";
2967
+ return node instanceof ERBBlockNode || node.type === "AST_ERB_BLOCK_NODE" || node.constructor.type === "AST_ERB_BLOCK_NODE";
2861
2968
  }
2862
2969
  /**
2863
2970
  * Checks if a node is a ERBWhenNode
2864
2971
  */
2865
2972
  function isERBWhenNode(node) {
2866
- return node instanceof ERBWhenNode || node.type === "AST_ERB_WHEN_NODE";
2973
+ return node instanceof ERBWhenNode || node.type === "AST_ERB_WHEN_NODE" || node.constructor.type === "AST_ERB_WHEN_NODE";
2867
2974
  }
2868
2975
  /**
2869
2976
  * Checks if a node is a ERBCaseNode
2870
2977
  */
2871
2978
  function isERBCaseNode(node) {
2872
- return node instanceof ERBCaseNode || node.type === "AST_ERB_CASE_NODE";
2979
+ return node instanceof ERBCaseNode || node.type === "AST_ERB_CASE_NODE" || node.constructor.type === "AST_ERB_CASE_NODE";
2873
2980
  }
2874
2981
  /**
2875
2982
  * Checks if a node is a ERBCaseMatchNode
2876
2983
  */
2877
2984
  function isERBCaseMatchNode(node) {
2878
- return node instanceof ERBCaseMatchNode || node.type === "AST_ERB_CASE_MATCH_NODE";
2985
+ return node instanceof ERBCaseMatchNode || node.type === "AST_ERB_CASE_MATCH_NODE" || node.constructor.type === "AST_ERB_CASE_MATCH_NODE";
2879
2986
  }
2880
2987
  /**
2881
2988
  * Checks if a node is a ERBWhileNode
2882
2989
  */
2883
2990
  function isERBWhileNode(node) {
2884
- return node instanceof ERBWhileNode || node.type === "AST_ERB_WHILE_NODE";
2991
+ return node instanceof ERBWhileNode || node.type === "AST_ERB_WHILE_NODE" || node.constructor.type === "AST_ERB_WHILE_NODE";
2885
2992
  }
2886
2993
  /**
2887
2994
  * Checks if a node is a ERBUntilNode
2888
2995
  */
2889
2996
  function isERBUntilNode(node) {
2890
- return node instanceof ERBUntilNode || node.type === "AST_ERB_UNTIL_NODE";
2997
+ return node instanceof ERBUntilNode || node.type === "AST_ERB_UNTIL_NODE" || node.constructor.type === "AST_ERB_UNTIL_NODE";
2891
2998
  }
2892
2999
  /**
2893
3000
  * Checks if a node is a ERBForNode
2894
3001
  */
2895
3002
  function isERBForNode(node) {
2896
- return node instanceof ERBForNode || node.type === "AST_ERB_FOR_NODE";
3003
+ return node instanceof ERBForNode || node.type === "AST_ERB_FOR_NODE" || node.constructor.type === "AST_ERB_FOR_NODE";
2897
3004
  }
2898
3005
  /**
2899
3006
  * Checks if a node is a ERBRescueNode
2900
3007
  */
2901
3008
  function isERBRescueNode(node) {
2902
- return node instanceof ERBRescueNode || node.type === "AST_ERB_RESCUE_NODE";
3009
+ return node instanceof ERBRescueNode || node.type === "AST_ERB_RESCUE_NODE" || node.constructor.type === "AST_ERB_RESCUE_NODE";
2903
3010
  }
2904
3011
  /**
2905
3012
  * Checks if a node is a ERBEnsureNode
2906
3013
  */
2907
3014
  function isERBEnsureNode(node) {
2908
- return node instanceof ERBEnsureNode || node.type === "AST_ERB_ENSURE_NODE";
3015
+ return node instanceof ERBEnsureNode || node.type === "AST_ERB_ENSURE_NODE" || node.constructor.type === "AST_ERB_ENSURE_NODE";
2909
3016
  }
2910
3017
  /**
2911
3018
  * Checks if a node is a ERBBeginNode
2912
3019
  */
2913
3020
  function isERBBeginNode(node) {
2914
- return node instanceof ERBBeginNode || node.type === "AST_ERB_BEGIN_NODE";
3021
+ return node instanceof ERBBeginNode || node.type === "AST_ERB_BEGIN_NODE" || node.constructor.type === "AST_ERB_BEGIN_NODE";
2915
3022
  }
2916
3023
  /**
2917
3024
  * Checks if a node is a ERBUnlessNode
2918
3025
  */
2919
3026
  function isERBUnlessNode(node) {
2920
- return node instanceof ERBUnlessNode || node.type === "AST_ERB_UNLESS_NODE";
3027
+ return node instanceof ERBUnlessNode || node.type === "AST_ERB_UNLESS_NODE" || node.constructor.type === "AST_ERB_UNLESS_NODE";
2921
3028
  }
2922
3029
  /**
2923
3030
  * Checks if a node is a ERBYieldNode
2924
3031
  */
2925
3032
  function isERBYieldNode(node) {
2926
- return node instanceof ERBYieldNode || node.type === "AST_ERB_YIELD_NODE";
3033
+ return node instanceof ERBYieldNode || node.type === "AST_ERB_YIELD_NODE" || node.constructor.type === "AST_ERB_YIELD_NODE";
2927
3034
  }
2928
3035
  /**
2929
3036
  * Checks if a node is a ERBInNode
2930
3037
  */
2931
3038
  function isERBInNode(node) {
2932
- return node instanceof ERBInNode || node.type === "AST_ERB_IN_NODE";
3039
+ return node instanceof ERBInNode || node.type === "AST_ERB_IN_NODE" || node.constructor.type === "AST_ERB_IN_NODE";
2933
3040
  }
2934
3041
  /**
2935
3042
  * Convenience type guards for common node categories
@@ -3118,6 +3225,8 @@
3118
3225
  return nodes.filter(node => isAnyOf(node, ...types));
3119
3226
  }
3120
3227
  function isNode(node, type) {
3228
+ if (!node)
3229
+ return false;
3121
3230
  if (typeof type === 'string') {
3122
3231
  const guard = AST_TYPE_GUARDS.get(type);
3123
3232
  return guard ? guard(node) : false;
@@ -3357,7 +3466,11 @@
3357
3466
  * Checks if a node is an ERB output node (generates content: <%= %> or <%== %>)
3358
3467
  */
3359
3468
  function isERBOutputNode(node) {
3360
- return isNode(node, ERBContentNode) && ["<%=", "<%=="].includes(node.tag_opening?.value);
3469
+ if (!isNode(node, ERBContentNode))
3470
+ return false;
3471
+ if (!node.tag_opening?.value)
3472
+ return false;
3473
+ return ["<%=", "<%=="].includes(node.tag_opening?.value);
3361
3474
  }
3362
3475
  /**
3363
3476
  * Checks if a node is a non-output ERB node (control flow: <% %>)
@@ -3493,6 +3606,87 @@
3493
3606
  function isCommentNode(node) {
3494
3607
  return isNode(node, HTMLCommentNode) || (isERBNode(node) && !isERBControlFlowNode(node));
3495
3608
  }
3609
+ /**
3610
+ * Compares two positions to determine if the first comes before the second
3611
+ * Returns true if pos1 comes before pos2 in source order
3612
+ * @param inclusive - If true, returns true when positions are equal
3613
+ */
3614
+ function isPositionBefore(position1, position2, inclusive = false) {
3615
+ if (position1.line < position2.line)
3616
+ return true;
3617
+ if (position1.line > position2.line)
3618
+ return false;
3619
+ return inclusive ? position1.column <= position2.column : position1.column < position2.column;
3620
+ }
3621
+ /**
3622
+ * Compares two positions to determine if they are equal
3623
+ * Returns true if pos1 and pos2 are at the same location
3624
+ */
3625
+ function isPositionEqual(position1, position2) {
3626
+ return position1.line === position2.line && position1.column === position2.column;
3627
+ }
3628
+ /**
3629
+ * Compares two positions to determine if the first comes after the second
3630
+ * Returns true if pos1 comes after pos2 in source order
3631
+ * @param inclusive - If true, returns true when positions are equal
3632
+ */
3633
+ function isPositionAfter(position1, position2, inclusive = false) {
3634
+ if (position1.line > position2.line)
3635
+ return true;
3636
+ if (position1.line < position2.line)
3637
+ return false;
3638
+ return inclusive ? position1.column >= position2.column : position1.column > position2.column;
3639
+ }
3640
+ /**
3641
+ * Gets nodes that appear before the specified location in source order
3642
+ * Uses line and column positions to determine ordering
3643
+ */
3644
+ function getNodesBeforeLocation(nodes, location) {
3645
+ return nodes.filter(node => node.location && isPositionBefore(node.location.end, location.start));
3646
+ }
3647
+ /**
3648
+ * Gets nodes that appear after the specified location in source order
3649
+ * Uses line and column positions to determine ordering
3650
+ */
3651
+ function getNodesAfterLocation(nodes, location) {
3652
+ return nodes.filter(node => node.location && isPositionAfter(node.location.start, location.end));
3653
+ }
3654
+ /**
3655
+ * Splits nodes into before and after the specified location
3656
+ * Returns an object with `before` and `after` arrays
3657
+ */
3658
+ function splitNodesAroundLocation(nodes, location) {
3659
+ return {
3660
+ before: getNodesBeforeLocation(nodes, location),
3661
+ after: getNodesAfterLocation(nodes, location)
3662
+ };
3663
+ }
3664
+ /**
3665
+ * Splits nodes at a specific position
3666
+ * Returns nodes that end before the position and nodes that start after the position
3667
+ * More precise than splitNodesAroundLocation as it uses a single position point
3668
+ * Uses the same defaults as the individual functions: before=exclusive, after=inclusive
3669
+ */
3670
+ function splitNodesAroundPosition(nodes, position) {
3671
+ return {
3672
+ before: getNodesBeforePosition(nodes, position), // uses default: inclusive = false
3673
+ after: getNodesAfterPosition(nodes, position) // uses default: inclusive = true
3674
+ };
3675
+ }
3676
+ /**
3677
+ * Gets nodes that end before the specified position
3678
+ * @param inclusive - If true, includes nodes that end exactly at the position (default: false, matching half-open interval semantics)
3679
+ */
3680
+ function getNodesBeforePosition(nodes, position, inclusive = false) {
3681
+ return nodes.filter(node => node.location && isPositionBefore(node.location.end, position, inclusive));
3682
+ }
3683
+ /**
3684
+ * Gets nodes that start after the specified position
3685
+ * @param inclusive - If true, includes nodes that start exactly at the position (default: true, matching typical boundary behavior)
3686
+ */
3687
+ function getNodesAfterPosition(nodes, position, inclusive = true) {
3688
+ return nodes.filter(node => node.location && isPositionAfter(node.location.start, position, inclusive));
3689
+ }
3496
3690
 
3497
3691
  const expectedFunctions = [
3498
3692
  "parse",
@@ -3545,7 +3739,7 @@
3545
3739
  }
3546
3740
 
3547
3741
  var name = "@herb-tools/core";
3548
- var version = "0.6.0";
3742
+ var version = "0.7.0";
3549
3743
  var packageJSON = {
3550
3744
  name: name,
3551
3745
  version: version};
@@ -3768,7 +3962,7 @@
3768
3962
  }
3769
3963
 
3770
3964
  // NOTE: This file is generated by the templates/template.rb script and should not
3771
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/javascript/packages/core/src/visitor.ts.erb
3965
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.0/templates/javascript/packages/core/src/visitor.ts.erb
3772
3966
  class Visitor {
3773
3967
  visit(node) {
3774
3968
  if (!node)
@@ -3974,6 +4168,10 @@
3974
4168
  exports.fromSerializedNode = fromSerializedNode;
3975
4169
  exports.getCombinedAttributeName = getCombinedAttributeName;
3976
4170
  exports.getCombinedStringFromNodes = getCombinedStringFromNodes;
4171
+ exports.getNodesAfterLocation = getNodesAfterLocation;
4172
+ exports.getNodesAfterPosition = getNodesAfterPosition;
4173
+ exports.getNodesBeforeLocation = getNodesBeforeLocation;
4174
+ exports.getNodesBeforePosition = getNodesBeforePosition;
3977
4175
  exports.getStaticAttributeName = getStaticAttributeName;
3978
4176
  exports.getStaticContentFromNodes = getStaticContentFromNodes;
3979
4177
  exports.getStaticStringFromNodes = getStaticStringFromNodes;
@@ -4025,9 +4223,13 @@
4025
4223
  exports.isNode = isNode;
4026
4224
  exports.isNoneOf = isNoneOf;
4027
4225
  exports.isParseResult = isParseResult;
4226
+ exports.isPositionAfter = isPositionAfter;
4227
+ exports.isPositionEqual = isPositionEqual;
4028
4228
  exports.isToken = isToken;
4029
4229
  exports.isWhitespaceNode = isWhitespaceNode;
4030
4230
  exports.isXMLDeclarationNode = isXMLDeclarationNode;
4231
+ exports.splitNodesAroundLocation = splitNodesAroundLocation;
4232
+ exports.splitNodesAroundPosition = splitNodesAroundPosition;
4031
4233
  exports.toMonacoDiagnostic = toMonacoDiagnostic;
4032
4234
 
4033
4235
  }));