@herb-tools/core 0.6.0 → 0.6.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.
- package/dist/herb-core.browser.js +222 -37
- package/dist/herb-core.browser.js.map +1 -1
- package/dist/herb-core.cjs +229 -36
- package/dist/herb-core.cjs.map +1 -1
- package/dist/herb-core.esm.js +222 -37
- package/dist/herb-core.esm.js.map +1 -1
- package/dist/herb-core.umd.js +229 -36
- package/dist/herb-core.umd.js.map +1 -1
- package/dist/types/ast-utils.d.ts +52 -2
- package/dist/types/node-type-guards.d.ts +3 -3
- package/dist/types/nodes.d.ts +38 -0
- package/package.json +1 -1
- package/src/ast-utils.ts +101 -1
- package/src/errors.ts +1 -1
- package/src/node-type-guards.ts +38 -36
- package/src/nodes.ts +137 -1
- package/src/visitor.ts +1 -1
package/dist/herb-core.umd.js
CHANGED
|
@@ -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.
|
|
138
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.6.1/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.
|
|
595
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.6.1/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
|
}
|
|
@@ -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,9 @@
|
|
|
876
897
|
body;
|
|
877
898
|
close_tag;
|
|
878
899
|
is_void;
|
|
900
|
+
static get type() {
|
|
901
|
+
return "AST_HTML_ELEMENT_NODE";
|
|
902
|
+
}
|
|
879
903
|
static from(data) {
|
|
880
904
|
return new HTMLElementNode({
|
|
881
905
|
type: data.type,
|
|
@@ -945,6 +969,9 @@
|
|
|
945
969
|
children;
|
|
946
970
|
close_quote;
|
|
947
971
|
quoted;
|
|
972
|
+
static get type() {
|
|
973
|
+
return "AST_HTML_ATTRIBUTE_VALUE_NODE";
|
|
974
|
+
}
|
|
948
975
|
static from(data) {
|
|
949
976
|
return new HTMLAttributeValueNode({
|
|
950
977
|
type: data.type,
|
|
@@ -1003,6 +1030,9 @@
|
|
|
1003
1030
|
}
|
|
1004
1031
|
class HTMLAttributeNameNode extends Node {
|
|
1005
1032
|
children;
|
|
1033
|
+
static get type() {
|
|
1034
|
+
return "AST_HTML_ATTRIBUTE_NAME_NODE";
|
|
1035
|
+
}
|
|
1006
1036
|
static from(data) {
|
|
1007
1037
|
return new HTMLAttributeNameNode({
|
|
1008
1038
|
type: data.type,
|
|
@@ -1051,6 +1081,9 @@
|
|
|
1051
1081
|
name;
|
|
1052
1082
|
equals;
|
|
1053
1083
|
value;
|
|
1084
|
+
static get type() {
|
|
1085
|
+
return "AST_HTML_ATTRIBUTE_NODE";
|
|
1086
|
+
}
|
|
1054
1087
|
static from(data) {
|
|
1055
1088
|
return new HTMLAttributeNode({
|
|
1056
1089
|
type: data.type,
|
|
@@ -1107,6 +1140,9 @@
|
|
|
1107
1140
|
}
|
|
1108
1141
|
class HTMLTextNode extends Node {
|
|
1109
1142
|
content;
|
|
1143
|
+
static get type() {
|
|
1144
|
+
return "AST_HTML_TEXT_NODE";
|
|
1145
|
+
}
|
|
1110
1146
|
static from(data) {
|
|
1111
1147
|
return new HTMLTextNode({
|
|
1112
1148
|
type: data.type,
|
|
@@ -1152,6 +1188,9 @@
|
|
|
1152
1188
|
comment_start;
|
|
1153
1189
|
children;
|
|
1154
1190
|
comment_end;
|
|
1191
|
+
static get type() {
|
|
1192
|
+
return "AST_HTML_COMMENT_NODE";
|
|
1193
|
+
}
|
|
1155
1194
|
static from(data) {
|
|
1156
1195
|
return new HTMLCommentNode({
|
|
1157
1196
|
type: data.type,
|
|
@@ -1208,6 +1247,9 @@
|
|
|
1208
1247
|
tag_opening;
|
|
1209
1248
|
children;
|
|
1210
1249
|
tag_closing;
|
|
1250
|
+
static get type() {
|
|
1251
|
+
return "AST_HTML_DOCTYPE_NODE";
|
|
1252
|
+
}
|
|
1211
1253
|
static from(data) {
|
|
1212
1254
|
return new HTMLDoctypeNode({
|
|
1213
1255
|
type: data.type,
|
|
@@ -1264,6 +1306,9 @@
|
|
|
1264
1306
|
tag_opening;
|
|
1265
1307
|
children;
|
|
1266
1308
|
tag_closing;
|
|
1309
|
+
static get type() {
|
|
1310
|
+
return "AST_XML_DECLARATION_NODE";
|
|
1311
|
+
}
|
|
1267
1312
|
static from(data) {
|
|
1268
1313
|
return new XMLDeclarationNode({
|
|
1269
1314
|
type: data.type,
|
|
@@ -1320,6 +1365,9 @@
|
|
|
1320
1365
|
tag_opening;
|
|
1321
1366
|
children;
|
|
1322
1367
|
tag_closing;
|
|
1368
|
+
static get type() {
|
|
1369
|
+
return "AST_CDATA_NODE";
|
|
1370
|
+
}
|
|
1323
1371
|
static from(data) {
|
|
1324
1372
|
return new CDATANode({
|
|
1325
1373
|
type: data.type,
|
|
@@ -1374,6 +1422,9 @@
|
|
|
1374
1422
|
}
|
|
1375
1423
|
class WhitespaceNode extends Node {
|
|
1376
1424
|
value;
|
|
1425
|
+
static get type() {
|
|
1426
|
+
return "AST_WHITESPACE_NODE";
|
|
1427
|
+
}
|
|
1377
1428
|
static from(data) {
|
|
1378
1429
|
return new WhitespaceNode({
|
|
1379
1430
|
type: data.type,
|
|
@@ -1422,6 +1473,9 @@
|
|
|
1422
1473
|
// no-op for analyzed_ruby
|
|
1423
1474
|
parsed;
|
|
1424
1475
|
valid;
|
|
1476
|
+
static get type() {
|
|
1477
|
+
return "AST_ERB_CONTENT_NODE";
|
|
1478
|
+
}
|
|
1425
1479
|
static from(data) {
|
|
1426
1480
|
return new ERBContentNode({
|
|
1427
1481
|
type: data.type,
|
|
@@ -1487,6 +1541,9 @@
|
|
|
1487
1541
|
tag_opening;
|
|
1488
1542
|
content;
|
|
1489
1543
|
tag_closing;
|
|
1544
|
+
static get type() {
|
|
1545
|
+
return "AST_ERB_END_NODE";
|
|
1546
|
+
}
|
|
1490
1547
|
static from(data) {
|
|
1491
1548
|
return new ERBEndNode({
|
|
1492
1549
|
type: data.type,
|
|
@@ -1541,6 +1598,9 @@
|
|
|
1541
1598
|
content;
|
|
1542
1599
|
tag_closing;
|
|
1543
1600
|
statements;
|
|
1601
|
+
static get type() {
|
|
1602
|
+
return "AST_ERB_ELSE_NODE";
|
|
1603
|
+
}
|
|
1544
1604
|
static from(data) {
|
|
1545
1605
|
return new ERBElseNode({
|
|
1546
1606
|
type: data.type,
|
|
@@ -1604,6 +1664,9 @@
|
|
|
1604
1664
|
statements;
|
|
1605
1665
|
subsequent;
|
|
1606
1666
|
end_node;
|
|
1667
|
+
static get type() {
|
|
1668
|
+
return "AST_ERB_IF_NODE";
|
|
1669
|
+
}
|
|
1607
1670
|
static from(data) {
|
|
1608
1671
|
return new ERBIfNode({
|
|
1609
1672
|
type: data.type,
|
|
@@ -1678,6 +1741,9 @@
|
|
|
1678
1741
|
tag_closing;
|
|
1679
1742
|
body;
|
|
1680
1743
|
end_node;
|
|
1744
|
+
static get type() {
|
|
1745
|
+
return "AST_ERB_BLOCK_NODE";
|
|
1746
|
+
}
|
|
1681
1747
|
static from(data) {
|
|
1682
1748
|
return new ERBBlockNode({
|
|
1683
1749
|
type: data.type,
|
|
@@ -1745,6 +1811,9 @@
|
|
|
1745
1811
|
content;
|
|
1746
1812
|
tag_closing;
|
|
1747
1813
|
statements;
|
|
1814
|
+
static get type() {
|
|
1815
|
+
return "AST_ERB_WHEN_NODE";
|
|
1816
|
+
}
|
|
1748
1817
|
static from(data) {
|
|
1749
1818
|
return new ERBWhenNode({
|
|
1750
1819
|
type: data.type,
|
|
@@ -1809,6 +1878,9 @@
|
|
|
1809
1878
|
conditions;
|
|
1810
1879
|
else_clause;
|
|
1811
1880
|
end_node;
|
|
1881
|
+
static get type() {
|
|
1882
|
+
return "AST_ERB_CASE_NODE";
|
|
1883
|
+
}
|
|
1812
1884
|
static from(data) {
|
|
1813
1885
|
return new ERBCaseNode({
|
|
1814
1886
|
type: data.type,
|
|
@@ -1891,6 +1963,9 @@
|
|
|
1891
1963
|
conditions;
|
|
1892
1964
|
else_clause;
|
|
1893
1965
|
end_node;
|
|
1966
|
+
static get type() {
|
|
1967
|
+
return "AST_ERB_CASE_MATCH_NODE";
|
|
1968
|
+
}
|
|
1894
1969
|
static from(data) {
|
|
1895
1970
|
return new ERBCaseMatchNode({
|
|
1896
1971
|
type: data.type,
|
|
@@ -1971,6 +2046,9 @@
|
|
|
1971
2046
|
tag_closing;
|
|
1972
2047
|
statements;
|
|
1973
2048
|
end_node;
|
|
2049
|
+
static get type() {
|
|
2050
|
+
return "AST_ERB_WHILE_NODE";
|
|
2051
|
+
}
|
|
1974
2052
|
static from(data) {
|
|
1975
2053
|
return new ERBWhileNode({
|
|
1976
2054
|
type: data.type,
|
|
@@ -2039,6 +2117,9 @@
|
|
|
2039
2117
|
tag_closing;
|
|
2040
2118
|
statements;
|
|
2041
2119
|
end_node;
|
|
2120
|
+
static get type() {
|
|
2121
|
+
return "AST_ERB_UNTIL_NODE";
|
|
2122
|
+
}
|
|
2042
2123
|
static from(data) {
|
|
2043
2124
|
return new ERBUntilNode({
|
|
2044
2125
|
type: data.type,
|
|
@@ -2107,6 +2188,9 @@
|
|
|
2107
2188
|
tag_closing;
|
|
2108
2189
|
statements;
|
|
2109
2190
|
end_node;
|
|
2191
|
+
static get type() {
|
|
2192
|
+
return "AST_ERB_FOR_NODE";
|
|
2193
|
+
}
|
|
2110
2194
|
static from(data) {
|
|
2111
2195
|
return new ERBForNode({
|
|
2112
2196
|
type: data.type,
|
|
@@ -2175,6 +2259,9 @@
|
|
|
2175
2259
|
tag_closing;
|
|
2176
2260
|
statements;
|
|
2177
2261
|
subsequent;
|
|
2262
|
+
static get type() {
|
|
2263
|
+
return "AST_ERB_RESCUE_NODE";
|
|
2264
|
+
}
|
|
2178
2265
|
static from(data) {
|
|
2179
2266
|
return new ERBRescueNode({
|
|
2180
2267
|
type: data.type,
|
|
@@ -2242,6 +2329,9 @@
|
|
|
2242
2329
|
content;
|
|
2243
2330
|
tag_closing;
|
|
2244
2331
|
statements;
|
|
2332
|
+
static get type() {
|
|
2333
|
+
return "AST_ERB_ENSURE_NODE";
|
|
2334
|
+
}
|
|
2245
2335
|
static from(data) {
|
|
2246
2336
|
return new ERBEnsureNode({
|
|
2247
2337
|
type: data.type,
|
|
@@ -2307,6 +2397,9 @@
|
|
|
2307
2397
|
else_clause;
|
|
2308
2398
|
ensure_clause;
|
|
2309
2399
|
end_node;
|
|
2400
|
+
static get type() {
|
|
2401
|
+
return "AST_ERB_BEGIN_NODE";
|
|
2402
|
+
}
|
|
2310
2403
|
static from(data) {
|
|
2311
2404
|
return new ERBBeginNode({
|
|
2312
2405
|
type: data.type,
|
|
@@ -2394,6 +2487,9 @@
|
|
|
2394
2487
|
statements;
|
|
2395
2488
|
else_clause;
|
|
2396
2489
|
end_node;
|
|
2490
|
+
static get type() {
|
|
2491
|
+
return "AST_ERB_UNLESS_NODE";
|
|
2492
|
+
}
|
|
2397
2493
|
static from(data) {
|
|
2398
2494
|
return new ERBUnlessNode({
|
|
2399
2495
|
type: data.type,
|
|
@@ -2466,6 +2562,9 @@
|
|
|
2466
2562
|
tag_opening;
|
|
2467
2563
|
content;
|
|
2468
2564
|
tag_closing;
|
|
2565
|
+
static get type() {
|
|
2566
|
+
return "AST_ERB_YIELD_NODE";
|
|
2567
|
+
}
|
|
2469
2568
|
static from(data) {
|
|
2470
2569
|
return new ERBYieldNode({
|
|
2471
2570
|
type: data.type,
|
|
@@ -2520,6 +2619,9 @@
|
|
|
2520
2619
|
content;
|
|
2521
2620
|
tag_closing;
|
|
2522
2621
|
statements;
|
|
2622
|
+
static get type() {
|
|
2623
|
+
return "AST_ERB_IN_NODE";
|
|
2624
|
+
}
|
|
2523
2625
|
static from(data) {
|
|
2524
2626
|
return new ERBInNode({
|
|
2525
2627
|
type: data.type,
|
|
@@ -2738,7 +2840,7 @@
|
|
|
2738
2840
|
}
|
|
2739
2841
|
|
|
2740
2842
|
// 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.
|
|
2843
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.6.1/templates/javascript/packages/core/src/node-type-guards.ts.erb
|
|
2742
2844
|
/**
|
|
2743
2845
|
* Type guard functions for AST nodes.
|
|
2744
2846
|
* These functions provide type checking by combining both instanceof
|
|
@@ -2749,187 +2851,187 @@
|
|
|
2749
2851
|
* Checks if a node is a DocumentNode
|
|
2750
2852
|
*/
|
|
2751
2853
|
function isDocumentNode(node) {
|
|
2752
|
-
return node instanceof DocumentNode || node.type === "AST_DOCUMENT_NODE";
|
|
2854
|
+
return node instanceof DocumentNode || node.type === "AST_DOCUMENT_NODE" || node.constructor.type === "AST_DOCUMENT_NODE";
|
|
2753
2855
|
}
|
|
2754
2856
|
/**
|
|
2755
2857
|
* Checks if a node is a LiteralNode
|
|
2756
2858
|
*/
|
|
2757
2859
|
function isLiteralNode(node) {
|
|
2758
|
-
return node instanceof LiteralNode || node.type === "AST_LITERAL_NODE";
|
|
2860
|
+
return node instanceof LiteralNode || node.type === "AST_LITERAL_NODE" || node.constructor.type === "AST_LITERAL_NODE";
|
|
2759
2861
|
}
|
|
2760
2862
|
/**
|
|
2761
2863
|
* Checks if a node is a HTMLOpenTagNode
|
|
2762
2864
|
*/
|
|
2763
2865
|
function isHTMLOpenTagNode(node) {
|
|
2764
|
-
return node instanceof HTMLOpenTagNode || node.type === "AST_HTML_OPEN_TAG_NODE";
|
|
2866
|
+
return node instanceof HTMLOpenTagNode || node.type === "AST_HTML_OPEN_TAG_NODE" || node.constructor.type === "AST_HTML_OPEN_TAG_NODE";
|
|
2765
2867
|
}
|
|
2766
2868
|
/**
|
|
2767
2869
|
* Checks if a node is a HTMLCloseTagNode
|
|
2768
2870
|
*/
|
|
2769
2871
|
function isHTMLCloseTagNode(node) {
|
|
2770
|
-
return node instanceof HTMLCloseTagNode || node.type === "AST_HTML_CLOSE_TAG_NODE";
|
|
2872
|
+
return node instanceof HTMLCloseTagNode || node.type === "AST_HTML_CLOSE_TAG_NODE" || node.constructor.type === "AST_HTML_CLOSE_TAG_NODE";
|
|
2771
2873
|
}
|
|
2772
2874
|
/**
|
|
2773
2875
|
* Checks if a node is a HTMLElementNode
|
|
2774
2876
|
*/
|
|
2775
2877
|
function isHTMLElementNode(node) {
|
|
2776
|
-
return node instanceof HTMLElementNode || node.type === "AST_HTML_ELEMENT_NODE";
|
|
2878
|
+
return node instanceof HTMLElementNode || node.type === "AST_HTML_ELEMENT_NODE" || node.constructor.type === "AST_HTML_ELEMENT_NODE";
|
|
2777
2879
|
}
|
|
2778
2880
|
/**
|
|
2779
2881
|
* Checks if a node is a HTMLAttributeValueNode
|
|
2780
2882
|
*/
|
|
2781
2883
|
function isHTMLAttributeValueNode(node) {
|
|
2782
|
-
return node instanceof HTMLAttributeValueNode || node.type === "AST_HTML_ATTRIBUTE_VALUE_NODE";
|
|
2884
|
+
return node instanceof HTMLAttributeValueNode || node.type === "AST_HTML_ATTRIBUTE_VALUE_NODE" || node.constructor.type === "AST_HTML_ATTRIBUTE_VALUE_NODE";
|
|
2783
2885
|
}
|
|
2784
2886
|
/**
|
|
2785
2887
|
* Checks if a node is a HTMLAttributeNameNode
|
|
2786
2888
|
*/
|
|
2787
2889
|
function isHTMLAttributeNameNode(node) {
|
|
2788
|
-
return node instanceof HTMLAttributeNameNode || node.type === "AST_HTML_ATTRIBUTE_NAME_NODE";
|
|
2890
|
+
return node instanceof HTMLAttributeNameNode || node.type === "AST_HTML_ATTRIBUTE_NAME_NODE" || node.constructor.type === "AST_HTML_ATTRIBUTE_NAME_NODE";
|
|
2789
2891
|
}
|
|
2790
2892
|
/**
|
|
2791
2893
|
* Checks if a node is a HTMLAttributeNode
|
|
2792
2894
|
*/
|
|
2793
2895
|
function isHTMLAttributeNode(node) {
|
|
2794
|
-
return node instanceof HTMLAttributeNode || node.type === "AST_HTML_ATTRIBUTE_NODE";
|
|
2896
|
+
return node instanceof HTMLAttributeNode || node.type === "AST_HTML_ATTRIBUTE_NODE" || node.constructor.type === "AST_HTML_ATTRIBUTE_NODE";
|
|
2795
2897
|
}
|
|
2796
2898
|
/**
|
|
2797
2899
|
* Checks if a node is a HTMLTextNode
|
|
2798
2900
|
*/
|
|
2799
2901
|
function isHTMLTextNode(node) {
|
|
2800
|
-
return node instanceof HTMLTextNode || node.type === "AST_HTML_TEXT_NODE";
|
|
2902
|
+
return node instanceof HTMLTextNode || node.type === "AST_HTML_TEXT_NODE" || node.constructor.type === "AST_HTML_TEXT_NODE";
|
|
2801
2903
|
}
|
|
2802
2904
|
/**
|
|
2803
2905
|
* Checks if a node is a HTMLCommentNode
|
|
2804
2906
|
*/
|
|
2805
2907
|
function isHTMLCommentNode(node) {
|
|
2806
|
-
return node instanceof HTMLCommentNode || node.type === "AST_HTML_COMMENT_NODE";
|
|
2908
|
+
return node instanceof HTMLCommentNode || node.type === "AST_HTML_COMMENT_NODE" || node.constructor.type === "AST_HTML_COMMENT_NODE";
|
|
2807
2909
|
}
|
|
2808
2910
|
/**
|
|
2809
2911
|
* Checks if a node is a HTMLDoctypeNode
|
|
2810
2912
|
*/
|
|
2811
2913
|
function isHTMLDoctypeNode(node) {
|
|
2812
|
-
return node instanceof HTMLDoctypeNode || node.type === "AST_HTML_DOCTYPE_NODE";
|
|
2914
|
+
return node instanceof HTMLDoctypeNode || node.type === "AST_HTML_DOCTYPE_NODE" || node.constructor.type === "AST_HTML_DOCTYPE_NODE";
|
|
2813
2915
|
}
|
|
2814
2916
|
/**
|
|
2815
2917
|
* Checks if a node is a XMLDeclarationNode
|
|
2816
2918
|
*/
|
|
2817
2919
|
function isXMLDeclarationNode(node) {
|
|
2818
|
-
return node instanceof XMLDeclarationNode || node.type === "AST_XML_DECLARATION_NODE";
|
|
2920
|
+
return node instanceof XMLDeclarationNode || node.type === "AST_XML_DECLARATION_NODE" || node.constructor.type === "AST_XML_DECLARATION_NODE";
|
|
2819
2921
|
}
|
|
2820
2922
|
/**
|
|
2821
2923
|
* Checks if a node is a CDATANode
|
|
2822
2924
|
*/
|
|
2823
2925
|
function isCDATANode(node) {
|
|
2824
|
-
return node instanceof CDATANode || node.type === "AST_CDATA_NODE";
|
|
2926
|
+
return node instanceof CDATANode || node.type === "AST_CDATA_NODE" || node.constructor.type === "AST_CDATA_NODE";
|
|
2825
2927
|
}
|
|
2826
2928
|
/**
|
|
2827
2929
|
* Checks if a node is a WhitespaceNode
|
|
2828
2930
|
*/
|
|
2829
2931
|
function isWhitespaceNode(node) {
|
|
2830
|
-
return node instanceof WhitespaceNode || node.type === "AST_WHITESPACE_NODE";
|
|
2932
|
+
return node instanceof WhitespaceNode || node.type === "AST_WHITESPACE_NODE" || node.constructor.type === "AST_WHITESPACE_NODE";
|
|
2831
2933
|
}
|
|
2832
2934
|
/**
|
|
2833
2935
|
* Checks if a node is a ERBContentNode
|
|
2834
2936
|
*/
|
|
2835
2937
|
function isERBContentNode(node) {
|
|
2836
|
-
return node instanceof ERBContentNode || node.type === "AST_ERB_CONTENT_NODE";
|
|
2938
|
+
return node instanceof ERBContentNode || node.type === "AST_ERB_CONTENT_NODE" || node.constructor.type === "AST_ERB_CONTENT_NODE";
|
|
2837
2939
|
}
|
|
2838
2940
|
/**
|
|
2839
2941
|
* Checks if a node is a ERBEndNode
|
|
2840
2942
|
*/
|
|
2841
2943
|
function isERBEndNode(node) {
|
|
2842
|
-
return node instanceof ERBEndNode || node.type === "AST_ERB_END_NODE";
|
|
2944
|
+
return node instanceof ERBEndNode || node.type === "AST_ERB_END_NODE" || node.constructor.type === "AST_ERB_END_NODE";
|
|
2843
2945
|
}
|
|
2844
2946
|
/**
|
|
2845
2947
|
* Checks if a node is a ERBElseNode
|
|
2846
2948
|
*/
|
|
2847
2949
|
function isERBElseNode(node) {
|
|
2848
|
-
return node instanceof ERBElseNode || node.type === "AST_ERB_ELSE_NODE";
|
|
2950
|
+
return node instanceof ERBElseNode || node.type === "AST_ERB_ELSE_NODE" || node.constructor.type === "AST_ERB_ELSE_NODE";
|
|
2849
2951
|
}
|
|
2850
2952
|
/**
|
|
2851
2953
|
* Checks if a node is a ERBIfNode
|
|
2852
2954
|
*/
|
|
2853
2955
|
function isERBIfNode(node) {
|
|
2854
|
-
return node instanceof ERBIfNode || node.type === "AST_ERB_IF_NODE";
|
|
2956
|
+
return node instanceof ERBIfNode || node.type === "AST_ERB_IF_NODE" || node.constructor.type === "AST_ERB_IF_NODE";
|
|
2855
2957
|
}
|
|
2856
2958
|
/**
|
|
2857
2959
|
* Checks if a node is a ERBBlockNode
|
|
2858
2960
|
*/
|
|
2859
2961
|
function isERBBlockNode(node) {
|
|
2860
|
-
return node instanceof ERBBlockNode || node.type === "AST_ERB_BLOCK_NODE";
|
|
2962
|
+
return node instanceof ERBBlockNode || node.type === "AST_ERB_BLOCK_NODE" || node.constructor.type === "AST_ERB_BLOCK_NODE";
|
|
2861
2963
|
}
|
|
2862
2964
|
/**
|
|
2863
2965
|
* Checks if a node is a ERBWhenNode
|
|
2864
2966
|
*/
|
|
2865
2967
|
function isERBWhenNode(node) {
|
|
2866
|
-
return node instanceof ERBWhenNode || node.type === "AST_ERB_WHEN_NODE";
|
|
2968
|
+
return node instanceof ERBWhenNode || node.type === "AST_ERB_WHEN_NODE" || node.constructor.type === "AST_ERB_WHEN_NODE";
|
|
2867
2969
|
}
|
|
2868
2970
|
/**
|
|
2869
2971
|
* Checks if a node is a ERBCaseNode
|
|
2870
2972
|
*/
|
|
2871
2973
|
function isERBCaseNode(node) {
|
|
2872
|
-
return node instanceof ERBCaseNode || node.type === "AST_ERB_CASE_NODE";
|
|
2974
|
+
return node instanceof ERBCaseNode || node.type === "AST_ERB_CASE_NODE" || node.constructor.type === "AST_ERB_CASE_NODE";
|
|
2873
2975
|
}
|
|
2874
2976
|
/**
|
|
2875
2977
|
* Checks if a node is a ERBCaseMatchNode
|
|
2876
2978
|
*/
|
|
2877
2979
|
function isERBCaseMatchNode(node) {
|
|
2878
|
-
return node instanceof ERBCaseMatchNode || node.type === "AST_ERB_CASE_MATCH_NODE";
|
|
2980
|
+
return node instanceof ERBCaseMatchNode || node.type === "AST_ERB_CASE_MATCH_NODE" || node.constructor.type === "AST_ERB_CASE_MATCH_NODE";
|
|
2879
2981
|
}
|
|
2880
2982
|
/**
|
|
2881
2983
|
* Checks if a node is a ERBWhileNode
|
|
2882
2984
|
*/
|
|
2883
2985
|
function isERBWhileNode(node) {
|
|
2884
|
-
return node instanceof ERBWhileNode || node.type === "AST_ERB_WHILE_NODE";
|
|
2986
|
+
return node instanceof ERBWhileNode || node.type === "AST_ERB_WHILE_NODE" || node.constructor.type === "AST_ERB_WHILE_NODE";
|
|
2885
2987
|
}
|
|
2886
2988
|
/**
|
|
2887
2989
|
* Checks if a node is a ERBUntilNode
|
|
2888
2990
|
*/
|
|
2889
2991
|
function isERBUntilNode(node) {
|
|
2890
|
-
return node instanceof ERBUntilNode || node.type === "AST_ERB_UNTIL_NODE";
|
|
2992
|
+
return node instanceof ERBUntilNode || node.type === "AST_ERB_UNTIL_NODE" || node.constructor.type === "AST_ERB_UNTIL_NODE";
|
|
2891
2993
|
}
|
|
2892
2994
|
/**
|
|
2893
2995
|
* Checks if a node is a ERBForNode
|
|
2894
2996
|
*/
|
|
2895
2997
|
function isERBForNode(node) {
|
|
2896
|
-
return node instanceof ERBForNode || node.type === "AST_ERB_FOR_NODE";
|
|
2998
|
+
return node instanceof ERBForNode || node.type === "AST_ERB_FOR_NODE" || node.constructor.type === "AST_ERB_FOR_NODE";
|
|
2897
2999
|
}
|
|
2898
3000
|
/**
|
|
2899
3001
|
* Checks if a node is a ERBRescueNode
|
|
2900
3002
|
*/
|
|
2901
3003
|
function isERBRescueNode(node) {
|
|
2902
|
-
return node instanceof ERBRescueNode || node.type === "AST_ERB_RESCUE_NODE";
|
|
3004
|
+
return node instanceof ERBRescueNode || node.type === "AST_ERB_RESCUE_NODE" || node.constructor.type === "AST_ERB_RESCUE_NODE";
|
|
2903
3005
|
}
|
|
2904
3006
|
/**
|
|
2905
3007
|
* Checks if a node is a ERBEnsureNode
|
|
2906
3008
|
*/
|
|
2907
3009
|
function isERBEnsureNode(node) {
|
|
2908
|
-
return node instanceof ERBEnsureNode || node.type === "AST_ERB_ENSURE_NODE";
|
|
3010
|
+
return node instanceof ERBEnsureNode || node.type === "AST_ERB_ENSURE_NODE" || node.constructor.type === "AST_ERB_ENSURE_NODE";
|
|
2909
3011
|
}
|
|
2910
3012
|
/**
|
|
2911
3013
|
* Checks if a node is a ERBBeginNode
|
|
2912
3014
|
*/
|
|
2913
3015
|
function isERBBeginNode(node) {
|
|
2914
|
-
return node instanceof ERBBeginNode || node.type === "AST_ERB_BEGIN_NODE";
|
|
3016
|
+
return node instanceof ERBBeginNode || node.type === "AST_ERB_BEGIN_NODE" || node.constructor.type === "AST_ERB_BEGIN_NODE";
|
|
2915
3017
|
}
|
|
2916
3018
|
/**
|
|
2917
3019
|
* Checks if a node is a ERBUnlessNode
|
|
2918
3020
|
*/
|
|
2919
3021
|
function isERBUnlessNode(node) {
|
|
2920
|
-
return node instanceof ERBUnlessNode || node.type === "AST_ERB_UNLESS_NODE";
|
|
3022
|
+
return node instanceof ERBUnlessNode || node.type === "AST_ERB_UNLESS_NODE" || node.constructor.type === "AST_ERB_UNLESS_NODE";
|
|
2921
3023
|
}
|
|
2922
3024
|
/**
|
|
2923
3025
|
* Checks if a node is a ERBYieldNode
|
|
2924
3026
|
*/
|
|
2925
3027
|
function isERBYieldNode(node) {
|
|
2926
|
-
return node instanceof ERBYieldNode || node.type === "AST_ERB_YIELD_NODE";
|
|
3028
|
+
return node instanceof ERBYieldNode || node.type === "AST_ERB_YIELD_NODE" || node.constructor.type === "AST_ERB_YIELD_NODE";
|
|
2927
3029
|
}
|
|
2928
3030
|
/**
|
|
2929
3031
|
* Checks if a node is a ERBInNode
|
|
2930
3032
|
*/
|
|
2931
3033
|
function isERBInNode(node) {
|
|
2932
|
-
return node instanceof ERBInNode || node.type === "AST_ERB_IN_NODE";
|
|
3034
|
+
return node instanceof ERBInNode || node.type === "AST_ERB_IN_NODE" || node.constructor.type === "AST_ERB_IN_NODE";
|
|
2933
3035
|
}
|
|
2934
3036
|
/**
|
|
2935
3037
|
* Convenience type guards for common node categories
|
|
@@ -3118,6 +3220,8 @@
|
|
|
3118
3220
|
return nodes.filter(node => isAnyOf(node, ...types));
|
|
3119
3221
|
}
|
|
3120
3222
|
function isNode(node, type) {
|
|
3223
|
+
if (!node)
|
|
3224
|
+
return false;
|
|
3121
3225
|
if (typeof type === 'string') {
|
|
3122
3226
|
const guard = AST_TYPE_GUARDS.get(type);
|
|
3123
3227
|
return guard ? guard(node) : false;
|
|
@@ -3493,6 +3597,87 @@
|
|
|
3493
3597
|
function isCommentNode(node) {
|
|
3494
3598
|
return isNode(node, HTMLCommentNode) || (isERBNode(node) && !isERBControlFlowNode(node));
|
|
3495
3599
|
}
|
|
3600
|
+
/**
|
|
3601
|
+
* Compares two positions to determine if the first comes before the second
|
|
3602
|
+
* Returns true if pos1 comes before pos2 in source order
|
|
3603
|
+
* @param inclusive - If true, returns true when positions are equal
|
|
3604
|
+
*/
|
|
3605
|
+
function isPositionBefore(position1, position2, inclusive = false) {
|
|
3606
|
+
if (position1.line < position2.line)
|
|
3607
|
+
return true;
|
|
3608
|
+
if (position1.line > position2.line)
|
|
3609
|
+
return false;
|
|
3610
|
+
return inclusive ? position1.column <= position2.column : position1.column < position2.column;
|
|
3611
|
+
}
|
|
3612
|
+
/**
|
|
3613
|
+
* Compares two positions to determine if they are equal
|
|
3614
|
+
* Returns true if pos1 and pos2 are at the same location
|
|
3615
|
+
*/
|
|
3616
|
+
function isPositionEqual(position1, position2) {
|
|
3617
|
+
return position1.line === position2.line && position1.column === position2.column;
|
|
3618
|
+
}
|
|
3619
|
+
/**
|
|
3620
|
+
* Compares two positions to determine if the first comes after the second
|
|
3621
|
+
* Returns true if pos1 comes after pos2 in source order
|
|
3622
|
+
* @param inclusive - If true, returns true when positions are equal
|
|
3623
|
+
*/
|
|
3624
|
+
function isPositionAfter(position1, position2, inclusive = false) {
|
|
3625
|
+
if (position1.line > position2.line)
|
|
3626
|
+
return true;
|
|
3627
|
+
if (position1.line < position2.line)
|
|
3628
|
+
return false;
|
|
3629
|
+
return inclusive ? position1.column >= position2.column : position1.column > position2.column;
|
|
3630
|
+
}
|
|
3631
|
+
/**
|
|
3632
|
+
* Gets nodes that appear before the specified location in source order
|
|
3633
|
+
* Uses line and column positions to determine ordering
|
|
3634
|
+
*/
|
|
3635
|
+
function getNodesBeforeLocation(nodes, location) {
|
|
3636
|
+
return nodes.filter(node => node.location && isPositionBefore(node.location.end, location.start));
|
|
3637
|
+
}
|
|
3638
|
+
/**
|
|
3639
|
+
* Gets nodes that appear after the specified location in source order
|
|
3640
|
+
* Uses line and column positions to determine ordering
|
|
3641
|
+
*/
|
|
3642
|
+
function getNodesAfterLocation(nodes, location) {
|
|
3643
|
+
return nodes.filter(node => node.location && isPositionAfter(node.location.start, location.end));
|
|
3644
|
+
}
|
|
3645
|
+
/**
|
|
3646
|
+
* Splits nodes into before and after the specified location
|
|
3647
|
+
* Returns an object with `before` and `after` arrays
|
|
3648
|
+
*/
|
|
3649
|
+
function splitNodesAroundLocation(nodes, location) {
|
|
3650
|
+
return {
|
|
3651
|
+
before: getNodesBeforeLocation(nodes, location),
|
|
3652
|
+
after: getNodesAfterLocation(nodes, location)
|
|
3653
|
+
};
|
|
3654
|
+
}
|
|
3655
|
+
/**
|
|
3656
|
+
* Splits nodes at a specific position
|
|
3657
|
+
* Returns nodes that end before the position and nodes that start after the position
|
|
3658
|
+
* More precise than splitNodesAroundLocation as it uses a single position point
|
|
3659
|
+
* Uses the same defaults as the individual functions: before=exclusive, after=inclusive
|
|
3660
|
+
*/
|
|
3661
|
+
function splitNodesAroundPosition(nodes, position) {
|
|
3662
|
+
return {
|
|
3663
|
+
before: getNodesBeforePosition(nodes, position), // uses default: inclusive = false
|
|
3664
|
+
after: getNodesAfterPosition(nodes, position) // uses default: inclusive = true
|
|
3665
|
+
};
|
|
3666
|
+
}
|
|
3667
|
+
/**
|
|
3668
|
+
* Gets nodes that end before the specified position
|
|
3669
|
+
* @param inclusive - If true, includes nodes that end exactly at the position (default: false, matching half-open interval semantics)
|
|
3670
|
+
*/
|
|
3671
|
+
function getNodesBeforePosition(nodes, position, inclusive = false) {
|
|
3672
|
+
return nodes.filter(node => node.location && isPositionBefore(node.location.end, position, inclusive));
|
|
3673
|
+
}
|
|
3674
|
+
/**
|
|
3675
|
+
* Gets nodes that start after the specified position
|
|
3676
|
+
* @param inclusive - If true, includes nodes that start exactly at the position (default: true, matching typical boundary behavior)
|
|
3677
|
+
*/
|
|
3678
|
+
function getNodesAfterPosition(nodes, position, inclusive = true) {
|
|
3679
|
+
return nodes.filter(node => node.location && isPositionAfter(node.location.start, position, inclusive));
|
|
3680
|
+
}
|
|
3496
3681
|
|
|
3497
3682
|
const expectedFunctions = [
|
|
3498
3683
|
"parse",
|
|
@@ -3545,7 +3730,7 @@
|
|
|
3545
3730
|
}
|
|
3546
3731
|
|
|
3547
3732
|
var name = "@herb-tools/core";
|
|
3548
|
-
var version = "0.6.
|
|
3733
|
+
var version = "0.6.1";
|
|
3549
3734
|
var packageJSON = {
|
|
3550
3735
|
name: name,
|
|
3551
3736
|
version: version};
|
|
@@ -3768,7 +3953,7 @@
|
|
|
3768
3953
|
}
|
|
3769
3954
|
|
|
3770
3955
|
// 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.
|
|
3956
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.6.1/templates/javascript/packages/core/src/visitor.ts.erb
|
|
3772
3957
|
class Visitor {
|
|
3773
3958
|
visit(node) {
|
|
3774
3959
|
if (!node)
|
|
@@ -3974,6 +4159,10 @@
|
|
|
3974
4159
|
exports.fromSerializedNode = fromSerializedNode;
|
|
3975
4160
|
exports.getCombinedAttributeName = getCombinedAttributeName;
|
|
3976
4161
|
exports.getCombinedStringFromNodes = getCombinedStringFromNodes;
|
|
4162
|
+
exports.getNodesAfterLocation = getNodesAfterLocation;
|
|
4163
|
+
exports.getNodesAfterPosition = getNodesAfterPosition;
|
|
4164
|
+
exports.getNodesBeforeLocation = getNodesBeforeLocation;
|
|
4165
|
+
exports.getNodesBeforePosition = getNodesBeforePosition;
|
|
3977
4166
|
exports.getStaticAttributeName = getStaticAttributeName;
|
|
3978
4167
|
exports.getStaticContentFromNodes = getStaticContentFromNodes;
|
|
3979
4168
|
exports.getStaticStringFromNodes = getStaticStringFromNodes;
|
|
@@ -4025,9 +4214,13 @@
|
|
|
4025
4214
|
exports.isNode = isNode;
|
|
4026
4215
|
exports.isNoneOf = isNoneOf;
|
|
4027
4216
|
exports.isParseResult = isParseResult;
|
|
4217
|
+
exports.isPositionAfter = isPositionAfter;
|
|
4218
|
+
exports.isPositionEqual = isPositionEqual;
|
|
4028
4219
|
exports.isToken = isToken;
|
|
4029
4220
|
exports.isWhitespaceNode = isWhitespaceNode;
|
|
4030
4221
|
exports.isXMLDeclarationNode = isXMLDeclarationNode;
|
|
4222
|
+
exports.splitNodesAroundLocation = splitNodesAroundLocation;
|
|
4223
|
+
exports.splitNodesAroundPosition = splitNodesAroundPosition;
|
|
4031
4224
|
exports.toMonacoDiagnostic = toMonacoDiagnostic;
|
|
4032
4225
|
|
|
4033
4226
|
}));
|