@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.
@@ -131,7 +131,7 @@ class Token {
131
131
  }
132
132
 
133
133
  // NOTE: This file is generated by the templates/template.rb script and should not
134
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/javascript/packages/core/src/errors.ts.erb
134
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.0/templates/javascript/packages/core/src/errors.ts.erb
135
135
  class HerbError {
136
136
  type;
137
137
  message;
@@ -588,7 +588,7 @@ function convertToUTF8(string) {
588
588
  }
589
589
 
590
590
  // NOTE: This file is generated by the templates/template.rb script and should not
591
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/javascript/packages/core/src/nodes.ts.erb
591
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.0/templates/javascript/packages/core/src/nodes.ts.erb
592
592
  class Node {
593
593
  type;
594
594
  location;
@@ -596,6 +596,9 @@ class Node {
596
596
  static from(node) {
597
597
  return fromSerializedNode(node);
598
598
  }
599
+ static get type() {
600
+ throw new Error("AST_NODE");
601
+ }
599
602
  constructor(type, location, errors) {
600
603
  this.type = type;
601
604
  this.location = location;
@@ -611,6 +614,12 @@ class Node {
611
614
  inspect() {
612
615
  return this.treeInspect(0);
613
616
  }
617
+ is(nodeClass) {
618
+ return this.type === nodeClass.type;
619
+ }
620
+ isOfType(type) {
621
+ return this.type === type;
622
+ }
614
623
  get isSingleLine() {
615
624
  return this.location.start.line === this.location.end.line;
616
625
  }
@@ -619,7 +628,7 @@ class Node {
619
628
  return "∅\n";
620
629
  if (array.length === 0)
621
630
  return "[]\n";
622
- let output = `(${array.length} item${array.length == 1 ? "" : "s"})\n`;
631
+ let output = `(${array.length} item${array.length === 1 ? "" : "s"})\n`;
623
632
  array.forEach((item, index) => {
624
633
  const isLast = index === array.length - 1;
625
634
  if (item instanceof Node || item instanceof HerbError) {
@@ -643,7 +652,7 @@ class Node {
643
652
  .treeInspect()
644
653
  .trimStart()
645
654
  .split("\n")
646
- .map((line, index) => index == 0 ? line.trimStart() : `${prefix}${prefix2}${line}`)
655
+ .map((line, index) => index === 0 ? line.trimStart() : `${prefix}${prefix2}${line}`)
647
656
  .join("\n")
648
657
  .trimStart();
649
658
  output += `\n`;
@@ -652,6 +661,9 @@ class Node {
652
661
  }
653
662
  class DocumentNode extends Node {
654
663
  children;
664
+ static get type() {
665
+ return "AST_DOCUMENT_NODE";
666
+ }
655
667
  static from(data) {
656
668
  return new DocumentNode({
657
669
  type: data.type,
@@ -698,6 +710,9 @@ class DocumentNode extends Node {
698
710
  }
699
711
  class LiteralNode extends Node {
700
712
  content;
713
+ static get type() {
714
+ return "AST_LITERAL_NODE";
715
+ }
701
716
  static from(data) {
702
717
  return new LiteralNode({
703
718
  type: data.type,
@@ -745,6 +760,9 @@ class HTMLOpenTagNode extends Node {
745
760
  tag_closing;
746
761
  children;
747
762
  is_void;
763
+ static get type() {
764
+ return "AST_HTML_OPEN_TAG_NODE";
765
+ }
748
766
  static from(data) {
749
767
  return new HTMLOpenTagNode({
750
768
  type: data.type,
@@ -810,6 +828,9 @@ class HTMLCloseTagNode extends Node {
810
828
  tag_name;
811
829
  children;
812
830
  tag_closing;
831
+ static get type() {
832
+ return "AST_HTML_CLOSE_TAG_NODE";
833
+ }
813
834
  static from(data) {
814
835
  return new HTMLCloseTagNode({
815
836
  type: data.type,
@@ -872,6 +893,10 @@ class HTMLElementNode extends Node {
872
893
  body;
873
894
  close_tag;
874
895
  is_void;
896
+ source;
897
+ static get type() {
898
+ return "AST_HTML_ELEMENT_NODE";
899
+ }
875
900
  static from(data) {
876
901
  return new HTMLElementNode({
877
902
  type: data.type,
@@ -882,6 +907,7 @@ class HTMLElementNode extends Node {
882
907
  body: (data.body || []).map(node => fromSerializedNode(node)),
883
908
  close_tag: data.close_tag ? fromSerializedNode((data.close_tag)) : null,
884
909
  is_void: data.is_void,
910
+ source: data.source,
885
911
  });
886
912
  }
887
913
  constructor(props) {
@@ -891,6 +917,7 @@ class HTMLElementNode extends Node {
891
917
  this.body = props.body;
892
918
  this.close_tag = props.close_tag;
893
919
  this.is_void = props.is_void;
920
+ this.source = props.source;
894
921
  }
895
922
  accept(visitor) {
896
923
  visitor.visitHTMLElementNode(this);
@@ -922,6 +949,7 @@ class HTMLElementNode extends Node {
922
949
  body: this.body.map(node => node.toJSON()),
923
950
  close_tag: this.close_tag ? this.close_tag.toJSON() : null,
924
951
  is_void: this.is_void,
952
+ source: this.source,
925
953
  };
926
954
  }
927
955
  treeInspect() {
@@ -932,7 +960,8 @@ class HTMLElementNode extends Node {
932
960
  output += `├── tag_name: ${this.tag_name ? this.tag_name.treeInspect() : "∅"}\n`;
933
961
  output += `├── body: ${this.inspectArray(this.body, "│ ")}`;
934
962
  output += `├── close_tag: ${this.inspectNode(this.close_tag, "│ ")}`;
935
- output += `└── is_void: ${typeof this.is_void === 'boolean' ? String(this.is_void) : "∅"}\n`;
963
+ output += `├── is_void: ${typeof this.is_void === 'boolean' ? String(this.is_void) : "∅"}\n`;
964
+ output += `└── source: ${this.source ? JSON.stringify(this.source) : "∅"}\n`;
936
965
  return output;
937
966
  }
938
967
  }
@@ -941,6 +970,9 @@ class HTMLAttributeValueNode extends Node {
941
970
  children;
942
971
  close_quote;
943
972
  quoted;
973
+ static get type() {
974
+ return "AST_HTML_ATTRIBUTE_VALUE_NODE";
975
+ }
944
976
  static from(data) {
945
977
  return new HTMLAttributeValueNode({
946
978
  type: data.type,
@@ -999,6 +1031,9 @@ class HTMLAttributeValueNode extends Node {
999
1031
  }
1000
1032
  class HTMLAttributeNameNode extends Node {
1001
1033
  children;
1034
+ static get type() {
1035
+ return "AST_HTML_ATTRIBUTE_NAME_NODE";
1036
+ }
1002
1037
  static from(data) {
1003
1038
  return new HTMLAttributeNameNode({
1004
1039
  type: data.type,
@@ -1047,6 +1082,9 @@ class HTMLAttributeNode extends Node {
1047
1082
  name;
1048
1083
  equals;
1049
1084
  value;
1085
+ static get type() {
1086
+ return "AST_HTML_ATTRIBUTE_NODE";
1087
+ }
1050
1088
  static from(data) {
1051
1089
  return new HTMLAttributeNode({
1052
1090
  type: data.type,
@@ -1103,6 +1141,9 @@ class HTMLAttributeNode extends Node {
1103
1141
  }
1104
1142
  class HTMLTextNode extends Node {
1105
1143
  content;
1144
+ static get type() {
1145
+ return "AST_HTML_TEXT_NODE";
1146
+ }
1106
1147
  static from(data) {
1107
1148
  return new HTMLTextNode({
1108
1149
  type: data.type,
@@ -1148,6 +1189,9 @@ class HTMLCommentNode extends Node {
1148
1189
  comment_start;
1149
1190
  children;
1150
1191
  comment_end;
1192
+ static get type() {
1193
+ return "AST_HTML_COMMENT_NODE";
1194
+ }
1151
1195
  static from(data) {
1152
1196
  return new HTMLCommentNode({
1153
1197
  type: data.type,
@@ -1204,6 +1248,9 @@ class HTMLDoctypeNode extends Node {
1204
1248
  tag_opening;
1205
1249
  children;
1206
1250
  tag_closing;
1251
+ static get type() {
1252
+ return "AST_HTML_DOCTYPE_NODE";
1253
+ }
1207
1254
  static from(data) {
1208
1255
  return new HTMLDoctypeNode({
1209
1256
  type: data.type,
@@ -1260,6 +1307,9 @@ class XMLDeclarationNode extends Node {
1260
1307
  tag_opening;
1261
1308
  children;
1262
1309
  tag_closing;
1310
+ static get type() {
1311
+ return "AST_XML_DECLARATION_NODE";
1312
+ }
1263
1313
  static from(data) {
1264
1314
  return new XMLDeclarationNode({
1265
1315
  type: data.type,
@@ -1316,6 +1366,9 @@ class CDATANode extends Node {
1316
1366
  tag_opening;
1317
1367
  children;
1318
1368
  tag_closing;
1369
+ static get type() {
1370
+ return "AST_CDATA_NODE";
1371
+ }
1319
1372
  static from(data) {
1320
1373
  return new CDATANode({
1321
1374
  type: data.type,
@@ -1370,6 +1423,9 @@ class CDATANode extends Node {
1370
1423
  }
1371
1424
  class WhitespaceNode extends Node {
1372
1425
  value;
1426
+ static get type() {
1427
+ return "AST_WHITESPACE_NODE";
1428
+ }
1373
1429
  static from(data) {
1374
1430
  return new WhitespaceNode({
1375
1431
  type: data.type,
@@ -1418,6 +1474,9 @@ class ERBContentNode extends Node {
1418
1474
  // no-op for analyzed_ruby
1419
1475
  parsed;
1420
1476
  valid;
1477
+ static get type() {
1478
+ return "AST_ERB_CONTENT_NODE";
1479
+ }
1421
1480
  static from(data) {
1422
1481
  return new ERBContentNode({
1423
1482
  type: data.type,
@@ -1483,6 +1542,9 @@ class ERBEndNode extends Node {
1483
1542
  tag_opening;
1484
1543
  content;
1485
1544
  tag_closing;
1545
+ static get type() {
1546
+ return "AST_ERB_END_NODE";
1547
+ }
1486
1548
  static from(data) {
1487
1549
  return new ERBEndNode({
1488
1550
  type: data.type,
@@ -1537,6 +1599,9 @@ class ERBElseNode extends Node {
1537
1599
  content;
1538
1600
  tag_closing;
1539
1601
  statements;
1602
+ static get type() {
1603
+ return "AST_ERB_ELSE_NODE";
1604
+ }
1540
1605
  static from(data) {
1541
1606
  return new ERBElseNode({
1542
1607
  type: data.type,
@@ -1600,6 +1665,9 @@ class ERBIfNode extends Node {
1600
1665
  statements;
1601
1666
  subsequent;
1602
1667
  end_node;
1668
+ static get type() {
1669
+ return "AST_ERB_IF_NODE";
1670
+ }
1603
1671
  static from(data) {
1604
1672
  return new ERBIfNode({
1605
1673
  type: data.type,
@@ -1674,6 +1742,9 @@ class ERBBlockNode extends Node {
1674
1742
  tag_closing;
1675
1743
  body;
1676
1744
  end_node;
1745
+ static get type() {
1746
+ return "AST_ERB_BLOCK_NODE";
1747
+ }
1677
1748
  static from(data) {
1678
1749
  return new ERBBlockNode({
1679
1750
  type: data.type,
@@ -1741,6 +1812,9 @@ class ERBWhenNode extends Node {
1741
1812
  content;
1742
1813
  tag_closing;
1743
1814
  statements;
1815
+ static get type() {
1816
+ return "AST_ERB_WHEN_NODE";
1817
+ }
1744
1818
  static from(data) {
1745
1819
  return new ERBWhenNode({
1746
1820
  type: data.type,
@@ -1805,6 +1879,9 @@ class ERBCaseNode extends Node {
1805
1879
  conditions;
1806
1880
  else_clause;
1807
1881
  end_node;
1882
+ static get type() {
1883
+ return "AST_ERB_CASE_NODE";
1884
+ }
1808
1885
  static from(data) {
1809
1886
  return new ERBCaseNode({
1810
1887
  type: data.type,
@@ -1887,6 +1964,9 @@ class ERBCaseMatchNode extends Node {
1887
1964
  conditions;
1888
1965
  else_clause;
1889
1966
  end_node;
1967
+ static get type() {
1968
+ return "AST_ERB_CASE_MATCH_NODE";
1969
+ }
1890
1970
  static from(data) {
1891
1971
  return new ERBCaseMatchNode({
1892
1972
  type: data.type,
@@ -1967,6 +2047,9 @@ class ERBWhileNode extends Node {
1967
2047
  tag_closing;
1968
2048
  statements;
1969
2049
  end_node;
2050
+ static get type() {
2051
+ return "AST_ERB_WHILE_NODE";
2052
+ }
1970
2053
  static from(data) {
1971
2054
  return new ERBWhileNode({
1972
2055
  type: data.type,
@@ -2035,6 +2118,9 @@ class ERBUntilNode extends Node {
2035
2118
  tag_closing;
2036
2119
  statements;
2037
2120
  end_node;
2121
+ static get type() {
2122
+ return "AST_ERB_UNTIL_NODE";
2123
+ }
2038
2124
  static from(data) {
2039
2125
  return new ERBUntilNode({
2040
2126
  type: data.type,
@@ -2103,6 +2189,9 @@ class ERBForNode extends Node {
2103
2189
  tag_closing;
2104
2190
  statements;
2105
2191
  end_node;
2192
+ static get type() {
2193
+ return "AST_ERB_FOR_NODE";
2194
+ }
2106
2195
  static from(data) {
2107
2196
  return new ERBForNode({
2108
2197
  type: data.type,
@@ -2171,6 +2260,9 @@ class ERBRescueNode extends Node {
2171
2260
  tag_closing;
2172
2261
  statements;
2173
2262
  subsequent;
2263
+ static get type() {
2264
+ return "AST_ERB_RESCUE_NODE";
2265
+ }
2174
2266
  static from(data) {
2175
2267
  return new ERBRescueNode({
2176
2268
  type: data.type,
@@ -2238,6 +2330,9 @@ class ERBEnsureNode extends Node {
2238
2330
  content;
2239
2331
  tag_closing;
2240
2332
  statements;
2333
+ static get type() {
2334
+ return "AST_ERB_ENSURE_NODE";
2335
+ }
2241
2336
  static from(data) {
2242
2337
  return new ERBEnsureNode({
2243
2338
  type: data.type,
@@ -2303,6 +2398,9 @@ class ERBBeginNode extends Node {
2303
2398
  else_clause;
2304
2399
  ensure_clause;
2305
2400
  end_node;
2401
+ static get type() {
2402
+ return "AST_ERB_BEGIN_NODE";
2403
+ }
2306
2404
  static from(data) {
2307
2405
  return new ERBBeginNode({
2308
2406
  type: data.type,
@@ -2390,6 +2488,9 @@ class ERBUnlessNode extends Node {
2390
2488
  statements;
2391
2489
  else_clause;
2392
2490
  end_node;
2491
+ static get type() {
2492
+ return "AST_ERB_UNLESS_NODE";
2493
+ }
2393
2494
  static from(data) {
2394
2495
  return new ERBUnlessNode({
2395
2496
  type: data.type,
@@ -2462,6 +2563,9 @@ class ERBYieldNode extends Node {
2462
2563
  tag_opening;
2463
2564
  content;
2464
2565
  tag_closing;
2566
+ static get type() {
2567
+ return "AST_ERB_YIELD_NODE";
2568
+ }
2465
2569
  static from(data) {
2466
2570
  return new ERBYieldNode({
2467
2571
  type: data.type,
@@ -2516,6 +2620,9 @@ class ERBInNode extends Node {
2516
2620
  content;
2517
2621
  tag_closing;
2518
2622
  statements;
2623
+ static get type() {
2624
+ return "AST_ERB_IN_NODE";
2625
+ }
2519
2626
  static from(data) {
2520
2627
  return new ERBInNode({
2521
2628
  type: data.type,
@@ -2734,7 +2841,7 @@ class ParseResult extends Result {
2734
2841
  }
2735
2842
 
2736
2843
  // NOTE: This file is generated by the templates/template.rb script and should not
2737
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/javascript/packages/core/src/node-type-guards.ts.erb
2844
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.0/templates/javascript/packages/core/src/node-type-guards.ts.erb
2738
2845
  /**
2739
2846
  * Type guard functions for AST nodes.
2740
2847
  * These functions provide type checking by combining both instanceof
@@ -2745,187 +2852,187 @@ class ParseResult extends Result {
2745
2852
  * Checks if a node is a DocumentNode
2746
2853
  */
2747
2854
  function isDocumentNode(node) {
2748
- return node instanceof DocumentNode || node.type === "AST_DOCUMENT_NODE";
2855
+ return node instanceof DocumentNode || node.type === "AST_DOCUMENT_NODE" || node.constructor.type === "AST_DOCUMENT_NODE";
2749
2856
  }
2750
2857
  /**
2751
2858
  * Checks if a node is a LiteralNode
2752
2859
  */
2753
2860
  function isLiteralNode(node) {
2754
- return node instanceof LiteralNode || node.type === "AST_LITERAL_NODE";
2861
+ return node instanceof LiteralNode || node.type === "AST_LITERAL_NODE" || node.constructor.type === "AST_LITERAL_NODE";
2755
2862
  }
2756
2863
  /**
2757
2864
  * Checks if a node is a HTMLOpenTagNode
2758
2865
  */
2759
2866
  function isHTMLOpenTagNode(node) {
2760
- return node instanceof HTMLOpenTagNode || node.type === "AST_HTML_OPEN_TAG_NODE";
2867
+ return node instanceof HTMLOpenTagNode || node.type === "AST_HTML_OPEN_TAG_NODE" || node.constructor.type === "AST_HTML_OPEN_TAG_NODE";
2761
2868
  }
2762
2869
  /**
2763
2870
  * Checks if a node is a HTMLCloseTagNode
2764
2871
  */
2765
2872
  function isHTMLCloseTagNode(node) {
2766
- return node instanceof HTMLCloseTagNode || node.type === "AST_HTML_CLOSE_TAG_NODE";
2873
+ return node instanceof HTMLCloseTagNode || node.type === "AST_HTML_CLOSE_TAG_NODE" || node.constructor.type === "AST_HTML_CLOSE_TAG_NODE";
2767
2874
  }
2768
2875
  /**
2769
2876
  * Checks if a node is a HTMLElementNode
2770
2877
  */
2771
2878
  function isHTMLElementNode(node) {
2772
- return node instanceof HTMLElementNode || node.type === "AST_HTML_ELEMENT_NODE";
2879
+ return node instanceof HTMLElementNode || node.type === "AST_HTML_ELEMENT_NODE" || node.constructor.type === "AST_HTML_ELEMENT_NODE";
2773
2880
  }
2774
2881
  /**
2775
2882
  * Checks if a node is a HTMLAttributeValueNode
2776
2883
  */
2777
2884
  function isHTMLAttributeValueNode(node) {
2778
- return node instanceof HTMLAttributeValueNode || node.type === "AST_HTML_ATTRIBUTE_VALUE_NODE";
2885
+ return node instanceof HTMLAttributeValueNode || node.type === "AST_HTML_ATTRIBUTE_VALUE_NODE" || node.constructor.type === "AST_HTML_ATTRIBUTE_VALUE_NODE";
2779
2886
  }
2780
2887
  /**
2781
2888
  * Checks if a node is a HTMLAttributeNameNode
2782
2889
  */
2783
2890
  function isHTMLAttributeNameNode(node) {
2784
- return node instanceof HTMLAttributeNameNode || node.type === "AST_HTML_ATTRIBUTE_NAME_NODE";
2891
+ return node instanceof HTMLAttributeNameNode || node.type === "AST_HTML_ATTRIBUTE_NAME_NODE" || node.constructor.type === "AST_HTML_ATTRIBUTE_NAME_NODE";
2785
2892
  }
2786
2893
  /**
2787
2894
  * Checks if a node is a HTMLAttributeNode
2788
2895
  */
2789
2896
  function isHTMLAttributeNode(node) {
2790
- return node instanceof HTMLAttributeNode || node.type === "AST_HTML_ATTRIBUTE_NODE";
2897
+ return node instanceof HTMLAttributeNode || node.type === "AST_HTML_ATTRIBUTE_NODE" || node.constructor.type === "AST_HTML_ATTRIBUTE_NODE";
2791
2898
  }
2792
2899
  /**
2793
2900
  * Checks if a node is a HTMLTextNode
2794
2901
  */
2795
2902
  function isHTMLTextNode(node) {
2796
- return node instanceof HTMLTextNode || node.type === "AST_HTML_TEXT_NODE";
2903
+ return node instanceof HTMLTextNode || node.type === "AST_HTML_TEXT_NODE" || node.constructor.type === "AST_HTML_TEXT_NODE";
2797
2904
  }
2798
2905
  /**
2799
2906
  * Checks if a node is a HTMLCommentNode
2800
2907
  */
2801
2908
  function isHTMLCommentNode(node) {
2802
- return node instanceof HTMLCommentNode || node.type === "AST_HTML_COMMENT_NODE";
2909
+ return node instanceof HTMLCommentNode || node.type === "AST_HTML_COMMENT_NODE" || node.constructor.type === "AST_HTML_COMMENT_NODE";
2803
2910
  }
2804
2911
  /**
2805
2912
  * Checks if a node is a HTMLDoctypeNode
2806
2913
  */
2807
2914
  function isHTMLDoctypeNode(node) {
2808
- return node instanceof HTMLDoctypeNode || node.type === "AST_HTML_DOCTYPE_NODE";
2915
+ return node instanceof HTMLDoctypeNode || node.type === "AST_HTML_DOCTYPE_NODE" || node.constructor.type === "AST_HTML_DOCTYPE_NODE";
2809
2916
  }
2810
2917
  /**
2811
2918
  * Checks if a node is a XMLDeclarationNode
2812
2919
  */
2813
2920
  function isXMLDeclarationNode(node) {
2814
- return node instanceof XMLDeclarationNode || node.type === "AST_XML_DECLARATION_NODE";
2921
+ return node instanceof XMLDeclarationNode || node.type === "AST_XML_DECLARATION_NODE" || node.constructor.type === "AST_XML_DECLARATION_NODE";
2815
2922
  }
2816
2923
  /**
2817
2924
  * Checks if a node is a CDATANode
2818
2925
  */
2819
2926
  function isCDATANode(node) {
2820
- return node instanceof CDATANode || node.type === "AST_CDATA_NODE";
2927
+ return node instanceof CDATANode || node.type === "AST_CDATA_NODE" || node.constructor.type === "AST_CDATA_NODE";
2821
2928
  }
2822
2929
  /**
2823
2930
  * Checks if a node is a WhitespaceNode
2824
2931
  */
2825
2932
  function isWhitespaceNode(node) {
2826
- return node instanceof WhitespaceNode || node.type === "AST_WHITESPACE_NODE";
2933
+ return node instanceof WhitespaceNode || node.type === "AST_WHITESPACE_NODE" || node.constructor.type === "AST_WHITESPACE_NODE";
2827
2934
  }
2828
2935
  /**
2829
2936
  * Checks if a node is a ERBContentNode
2830
2937
  */
2831
2938
  function isERBContentNode(node) {
2832
- return node instanceof ERBContentNode || node.type === "AST_ERB_CONTENT_NODE";
2939
+ return node instanceof ERBContentNode || node.type === "AST_ERB_CONTENT_NODE" || node.constructor.type === "AST_ERB_CONTENT_NODE";
2833
2940
  }
2834
2941
  /**
2835
2942
  * Checks if a node is a ERBEndNode
2836
2943
  */
2837
2944
  function isERBEndNode(node) {
2838
- return node instanceof ERBEndNode || node.type === "AST_ERB_END_NODE";
2945
+ return node instanceof ERBEndNode || node.type === "AST_ERB_END_NODE" || node.constructor.type === "AST_ERB_END_NODE";
2839
2946
  }
2840
2947
  /**
2841
2948
  * Checks if a node is a ERBElseNode
2842
2949
  */
2843
2950
  function isERBElseNode(node) {
2844
- return node instanceof ERBElseNode || node.type === "AST_ERB_ELSE_NODE";
2951
+ return node instanceof ERBElseNode || node.type === "AST_ERB_ELSE_NODE" || node.constructor.type === "AST_ERB_ELSE_NODE";
2845
2952
  }
2846
2953
  /**
2847
2954
  * Checks if a node is a ERBIfNode
2848
2955
  */
2849
2956
  function isERBIfNode(node) {
2850
- return node instanceof ERBIfNode || node.type === "AST_ERB_IF_NODE";
2957
+ return node instanceof ERBIfNode || node.type === "AST_ERB_IF_NODE" || node.constructor.type === "AST_ERB_IF_NODE";
2851
2958
  }
2852
2959
  /**
2853
2960
  * Checks if a node is a ERBBlockNode
2854
2961
  */
2855
2962
  function isERBBlockNode(node) {
2856
- return node instanceof ERBBlockNode || node.type === "AST_ERB_BLOCK_NODE";
2963
+ return node instanceof ERBBlockNode || node.type === "AST_ERB_BLOCK_NODE" || node.constructor.type === "AST_ERB_BLOCK_NODE";
2857
2964
  }
2858
2965
  /**
2859
2966
  * Checks if a node is a ERBWhenNode
2860
2967
  */
2861
2968
  function isERBWhenNode(node) {
2862
- return node instanceof ERBWhenNode || node.type === "AST_ERB_WHEN_NODE";
2969
+ return node instanceof ERBWhenNode || node.type === "AST_ERB_WHEN_NODE" || node.constructor.type === "AST_ERB_WHEN_NODE";
2863
2970
  }
2864
2971
  /**
2865
2972
  * Checks if a node is a ERBCaseNode
2866
2973
  */
2867
2974
  function isERBCaseNode(node) {
2868
- return node instanceof ERBCaseNode || node.type === "AST_ERB_CASE_NODE";
2975
+ return node instanceof ERBCaseNode || node.type === "AST_ERB_CASE_NODE" || node.constructor.type === "AST_ERB_CASE_NODE";
2869
2976
  }
2870
2977
  /**
2871
2978
  * Checks if a node is a ERBCaseMatchNode
2872
2979
  */
2873
2980
  function isERBCaseMatchNode(node) {
2874
- return node instanceof ERBCaseMatchNode || node.type === "AST_ERB_CASE_MATCH_NODE";
2981
+ return node instanceof ERBCaseMatchNode || node.type === "AST_ERB_CASE_MATCH_NODE" || node.constructor.type === "AST_ERB_CASE_MATCH_NODE";
2875
2982
  }
2876
2983
  /**
2877
2984
  * Checks if a node is a ERBWhileNode
2878
2985
  */
2879
2986
  function isERBWhileNode(node) {
2880
- return node instanceof ERBWhileNode || node.type === "AST_ERB_WHILE_NODE";
2987
+ return node instanceof ERBWhileNode || node.type === "AST_ERB_WHILE_NODE" || node.constructor.type === "AST_ERB_WHILE_NODE";
2881
2988
  }
2882
2989
  /**
2883
2990
  * Checks if a node is a ERBUntilNode
2884
2991
  */
2885
2992
  function isERBUntilNode(node) {
2886
- return node instanceof ERBUntilNode || node.type === "AST_ERB_UNTIL_NODE";
2993
+ return node instanceof ERBUntilNode || node.type === "AST_ERB_UNTIL_NODE" || node.constructor.type === "AST_ERB_UNTIL_NODE";
2887
2994
  }
2888
2995
  /**
2889
2996
  * Checks if a node is a ERBForNode
2890
2997
  */
2891
2998
  function isERBForNode(node) {
2892
- return node instanceof ERBForNode || node.type === "AST_ERB_FOR_NODE";
2999
+ return node instanceof ERBForNode || node.type === "AST_ERB_FOR_NODE" || node.constructor.type === "AST_ERB_FOR_NODE";
2893
3000
  }
2894
3001
  /**
2895
3002
  * Checks if a node is a ERBRescueNode
2896
3003
  */
2897
3004
  function isERBRescueNode(node) {
2898
- return node instanceof ERBRescueNode || node.type === "AST_ERB_RESCUE_NODE";
3005
+ return node instanceof ERBRescueNode || node.type === "AST_ERB_RESCUE_NODE" || node.constructor.type === "AST_ERB_RESCUE_NODE";
2899
3006
  }
2900
3007
  /**
2901
3008
  * Checks if a node is a ERBEnsureNode
2902
3009
  */
2903
3010
  function isERBEnsureNode(node) {
2904
- return node instanceof ERBEnsureNode || node.type === "AST_ERB_ENSURE_NODE";
3011
+ return node instanceof ERBEnsureNode || node.type === "AST_ERB_ENSURE_NODE" || node.constructor.type === "AST_ERB_ENSURE_NODE";
2905
3012
  }
2906
3013
  /**
2907
3014
  * Checks if a node is a ERBBeginNode
2908
3015
  */
2909
3016
  function isERBBeginNode(node) {
2910
- return node instanceof ERBBeginNode || node.type === "AST_ERB_BEGIN_NODE";
3017
+ return node instanceof ERBBeginNode || node.type === "AST_ERB_BEGIN_NODE" || node.constructor.type === "AST_ERB_BEGIN_NODE";
2911
3018
  }
2912
3019
  /**
2913
3020
  * Checks if a node is a ERBUnlessNode
2914
3021
  */
2915
3022
  function isERBUnlessNode(node) {
2916
- return node instanceof ERBUnlessNode || node.type === "AST_ERB_UNLESS_NODE";
3023
+ return node instanceof ERBUnlessNode || node.type === "AST_ERB_UNLESS_NODE" || node.constructor.type === "AST_ERB_UNLESS_NODE";
2917
3024
  }
2918
3025
  /**
2919
3026
  * Checks if a node is a ERBYieldNode
2920
3027
  */
2921
3028
  function isERBYieldNode(node) {
2922
- return node instanceof ERBYieldNode || node.type === "AST_ERB_YIELD_NODE";
3029
+ return node instanceof ERBYieldNode || node.type === "AST_ERB_YIELD_NODE" || node.constructor.type === "AST_ERB_YIELD_NODE";
2923
3030
  }
2924
3031
  /**
2925
3032
  * Checks if a node is a ERBInNode
2926
3033
  */
2927
3034
  function isERBInNode(node) {
2928
- return node instanceof ERBInNode || node.type === "AST_ERB_IN_NODE";
3035
+ return node instanceof ERBInNode || node.type === "AST_ERB_IN_NODE" || node.constructor.type === "AST_ERB_IN_NODE";
2929
3036
  }
2930
3037
  /**
2931
3038
  * Convenience type guards for common node categories
@@ -3114,6 +3221,8 @@ function filterNodes(nodes, ...types) {
3114
3221
  return nodes.filter(node => isAnyOf(node, ...types));
3115
3222
  }
3116
3223
  function isNode(node, type) {
3224
+ if (!node)
3225
+ return false;
3117
3226
  if (typeof type === 'string') {
3118
3227
  const guard = AST_TYPE_GUARDS.get(type);
3119
3228
  return guard ? guard(node) : false;
@@ -3353,7 +3462,11 @@ function filterERBInNodes(nodes) {
3353
3462
  * Checks if a node is an ERB output node (generates content: <%= %> or <%== %>)
3354
3463
  */
3355
3464
  function isERBOutputNode(node) {
3356
- return isNode(node, ERBContentNode) && ["<%=", "<%=="].includes(node.tag_opening?.value);
3465
+ if (!isNode(node, ERBContentNode))
3466
+ return false;
3467
+ if (!node.tag_opening?.value)
3468
+ return false;
3469
+ return ["<%=", "<%=="].includes(node.tag_opening?.value);
3357
3470
  }
3358
3471
  /**
3359
3472
  * Checks if a node is a non-output ERB node (control flow: <% %>)
@@ -3489,6 +3602,87 @@ function getTagName(node) {
3489
3602
  function isCommentNode(node) {
3490
3603
  return isNode(node, HTMLCommentNode) || (isERBNode(node) && !isERBControlFlowNode(node));
3491
3604
  }
3605
+ /**
3606
+ * Compares two positions to determine if the first comes before the second
3607
+ * Returns true if pos1 comes before pos2 in source order
3608
+ * @param inclusive - If true, returns true when positions are equal
3609
+ */
3610
+ function isPositionBefore(position1, position2, inclusive = false) {
3611
+ if (position1.line < position2.line)
3612
+ return true;
3613
+ if (position1.line > position2.line)
3614
+ return false;
3615
+ return inclusive ? position1.column <= position2.column : position1.column < position2.column;
3616
+ }
3617
+ /**
3618
+ * Compares two positions to determine if they are equal
3619
+ * Returns true if pos1 and pos2 are at the same location
3620
+ */
3621
+ function isPositionEqual(position1, position2) {
3622
+ return position1.line === position2.line && position1.column === position2.column;
3623
+ }
3624
+ /**
3625
+ * Compares two positions to determine if the first comes after the second
3626
+ * Returns true if pos1 comes after pos2 in source order
3627
+ * @param inclusive - If true, returns true when positions are equal
3628
+ */
3629
+ function isPositionAfter(position1, position2, inclusive = false) {
3630
+ if (position1.line > position2.line)
3631
+ return true;
3632
+ if (position1.line < position2.line)
3633
+ return false;
3634
+ return inclusive ? position1.column >= position2.column : position1.column > position2.column;
3635
+ }
3636
+ /**
3637
+ * Gets nodes that appear before the specified location in source order
3638
+ * Uses line and column positions to determine ordering
3639
+ */
3640
+ function getNodesBeforeLocation(nodes, location) {
3641
+ return nodes.filter(node => node.location && isPositionBefore(node.location.end, location.start));
3642
+ }
3643
+ /**
3644
+ * Gets nodes that appear after the specified location in source order
3645
+ * Uses line and column positions to determine ordering
3646
+ */
3647
+ function getNodesAfterLocation(nodes, location) {
3648
+ return nodes.filter(node => node.location && isPositionAfter(node.location.start, location.end));
3649
+ }
3650
+ /**
3651
+ * Splits nodes into before and after the specified location
3652
+ * Returns an object with `before` and `after` arrays
3653
+ */
3654
+ function splitNodesAroundLocation(nodes, location) {
3655
+ return {
3656
+ before: getNodesBeforeLocation(nodes, location),
3657
+ after: getNodesAfterLocation(nodes, location)
3658
+ };
3659
+ }
3660
+ /**
3661
+ * Splits nodes at a specific position
3662
+ * Returns nodes that end before the position and nodes that start after the position
3663
+ * More precise than splitNodesAroundLocation as it uses a single position point
3664
+ * Uses the same defaults as the individual functions: before=exclusive, after=inclusive
3665
+ */
3666
+ function splitNodesAroundPosition(nodes, position) {
3667
+ return {
3668
+ before: getNodesBeforePosition(nodes, position), // uses default: inclusive = false
3669
+ after: getNodesAfterPosition(nodes, position) // uses default: inclusive = true
3670
+ };
3671
+ }
3672
+ /**
3673
+ * Gets nodes that end before the specified position
3674
+ * @param inclusive - If true, includes nodes that end exactly at the position (default: false, matching half-open interval semantics)
3675
+ */
3676
+ function getNodesBeforePosition(nodes, position, inclusive = false) {
3677
+ return nodes.filter(node => node.location && isPositionBefore(node.location.end, position, inclusive));
3678
+ }
3679
+ /**
3680
+ * Gets nodes that start after the specified position
3681
+ * @param inclusive - If true, includes nodes that start exactly at the position (default: true, matching typical boundary behavior)
3682
+ */
3683
+ function getNodesAfterPosition(nodes, position, inclusive = true) {
3684
+ return nodes.filter(node => node.location && isPositionAfter(node.location.start, position, inclusive));
3685
+ }
3492
3686
 
3493
3687
  const expectedFunctions = [
3494
3688
  "parse",
@@ -3541,7 +3735,7 @@ function toMonacoDiagnostic(diagnostic) {
3541
3735
  }
3542
3736
 
3543
3737
  var name = "@herb-tools/core";
3544
- var version = "0.6.0";
3738
+ var version = "0.7.0";
3545
3739
  var packageJSON = {
3546
3740
  name: name,
3547
3741
  version: version};
@@ -3764,7 +3958,7 @@ class HerbBackend {
3764
3958
  }
3765
3959
 
3766
3960
  // NOTE: This file is generated by the templates/template.rb script and should not
3767
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/javascript/packages/core/src/visitor.ts.erb
3961
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.0/templates/javascript/packages/core/src/visitor.ts.erb
3768
3962
  class Visitor {
3769
3963
  visit(node) {
3770
3964
  if (!node)
@@ -3970,6 +4164,10 @@ exports.fromSerializedError = fromSerializedError;
3970
4164
  exports.fromSerializedNode = fromSerializedNode;
3971
4165
  exports.getCombinedAttributeName = getCombinedAttributeName;
3972
4166
  exports.getCombinedStringFromNodes = getCombinedStringFromNodes;
4167
+ exports.getNodesAfterLocation = getNodesAfterLocation;
4168
+ exports.getNodesAfterPosition = getNodesAfterPosition;
4169
+ exports.getNodesBeforeLocation = getNodesBeforeLocation;
4170
+ exports.getNodesBeforePosition = getNodesBeforePosition;
3973
4171
  exports.getStaticAttributeName = getStaticAttributeName;
3974
4172
  exports.getStaticContentFromNodes = getStaticContentFromNodes;
3975
4173
  exports.getStaticStringFromNodes = getStaticStringFromNodes;
@@ -4021,8 +4219,12 @@ exports.isLiteralNode = isLiteralNode;
4021
4219
  exports.isNode = isNode;
4022
4220
  exports.isNoneOf = isNoneOf;
4023
4221
  exports.isParseResult = isParseResult;
4222
+ exports.isPositionAfter = isPositionAfter;
4223
+ exports.isPositionEqual = isPositionEqual;
4024
4224
  exports.isToken = isToken;
4025
4225
  exports.isWhitespaceNode = isWhitespaceNode;
4026
4226
  exports.isXMLDeclarationNode = isXMLDeclarationNode;
4227
+ exports.splitNodesAroundLocation = splitNodesAroundLocation;
4228
+ exports.splitNodesAroundPosition = splitNodesAroundPosition;
4027
4229
  exports.toMonacoDiagnostic = toMonacoDiagnostic;
4028
4230
  //# sourceMappingURL=herb-core.cjs.map