@herb-tools/core 0.1.1 → 0.2.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.
@@ -1,10 +1,3 @@
1
- class ASTNode {
2
- errors;
3
- constructor() {
4
- this.errors = [];
5
- }
6
- }
7
-
8
1
  const expectedFunctions = [
9
2
  "parse",
10
3
  "lex",
@@ -734,7 +727,7 @@ class RubyParseError extends HerbError {
734
727
  }
735
728
 
736
729
  var name = "@herb-tools/core";
737
- var version = "0.1.1";
730
+ var version = "0.2.0";
738
731
  var packageJSON = {
739
732
  name: name,
740
733
  version: version};
@@ -945,6 +938,7 @@ function fromSerializedNode(node) {
945
938
  case "AST_ERB_BLOCK_NODE": return ERBBlockNode.from(node);
946
939
  case "AST_ERB_WHEN_NODE": return ERBWhenNode.from(node);
947
940
  case "AST_ERB_CASE_NODE": return ERBCaseNode.from(node);
941
+ case "AST_ERB_CASE_MATCH_NODE": return ERBCaseMatchNode.from(node);
948
942
  case "AST_ERB_WHILE_NODE": return ERBWhileNode.from(node);
949
943
  case "AST_ERB_UNTIL_NODE": return ERBUntilNode.from(node);
950
944
  case "AST_ERB_FOR_NODE": return ERBForNode.from(node);
@@ -952,6 +946,8 @@ function fromSerializedNode(node) {
952
946
  case "AST_ERB_ENSURE_NODE": return ERBEnsureNode.from(node);
953
947
  case "AST_ERB_BEGIN_NODE": return ERBBeginNode.from(node);
954
948
  case "AST_ERB_UNLESS_NODE": return ERBUnlessNode.from(node);
949
+ case "AST_ERB_YIELD_NODE": return ERBYieldNode.from(node);
950
+ case "AST_ERB_IN_NODE": return ERBInNode.from(node);
955
951
  default:
956
952
  throw new Error(`Unknown node type: ${node.type}`);
957
953
  }
@@ -970,10 +966,16 @@ class DocumentNode extends Node {
970
966
  super(props.type, props.location, props.errors);
971
967
  this.children = props.children;
972
968
  }
969
+ accept(visitor) {
970
+ visitor.visitDocumentNode(this);
971
+ }
973
972
  childNodes() {
974
973
  return [
975
974
  ...this.children,
976
- ].filter(node => node !== null && node !== undefined);
975
+ ];
976
+ }
977
+ compactChildNodes() {
978
+ return this.childNodes().filter(node => node !== null && node !== undefined);
977
979
  }
978
980
  recursiveErrors() {
979
981
  return [
@@ -1011,8 +1013,14 @@ class LiteralNode extends Node {
1011
1013
  super(props.type, props.location, props.errors);
1012
1014
  this.content = convertToUTF8(props.content);
1013
1015
  }
1016
+ accept(visitor) {
1017
+ visitor.visitLiteralNode(this);
1018
+ }
1014
1019
  childNodes() {
1015
- return [].filter(node => node !== null && node !== undefined);
1020
+ return [];
1021
+ }
1022
+ compactChildNodes() {
1023
+ return this.childNodes().filter(node => node !== null && node !== undefined);
1016
1024
  }
1017
1025
  recursiveErrors() {
1018
1026
  return [
@@ -1061,10 +1069,16 @@ class HTMLOpenTagNode extends Node {
1061
1069
  this.children = props.children;
1062
1070
  this.is_void = props.is_void;
1063
1071
  }
1072
+ accept(visitor) {
1073
+ visitor.visitHTMLOpenTagNode(this);
1074
+ }
1064
1075
  childNodes() {
1065
1076
  return [
1066
1077
  ...this.children,
1067
- ].filter(node => node !== null && node !== undefined);
1078
+ ];
1079
+ }
1080
+ compactChildNodes() {
1081
+ return this.childNodes().filter(node => node !== null && node !== undefined);
1068
1082
  }
1069
1083
  recursiveErrors() {
1070
1084
  return [
@@ -1116,8 +1130,14 @@ class HTMLCloseTagNode extends Node {
1116
1130
  this.tag_name = props.tag_name;
1117
1131
  this.tag_closing = props.tag_closing;
1118
1132
  }
1133
+ accept(visitor) {
1134
+ visitor.visitHTMLCloseTagNode(this);
1135
+ }
1119
1136
  childNodes() {
1120
- return [].filter(node => node !== null && node !== undefined);
1137
+ return [];
1138
+ }
1139
+ compactChildNodes() {
1140
+ return this.childNodes().filter(node => node !== null && node !== undefined);
1121
1141
  }
1122
1142
  recursiveErrors() {
1123
1143
  return [
@@ -1170,10 +1190,16 @@ class HTMLSelfCloseTagNode extends Node {
1170
1190
  this.tag_closing = props.tag_closing;
1171
1191
  this.is_void = props.is_void;
1172
1192
  }
1193
+ accept(visitor) {
1194
+ visitor.visitHTMLSelfCloseTagNode(this);
1195
+ }
1173
1196
  childNodes() {
1174
1197
  return [
1175
1198
  ...this.attributes,
1176
- ].filter(node => node !== null && node !== undefined);
1199
+ ];
1200
+ }
1201
+ compactChildNodes() {
1202
+ return this.childNodes().filter(node => node !== null && node !== undefined);
1177
1203
  }
1178
1204
  recursiveErrors() {
1179
1205
  return [
@@ -1231,12 +1257,18 @@ class HTMLElementNode extends Node {
1231
1257
  this.close_tag = props.close_tag;
1232
1258
  this.is_void = props.is_void;
1233
1259
  }
1260
+ accept(visitor) {
1261
+ visitor.visitHTMLElementNode(this);
1262
+ }
1234
1263
  childNodes() {
1235
1264
  return [
1236
1265
  this.open_tag,
1237
1266
  ...this.body,
1238
1267
  this.close_tag,
1239
- ].filter(node => node !== null && node !== undefined);
1268
+ ];
1269
+ }
1270
+ compactChildNodes() {
1271
+ return this.childNodes().filter(node => node !== null && node !== undefined);
1240
1272
  }
1241
1273
  recursiveErrors() {
1242
1274
  return [
@@ -1293,10 +1325,16 @@ class HTMLAttributeValueNode extends Node {
1293
1325
  this.close_quote = props.close_quote;
1294
1326
  this.quoted = props.quoted;
1295
1327
  }
1328
+ accept(visitor) {
1329
+ visitor.visitHTMLAttributeValueNode(this);
1330
+ }
1296
1331
  childNodes() {
1297
1332
  return [
1298
1333
  ...this.children,
1299
- ].filter(node => node !== null && node !== undefined);
1334
+ ];
1335
+ }
1336
+ compactChildNodes() {
1337
+ return this.childNodes().filter(node => node !== null && node !== undefined);
1300
1338
  }
1301
1339
  recursiveErrors() {
1302
1340
  return [
@@ -1340,8 +1378,14 @@ class HTMLAttributeNameNode extends Node {
1340
1378
  super(props.type, props.location, props.errors);
1341
1379
  this.name = props.name;
1342
1380
  }
1381
+ accept(visitor) {
1382
+ visitor.visitHTMLAttributeNameNode(this);
1383
+ }
1343
1384
  childNodes() {
1344
- return [].filter(node => node !== null && node !== undefined);
1385
+ return [];
1386
+ }
1387
+ compactChildNodes() {
1388
+ return this.childNodes().filter(node => node !== null && node !== undefined);
1345
1389
  }
1346
1390
  recursiveErrors() {
1347
1391
  return [
@@ -1384,11 +1428,17 @@ class HTMLAttributeNode extends Node {
1384
1428
  this.equals = props.equals;
1385
1429
  this.value = props.value;
1386
1430
  }
1431
+ accept(visitor) {
1432
+ visitor.visitHTMLAttributeNode(this);
1433
+ }
1387
1434
  childNodes() {
1388
1435
  return [
1389
1436
  this.name,
1390
1437
  this.value,
1391
- ].filter(node => node !== null && node !== undefined);
1438
+ ];
1439
+ }
1440
+ compactChildNodes() {
1441
+ return this.childNodes().filter(node => node !== null && node !== undefined);
1392
1442
  }
1393
1443
  recursiveErrors() {
1394
1444
  return [
@@ -1431,8 +1481,14 @@ class HTMLTextNode extends Node {
1431
1481
  super(props.type, props.location, props.errors);
1432
1482
  this.content = convertToUTF8(props.content);
1433
1483
  }
1484
+ accept(visitor) {
1485
+ visitor.visitHTMLTextNode(this);
1486
+ }
1434
1487
  childNodes() {
1435
- return [].filter(node => node !== null && node !== undefined);
1488
+ return [];
1489
+ }
1490
+ compactChildNodes() {
1491
+ return this.childNodes().filter(node => node !== null && node !== undefined);
1436
1492
  }
1437
1493
  recursiveErrors() {
1438
1494
  return [
@@ -1475,10 +1531,16 @@ class HTMLCommentNode extends Node {
1475
1531
  this.children = props.children;
1476
1532
  this.comment_end = props.comment_end;
1477
1533
  }
1534
+ accept(visitor) {
1535
+ visitor.visitHTMLCommentNode(this);
1536
+ }
1478
1537
  childNodes() {
1479
1538
  return [
1480
1539
  ...this.children,
1481
- ].filter(node => node !== null && node !== undefined);
1540
+ ];
1541
+ }
1542
+ compactChildNodes() {
1543
+ return this.childNodes().filter(node => node !== null && node !== undefined);
1482
1544
  }
1483
1545
  recursiveErrors() {
1484
1546
  return [
@@ -1526,10 +1588,16 @@ class HTMLDoctypeNode extends Node {
1526
1588
  this.children = props.children;
1527
1589
  this.tag_closing = props.tag_closing;
1528
1590
  }
1591
+ accept(visitor) {
1592
+ visitor.visitHTMLDoctypeNode(this);
1593
+ }
1529
1594
  childNodes() {
1530
1595
  return [
1531
1596
  ...this.children,
1532
- ].filter(node => node !== null && node !== undefined);
1597
+ ];
1598
+ }
1599
+ compactChildNodes() {
1600
+ return this.childNodes().filter(node => node !== null && node !== undefined);
1533
1601
  }
1534
1602
  recursiveErrors() {
1535
1603
  return [
@@ -1571,8 +1639,14 @@ class WhitespaceNode extends Node {
1571
1639
  super(props.type, props.location, props.errors);
1572
1640
  this.value = props.value;
1573
1641
  }
1642
+ accept(visitor) {
1643
+ visitor.visitWhitespaceNode(this);
1644
+ }
1574
1645
  childNodes() {
1575
- return [].filter(node => node !== null && node !== undefined);
1646
+ return [];
1647
+ }
1648
+ compactChildNodes() {
1649
+ return this.childNodes().filter(node => node !== null && node !== undefined);
1576
1650
  }
1577
1651
  recursiveErrors() {
1578
1652
  return [
@@ -1624,8 +1698,14 @@ class ERBContentNode extends Node {
1624
1698
  this.parsed = props.parsed;
1625
1699
  this.valid = props.valid;
1626
1700
  }
1701
+ accept(visitor) {
1702
+ visitor.visitERBContentNode(this);
1703
+ }
1627
1704
  childNodes() {
1628
- return [].filter(node => node !== null && node !== undefined);
1705
+ return [];
1706
+ }
1707
+ compactChildNodes() {
1708
+ return this.childNodes().filter(node => node !== null && node !== undefined);
1629
1709
  }
1630
1710
  recursiveErrors() {
1631
1711
  return [
@@ -1678,8 +1758,14 @@ class ERBEndNode extends Node {
1678
1758
  this.content = props.content;
1679
1759
  this.tag_closing = props.tag_closing;
1680
1760
  }
1761
+ accept(visitor) {
1762
+ visitor.visitERBEndNode(this);
1763
+ }
1681
1764
  childNodes() {
1682
- return [].filter(node => node !== null && node !== undefined);
1765
+ return [];
1766
+ }
1767
+ compactChildNodes() {
1768
+ return this.childNodes().filter(node => node !== null && node !== undefined);
1683
1769
  }
1684
1770
  recursiveErrors() {
1685
1771
  return [
@@ -1729,10 +1815,16 @@ class ERBElseNode extends Node {
1729
1815
  this.tag_closing = props.tag_closing;
1730
1816
  this.statements = props.statements;
1731
1817
  }
1818
+ accept(visitor) {
1819
+ visitor.visitERBElseNode(this);
1820
+ }
1732
1821
  childNodes() {
1733
1822
  return [
1734
1823
  ...this.statements,
1735
- ].filter(node => node !== null && node !== undefined);
1824
+ ];
1825
+ }
1826
+ compactChildNodes() {
1827
+ return this.childNodes().filter(node => node !== null && node !== undefined);
1736
1828
  }
1737
1829
  recursiveErrors() {
1738
1830
  return [
@@ -1791,12 +1883,18 @@ class ERBIfNode extends Node {
1791
1883
  this.subsequent = props.subsequent;
1792
1884
  this.end_node = props.end_node;
1793
1885
  }
1886
+ accept(visitor) {
1887
+ visitor.visitERBIfNode(this);
1888
+ }
1794
1889
  childNodes() {
1795
1890
  return [
1796
1891
  ...this.statements,
1797
1892
  this.subsequent,
1798
1893
  this.end_node,
1799
- ].filter(node => node !== null && node !== undefined);
1894
+ ];
1895
+ }
1896
+ compactChildNodes() {
1897
+ return this.childNodes().filter(node => node !== null && node !== undefined);
1800
1898
  }
1801
1899
  recursiveErrors() {
1802
1900
  return [
@@ -1858,11 +1956,17 @@ class ERBBlockNode extends Node {
1858
1956
  this.body = props.body;
1859
1957
  this.end_node = props.end_node;
1860
1958
  }
1959
+ accept(visitor) {
1960
+ visitor.visitERBBlockNode(this);
1961
+ }
1861
1962
  childNodes() {
1862
1963
  return [
1863
1964
  ...this.body,
1864
1965
  this.end_node,
1865
- ].filter(node => node !== null && node !== undefined);
1966
+ ];
1967
+ }
1968
+ compactChildNodes() {
1969
+ return this.childNodes().filter(node => node !== null && node !== undefined);
1866
1970
  }
1867
1971
  recursiveErrors() {
1868
1972
  return [
@@ -1918,10 +2022,16 @@ class ERBWhenNode extends Node {
1918
2022
  this.tag_closing = props.tag_closing;
1919
2023
  this.statements = props.statements;
1920
2024
  }
2025
+ accept(visitor) {
2026
+ visitor.visitERBWhenNode(this);
2027
+ }
1921
2028
  childNodes() {
1922
2029
  return [
1923
2030
  ...this.statements,
1924
- ].filter(node => node !== null && node !== undefined);
2031
+ ];
2032
+ }
2033
+ compactChildNodes() {
2034
+ return this.childNodes().filter(node => node !== null && node !== undefined);
1925
2035
  }
1926
2036
  recursiveErrors() {
1927
2037
  return [
@@ -1983,13 +2093,19 @@ class ERBCaseNode extends Node {
1983
2093
  this.else_clause = props.else_clause;
1984
2094
  this.end_node = props.end_node;
1985
2095
  }
2096
+ accept(visitor) {
2097
+ visitor.visitERBCaseNode(this);
2098
+ }
1986
2099
  childNodes() {
1987
2100
  return [
1988
2101
  ...this.children,
1989
2102
  ...this.conditions,
1990
2103
  this.else_clause,
1991
2104
  this.end_node,
1992
- ].filter(node => node !== null && node !== undefined);
2105
+ ];
2106
+ }
2107
+ compactChildNodes() {
2108
+ return this.childNodes().filter(node => node !== null && node !== undefined);
1993
2109
  }
1994
2110
  recursiveErrors() {
1995
2111
  return [
@@ -2028,6 +2144,89 @@ class ERBCaseNode extends Node {
2028
2144
  return output;
2029
2145
  }
2030
2146
  }
2147
+ class ERBCaseMatchNode extends Node {
2148
+ tag_opening;
2149
+ content;
2150
+ tag_closing;
2151
+ children;
2152
+ conditions;
2153
+ else_clause;
2154
+ end_node;
2155
+ static from(data) {
2156
+ return new ERBCaseMatchNode({
2157
+ type: data.type,
2158
+ location: Location.from(data.location),
2159
+ errors: (data.errors || []).map(error => HerbError.from(error)),
2160
+ tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
2161
+ content: data.content ? Token.from(data.content) : null,
2162
+ tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
2163
+ children: (data.children || []).map(node => fromSerializedNode(node)),
2164
+ conditions: (data.conditions || []).map(node => fromSerializedNode(node)),
2165
+ else_clause: data.else_clause ? fromSerializedNode(data.else_clause) : null,
2166
+ end_node: data.end_node ? fromSerializedNode(data.end_node) : null,
2167
+ });
2168
+ }
2169
+ constructor(props) {
2170
+ super(props.type, props.location, props.errors);
2171
+ this.tag_opening = props.tag_opening;
2172
+ this.content = props.content;
2173
+ this.tag_closing = props.tag_closing;
2174
+ this.children = props.children;
2175
+ this.conditions = props.conditions;
2176
+ this.else_clause = props.else_clause;
2177
+ this.end_node = props.end_node;
2178
+ }
2179
+ accept(visitor) {
2180
+ visitor.visitERBCaseMatchNode(this);
2181
+ }
2182
+ childNodes() {
2183
+ return [
2184
+ ...this.children,
2185
+ ...this.conditions,
2186
+ this.else_clause,
2187
+ this.end_node,
2188
+ ];
2189
+ }
2190
+ compactChildNodes() {
2191
+ return this.childNodes().filter(node => node !== null && node !== undefined);
2192
+ }
2193
+ recursiveErrors() {
2194
+ return [
2195
+ ...this.errors,
2196
+ ...this.children.map(node => node.recursiveErrors()),
2197
+ ...this.conditions.map(node => node.recursiveErrors()),
2198
+ this.else_clause ? this.else_clause.recursiveErrors() : [],
2199
+ this.end_node ? this.end_node.recursiveErrors() : [],
2200
+ ].flat();
2201
+ }
2202
+ toJSON() {
2203
+ return {
2204
+ ...super.toJSON(),
2205
+ type: "AST_ERB_CASE_MATCH_NODE",
2206
+ tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
2207
+ content: this.content ? this.content.toJSON() : null,
2208
+ tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
2209
+ children: this.children.map(node => node.toJSON()),
2210
+ conditions: this.conditions.map(node => node.toJSON()),
2211
+ else_clause: this.else_clause ? this.else_clause.toJSON() : null,
2212
+ end_node: this.end_node ? this.end_node.toJSON() : null,
2213
+ };
2214
+ }
2215
+ treeInspect() {
2216
+ let output = "";
2217
+ output += `@ ERBCaseMatchNode ${this.location.treeInspectWithLabel()}\n`;
2218
+ output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
2219
+ output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
2220
+ output += `├── content: ${this.content ? this.content.treeInspect() : "∅"}\n`;
2221
+ output += `├── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
2222
+ output += `├── children: ${this.inspectArray(this.children, "│ ")}`;
2223
+ output += `├── conditions: ${this.inspectArray(this.conditions, "│ ")}`;
2224
+ output += `├── else_clause: ${this.inspectNode(this.else_clause, "│ ")}`;
2225
+ output += `└── end_node: ${this.inspectNode(this.end_node, " ")}`;
2226
+ // output += "\n";
2227
+ return output;
2228
+ }
2229
+ }
2031
2230
  class ERBWhileNode extends Node {
2032
2231
  tag_opening;
2033
2232
  content;
@@ -2054,11 +2253,17 @@ class ERBWhileNode extends Node {
2054
2253
  this.statements = props.statements;
2055
2254
  this.end_node = props.end_node;
2056
2255
  }
2256
+ accept(visitor) {
2257
+ visitor.visitERBWhileNode(this);
2258
+ }
2057
2259
  childNodes() {
2058
2260
  return [
2059
2261
  ...this.statements,
2060
2262
  this.end_node,
2061
- ].filter(node => node !== null && node !== undefined);
2263
+ ];
2264
+ }
2265
+ compactChildNodes() {
2266
+ return this.childNodes().filter(node => node !== null && node !== undefined);
2062
2267
  }
2063
2268
  recursiveErrors() {
2064
2269
  return [
@@ -2117,11 +2322,17 @@ class ERBUntilNode extends Node {
2117
2322
  this.statements = props.statements;
2118
2323
  this.end_node = props.end_node;
2119
2324
  }
2325
+ accept(visitor) {
2326
+ visitor.visitERBUntilNode(this);
2327
+ }
2120
2328
  childNodes() {
2121
2329
  return [
2122
2330
  ...this.statements,
2123
2331
  this.end_node,
2124
- ].filter(node => node !== null && node !== undefined);
2332
+ ];
2333
+ }
2334
+ compactChildNodes() {
2335
+ return this.childNodes().filter(node => node !== null && node !== undefined);
2125
2336
  }
2126
2337
  recursiveErrors() {
2127
2338
  return [
@@ -2180,11 +2391,17 @@ class ERBForNode extends Node {
2180
2391
  this.statements = props.statements;
2181
2392
  this.end_node = props.end_node;
2182
2393
  }
2394
+ accept(visitor) {
2395
+ visitor.visitERBForNode(this);
2396
+ }
2183
2397
  childNodes() {
2184
2398
  return [
2185
2399
  ...this.statements,
2186
2400
  this.end_node,
2187
- ].filter(node => node !== null && node !== undefined);
2401
+ ];
2402
+ }
2403
+ compactChildNodes() {
2404
+ return this.childNodes().filter(node => node !== null && node !== undefined);
2188
2405
  }
2189
2406
  recursiveErrors() {
2190
2407
  return [
@@ -2243,11 +2460,17 @@ class ERBRescueNode extends Node {
2243
2460
  this.statements = props.statements;
2244
2461
  this.subsequent = props.subsequent;
2245
2462
  }
2463
+ accept(visitor) {
2464
+ visitor.visitERBRescueNode(this);
2465
+ }
2246
2466
  childNodes() {
2247
2467
  return [
2248
2468
  ...this.statements,
2249
2469
  this.subsequent,
2250
- ].filter(node => node !== null && node !== undefined);
2470
+ ];
2471
+ }
2472
+ compactChildNodes() {
2473
+ return this.childNodes().filter(node => node !== null && node !== undefined);
2251
2474
  }
2252
2475
  recursiveErrors() {
2253
2476
  return [
@@ -2303,10 +2526,16 @@ class ERBEnsureNode extends Node {
2303
2526
  this.tag_closing = props.tag_closing;
2304
2527
  this.statements = props.statements;
2305
2528
  }
2529
+ accept(visitor) {
2530
+ visitor.visitERBEnsureNode(this);
2531
+ }
2306
2532
  childNodes() {
2307
2533
  return [
2308
2534
  ...this.statements,
2309
- ].filter(node => node !== null && node !== undefined);
2535
+ ];
2536
+ }
2537
+ compactChildNodes() {
2538
+ return this.childNodes().filter(node => node !== null && node !== undefined);
2310
2539
  }
2311
2540
  recursiveErrors() {
2312
2541
  return [
@@ -2371,6 +2600,9 @@ class ERBBeginNode extends Node {
2371
2600
  this.ensure_clause = props.ensure_clause;
2372
2601
  this.end_node = props.end_node;
2373
2602
  }
2603
+ accept(visitor) {
2604
+ visitor.visitERBBeginNode(this);
2605
+ }
2374
2606
  childNodes() {
2375
2607
  return [
2376
2608
  ...this.statements,
@@ -2378,7 +2610,10 @@ class ERBBeginNode extends Node {
2378
2610
  this.else_clause,
2379
2611
  this.ensure_clause,
2380
2612
  this.end_node,
2381
- ].filter(node => node !== null && node !== undefined);
2613
+ ];
2614
+ }
2615
+ compactChildNodes() {
2616
+ return this.childNodes().filter(node => node !== null && node !== undefined);
2382
2617
  }
2383
2618
  recursiveErrors() {
2384
2619
  return [
@@ -2449,12 +2684,18 @@ class ERBUnlessNode extends Node {
2449
2684
  this.else_clause = props.else_clause;
2450
2685
  this.end_node = props.end_node;
2451
2686
  }
2687
+ accept(visitor) {
2688
+ visitor.visitERBUnlessNode(this);
2689
+ }
2452
2690
  childNodes() {
2453
2691
  return [
2454
2692
  ...this.statements,
2455
2693
  this.else_clause,
2456
2694
  this.end_node,
2457
- ].filter(node => node !== null && node !== undefined);
2695
+ ];
2696
+ }
2697
+ compactChildNodes() {
2698
+ return this.childNodes().filter(node => node !== null && node !== undefined);
2458
2699
  }
2459
2700
  recursiveErrors() {
2460
2701
  return [
@@ -2490,6 +2731,122 @@ class ERBUnlessNode extends Node {
2490
2731
  return output;
2491
2732
  }
2492
2733
  }
2734
+ class ERBYieldNode extends Node {
2735
+ tag_opening;
2736
+ content;
2737
+ tag_closing;
2738
+ static from(data) {
2739
+ return new ERBYieldNode({
2740
+ type: data.type,
2741
+ location: Location.from(data.location),
2742
+ errors: (data.errors || []).map(error => HerbError.from(error)),
2743
+ tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
2744
+ content: data.content ? Token.from(data.content) : null,
2745
+ tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
2746
+ });
2747
+ }
2748
+ constructor(props) {
2749
+ super(props.type, props.location, props.errors);
2750
+ this.tag_opening = props.tag_opening;
2751
+ this.content = props.content;
2752
+ this.tag_closing = props.tag_closing;
2753
+ }
2754
+ accept(visitor) {
2755
+ visitor.visitERBYieldNode(this);
2756
+ }
2757
+ childNodes() {
2758
+ return [];
2759
+ }
2760
+ compactChildNodes() {
2761
+ return this.childNodes().filter(node => node !== null && node !== undefined);
2762
+ }
2763
+ recursiveErrors() {
2764
+ return [
2765
+ ...this.errors,
2766
+ ].flat();
2767
+ }
2768
+ toJSON() {
2769
+ return {
2770
+ ...super.toJSON(),
2771
+ type: "AST_ERB_YIELD_NODE",
2772
+ tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
2773
+ content: this.content ? this.content.toJSON() : null,
2774
+ tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
2775
+ };
2776
+ }
2777
+ treeInspect() {
2778
+ let output = "";
2779
+ output += `@ ERBYieldNode ${this.location.treeInspectWithLabel()}\n`;
2780
+ output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
2781
+ output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
2782
+ output += `├── content: ${this.content ? this.content.treeInspect() : "∅"}\n`;
2783
+ output += `└── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
2784
+ // output += "\n";
2785
+ return output;
2786
+ }
2787
+ }
2788
+ class ERBInNode extends Node {
2789
+ tag_opening;
2790
+ content;
2791
+ tag_closing;
2792
+ statements;
2793
+ static from(data) {
2794
+ return new ERBInNode({
2795
+ type: data.type,
2796
+ location: Location.from(data.location),
2797
+ errors: (data.errors || []).map(error => HerbError.from(error)),
2798
+ tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
2799
+ content: data.content ? Token.from(data.content) : null,
2800
+ tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
2801
+ statements: (data.statements || []).map(node => fromSerializedNode(node)),
2802
+ });
2803
+ }
2804
+ constructor(props) {
2805
+ super(props.type, props.location, props.errors);
2806
+ this.tag_opening = props.tag_opening;
2807
+ this.content = props.content;
2808
+ this.tag_closing = props.tag_closing;
2809
+ this.statements = props.statements;
2810
+ }
2811
+ accept(visitor) {
2812
+ visitor.visitERBInNode(this);
2813
+ }
2814
+ childNodes() {
2815
+ return [
2816
+ ...this.statements,
2817
+ ];
2818
+ }
2819
+ compactChildNodes() {
2820
+ return this.childNodes().filter(node => node !== null && node !== undefined);
2821
+ }
2822
+ recursiveErrors() {
2823
+ return [
2824
+ ...this.errors,
2825
+ ...this.statements.map(node => node.recursiveErrors()),
2826
+ ].flat();
2827
+ }
2828
+ toJSON() {
2829
+ return {
2830
+ ...super.toJSON(),
2831
+ type: "AST_ERB_IN_NODE",
2832
+ tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
2833
+ content: this.content ? this.content.toJSON() : null,
2834
+ tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
2835
+ statements: this.statements.map(node => node.toJSON()),
2836
+ };
2837
+ }
2838
+ treeInspect() {
2839
+ let output = "";
2840
+ output += `@ ERBInNode ${this.location.treeInspectWithLabel()}\n`;
2841
+ output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
2842
+ output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
2843
+ output += `├── content: ${this.content ? this.content.treeInspect() : "∅"}\n`;
2844
+ output += `├── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
2845
+ output += `└── statements: ${this.inspectArray(this.statements, " ")}`;
2846
+ // output += "\n";
2847
+ return output;
2848
+ }
2849
+ }
2493
2850
 
2494
2851
  class HerbWarning {
2495
2852
  message;
@@ -2687,18 +3044,111 @@ class HerbBackend {
2687
3044
  }
2688
3045
  }
2689
3046
 
2690
- /**
2691
- * Represents a visitor that can traverse nodes.
2692
- */
3047
+ // NOTE: This file is generated by the templates/template.rb script and should not
3048
+ // be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/visitor.ts.erb
2693
3049
  class Visitor {
2694
- /**
2695
- * Visits a node and performs an action.
2696
- * @param node - The node to visit.
2697
- */
2698
3050
  visit(node) {
2699
- console.log("Node", node); // TODO: implement
3051
+ if (!node)
3052
+ return;
3053
+ node.accept(this);
3054
+ }
3055
+ visitAll(nodes) {
3056
+ nodes.forEach(node => node?.accept(this));
3057
+ }
3058
+ visitChildNodes(node) {
3059
+ node.compactChildNodes().forEach(node => node.accept(this));
3060
+ }
3061
+ visitDocumentNode(node) {
3062
+ this.visitChildNodes(node);
3063
+ }
3064
+ visitLiteralNode(node) {
3065
+ this.visitChildNodes(node);
3066
+ }
3067
+ visitHTMLOpenTagNode(node) {
3068
+ this.visitChildNodes(node);
3069
+ }
3070
+ visitHTMLCloseTagNode(node) {
3071
+ this.visitChildNodes(node);
3072
+ }
3073
+ visitHTMLSelfCloseTagNode(node) {
3074
+ this.visitChildNodes(node);
3075
+ }
3076
+ visitHTMLElementNode(node) {
3077
+ this.visitChildNodes(node);
3078
+ }
3079
+ visitHTMLAttributeValueNode(node) {
3080
+ this.visitChildNodes(node);
3081
+ }
3082
+ visitHTMLAttributeNameNode(node) {
3083
+ this.visitChildNodes(node);
3084
+ }
3085
+ visitHTMLAttributeNode(node) {
3086
+ this.visitChildNodes(node);
3087
+ }
3088
+ visitHTMLTextNode(node) {
3089
+ this.visitChildNodes(node);
3090
+ }
3091
+ visitHTMLCommentNode(node) {
3092
+ this.visitChildNodes(node);
3093
+ }
3094
+ visitHTMLDoctypeNode(node) {
3095
+ this.visitChildNodes(node);
3096
+ }
3097
+ visitWhitespaceNode(node) {
3098
+ this.visitChildNodes(node);
3099
+ }
3100
+ visitERBContentNode(node) {
3101
+ this.visitChildNodes(node);
3102
+ }
3103
+ visitERBEndNode(node) {
3104
+ this.visitChildNodes(node);
3105
+ }
3106
+ visitERBElseNode(node) {
3107
+ this.visitChildNodes(node);
3108
+ }
3109
+ visitERBIfNode(node) {
3110
+ this.visitChildNodes(node);
3111
+ }
3112
+ visitERBBlockNode(node) {
3113
+ this.visitChildNodes(node);
3114
+ }
3115
+ visitERBWhenNode(node) {
3116
+ this.visitChildNodes(node);
3117
+ }
3118
+ visitERBCaseNode(node) {
3119
+ this.visitChildNodes(node);
3120
+ }
3121
+ visitERBCaseMatchNode(node) {
3122
+ this.visitChildNodes(node);
3123
+ }
3124
+ visitERBWhileNode(node) {
3125
+ this.visitChildNodes(node);
3126
+ }
3127
+ visitERBUntilNode(node) {
3128
+ this.visitChildNodes(node);
3129
+ }
3130
+ visitERBForNode(node) {
3131
+ this.visitChildNodes(node);
3132
+ }
3133
+ visitERBRescueNode(node) {
3134
+ this.visitChildNodes(node);
3135
+ }
3136
+ visitERBEnsureNode(node) {
3137
+ this.visitChildNodes(node);
3138
+ }
3139
+ visitERBBeginNode(node) {
3140
+ this.visitChildNodes(node);
3141
+ }
3142
+ visitERBUnlessNode(node) {
3143
+ this.visitChildNodes(node);
3144
+ }
3145
+ visitERBYieldNode(node) {
3146
+ this.visitChildNodes(node);
3147
+ }
3148
+ visitERBInNode(node) {
3149
+ this.visitChildNodes(node);
2700
3150
  }
2701
3151
  }
2702
3152
 
2703
- export { ASTNode, DocumentNode, ERBBeginNode, ERBBlockNode, ERBCaseNode, ERBContentNode, ERBElseNode, ERBEndNode, ERBEnsureNode, ERBForNode, ERBIfNode, ERBRescueNode, ERBUnlessNode, ERBUntilNode, ERBWhenNode, ERBWhileNode, HTMLAttributeNameNode, HTMLAttributeNode, HTMLAttributeValueNode, HTMLCloseTagNode, HTMLCommentNode, HTMLDoctypeNode, HTMLElementNode, HTMLOpenTagNode, HTMLSelfCloseTagNode, HTMLTextNode, HerbBackend, LexResult, LiteralNode, Location, MissingClosingTagError, MissingOpeningTagError, ParseResult, Position, QuotesMismatchError, Range, Result, RubyParseError, TagNamesMismatchError, Token, TokenList, UnclosedElementError, UnexpectedError, UnexpectedTokenError, Visitor, VoidElementClosingTagError, WhitespaceNode, _TYPECHECK, convertToUTF8, ensureLibHerbBackend, ensureString, fromSerializedError, fromSerializedNode, isLibHerbBackend };
3153
+ export { DocumentNode, ERBBeginNode, ERBBlockNode, ERBCaseMatchNode, ERBCaseNode, ERBContentNode, ERBElseNode, ERBEndNode, ERBEnsureNode, ERBForNode, ERBIfNode, ERBInNode, ERBRescueNode, ERBUnlessNode, ERBUntilNode, ERBWhenNode, ERBWhileNode, ERBYieldNode, HTMLAttributeNameNode, HTMLAttributeNode, HTMLAttributeValueNode, HTMLCloseTagNode, HTMLCommentNode, HTMLDoctypeNode, HTMLElementNode, HTMLOpenTagNode, HTMLSelfCloseTagNode, HTMLTextNode, HerbBackend, LexResult, LiteralNode, Location, MissingClosingTagError, MissingOpeningTagError, Node, ParseResult, Position, QuotesMismatchError, Range, Result, RubyParseError, TagNamesMismatchError, Token, TokenList, UnclosedElementError, UnexpectedError, UnexpectedTokenError, Visitor, VoidElementClosingTagError, WhitespaceNode, _TYPECHECK, convertToUTF8, ensureLibHerbBackend, ensureString, fromSerializedError, fromSerializedNode, isLibHerbBackend };
2704
3154
  //# sourceMappingURL=herb-core.esm.js.map