@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.
- package/CHANGELOG.md +4 -0
- package/dist/herb-core.browser.js +494 -44
- package/dist/herb-core.browser.js.map +1 -1
- package/dist/herb-core.cjs +497 -44
- package/dist/herb-core.cjs.map +1 -1
- package/dist/herb-core.esm.js +494 -44
- package/dist/herb-core.esm.js.map +1 -1
- package/dist/herb-core.umd.js +497 -44
- package/dist/herb-core.umd.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/node.d.ts +4 -1
- package/dist/types/nodes.d.ts +174 -32
- package/dist/types/visitor.d.ts +35 -9
- package/package.json +2 -11
- package/src/index.ts +1 -1
- package/src/node.ts +4 -1
- package/src/nodes.ts +568 -60
- package/src/visitor.ts +170 -10
- package/dist/types/ast.d.ts +0 -4
- package/src/ast.ts +0 -7
package/dist/herb-core.umd.js
CHANGED
|
@@ -4,13 +4,6 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Herb = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
class ASTNode {
|
|
8
|
-
errors;
|
|
9
|
-
constructor() {
|
|
10
|
-
this.errors = [];
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
7
|
const expectedFunctions = [
|
|
15
8
|
"parse",
|
|
16
9
|
"lex",
|
|
@@ -740,7 +733,7 @@
|
|
|
740
733
|
}
|
|
741
734
|
|
|
742
735
|
var name = "@herb-tools/core";
|
|
743
|
-
var version = "0.
|
|
736
|
+
var version = "0.2.0";
|
|
744
737
|
var packageJSON = {
|
|
745
738
|
name: name,
|
|
746
739
|
version: version};
|
|
@@ -951,6 +944,7 @@
|
|
|
951
944
|
case "AST_ERB_BLOCK_NODE": return ERBBlockNode.from(node);
|
|
952
945
|
case "AST_ERB_WHEN_NODE": return ERBWhenNode.from(node);
|
|
953
946
|
case "AST_ERB_CASE_NODE": return ERBCaseNode.from(node);
|
|
947
|
+
case "AST_ERB_CASE_MATCH_NODE": return ERBCaseMatchNode.from(node);
|
|
954
948
|
case "AST_ERB_WHILE_NODE": return ERBWhileNode.from(node);
|
|
955
949
|
case "AST_ERB_UNTIL_NODE": return ERBUntilNode.from(node);
|
|
956
950
|
case "AST_ERB_FOR_NODE": return ERBForNode.from(node);
|
|
@@ -958,6 +952,8 @@
|
|
|
958
952
|
case "AST_ERB_ENSURE_NODE": return ERBEnsureNode.from(node);
|
|
959
953
|
case "AST_ERB_BEGIN_NODE": return ERBBeginNode.from(node);
|
|
960
954
|
case "AST_ERB_UNLESS_NODE": return ERBUnlessNode.from(node);
|
|
955
|
+
case "AST_ERB_YIELD_NODE": return ERBYieldNode.from(node);
|
|
956
|
+
case "AST_ERB_IN_NODE": return ERBInNode.from(node);
|
|
961
957
|
default:
|
|
962
958
|
throw new Error(`Unknown node type: ${node.type}`);
|
|
963
959
|
}
|
|
@@ -976,10 +972,16 @@
|
|
|
976
972
|
super(props.type, props.location, props.errors);
|
|
977
973
|
this.children = props.children;
|
|
978
974
|
}
|
|
975
|
+
accept(visitor) {
|
|
976
|
+
visitor.visitDocumentNode(this);
|
|
977
|
+
}
|
|
979
978
|
childNodes() {
|
|
980
979
|
return [
|
|
981
980
|
...this.children,
|
|
982
|
-
]
|
|
981
|
+
];
|
|
982
|
+
}
|
|
983
|
+
compactChildNodes() {
|
|
984
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
983
985
|
}
|
|
984
986
|
recursiveErrors() {
|
|
985
987
|
return [
|
|
@@ -1017,8 +1019,14 @@
|
|
|
1017
1019
|
super(props.type, props.location, props.errors);
|
|
1018
1020
|
this.content = convertToUTF8(props.content);
|
|
1019
1021
|
}
|
|
1022
|
+
accept(visitor) {
|
|
1023
|
+
visitor.visitLiteralNode(this);
|
|
1024
|
+
}
|
|
1020
1025
|
childNodes() {
|
|
1021
|
-
return []
|
|
1026
|
+
return [];
|
|
1027
|
+
}
|
|
1028
|
+
compactChildNodes() {
|
|
1029
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1022
1030
|
}
|
|
1023
1031
|
recursiveErrors() {
|
|
1024
1032
|
return [
|
|
@@ -1067,10 +1075,16 @@
|
|
|
1067
1075
|
this.children = props.children;
|
|
1068
1076
|
this.is_void = props.is_void;
|
|
1069
1077
|
}
|
|
1078
|
+
accept(visitor) {
|
|
1079
|
+
visitor.visitHTMLOpenTagNode(this);
|
|
1080
|
+
}
|
|
1070
1081
|
childNodes() {
|
|
1071
1082
|
return [
|
|
1072
1083
|
...this.children,
|
|
1073
|
-
]
|
|
1084
|
+
];
|
|
1085
|
+
}
|
|
1086
|
+
compactChildNodes() {
|
|
1087
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1074
1088
|
}
|
|
1075
1089
|
recursiveErrors() {
|
|
1076
1090
|
return [
|
|
@@ -1122,8 +1136,14 @@
|
|
|
1122
1136
|
this.tag_name = props.tag_name;
|
|
1123
1137
|
this.tag_closing = props.tag_closing;
|
|
1124
1138
|
}
|
|
1139
|
+
accept(visitor) {
|
|
1140
|
+
visitor.visitHTMLCloseTagNode(this);
|
|
1141
|
+
}
|
|
1125
1142
|
childNodes() {
|
|
1126
|
-
return []
|
|
1143
|
+
return [];
|
|
1144
|
+
}
|
|
1145
|
+
compactChildNodes() {
|
|
1146
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1127
1147
|
}
|
|
1128
1148
|
recursiveErrors() {
|
|
1129
1149
|
return [
|
|
@@ -1176,10 +1196,16 @@
|
|
|
1176
1196
|
this.tag_closing = props.tag_closing;
|
|
1177
1197
|
this.is_void = props.is_void;
|
|
1178
1198
|
}
|
|
1199
|
+
accept(visitor) {
|
|
1200
|
+
visitor.visitHTMLSelfCloseTagNode(this);
|
|
1201
|
+
}
|
|
1179
1202
|
childNodes() {
|
|
1180
1203
|
return [
|
|
1181
1204
|
...this.attributes,
|
|
1182
|
-
]
|
|
1205
|
+
];
|
|
1206
|
+
}
|
|
1207
|
+
compactChildNodes() {
|
|
1208
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1183
1209
|
}
|
|
1184
1210
|
recursiveErrors() {
|
|
1185
1211
|
return [
|
|
@@ -1237,12 +1263,18 @@
|
|
|
1237
1263
|
this.close_tag = props.close_tag;
|
|
1238
1264
|
this.is_void = props.is_void;
|
|
1239
1265
|
}
|
|
1266
|
+
accept(visitor) {
|
|
1267
|
+
visitor.visitHTMLElementNode(this);
|
|
1268
|
+
}
|
|
1240
1269
|
childNodes() {
|
|
1241
1270
|
return [
|
|
1242
1271
|
this.open_tag,
|
|
1243
1272
|
...this.body,
|
|
1244
1273
|
this.close_tag,
|
|
1245
|
-
]
|
|
1274
|
+
];
|
|
1275
|
+
}
|
|
1276
|
+
compactChildNodes() {
|
|
1277
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1246
1278
|
}
|
|
1247
1279
|
recursiveErrors() {
|
|
1248
1280
|
return [
|
|
@@ -1299,10 +1331,16 @@
|
|
|
1299
1331
|
this.close_quote = props.close_quote;
|
|
1300
1332
|
this.quoted = props.quoted;
|
|
1301
1333
|
}
|
|
1334
|
+
accept(visitor) {
|
|
1335
|
+
visitor.visitHTMLAttributeValueNode(this);
|
|
1336
|
+
}
|
|
1302
1337
|
childNodes() {
|
|
1303
1338
|
return [
|
|
1304
1339
|
...this.children,
|
|
1305
|
-
]
|
|
1340
|
+
];
|
|
1341
|
+
}
|
|
1342
|
+
compactChildNodes() {
|
|
1343
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1306
1344
|
}
|
|
1307
1345
|
recursiveErrors() {
|
|
1308
1346
|
return [
|
|
@@ -1346,8 +1384,14 @@
|
|
|
1346
1384
|
super(props.type, props.location, props.errors);
|
|
1347
1385
|
this.name = props.name;
|
|
1348
1386
|
}
|
|
1387
|
+
accept(visitor) {
|
|
1388
|
+
visitor.visitHTMLAttributeNameNode(this);
|
|
1389
|
+
}
|
|
1349
1390
|
childNodes() {
|
|
1350
|
-
return []
|
|
1391
|
+
return [];
|
|
1392
|
+
}
|
|
1393
|
+
compactChildNodes() {
|
|
1394
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1351
1395
|
}
|
|
1352
1396
|
recursiveErrors() {
|
|
1353
1397
|
return [
|
|
@@ -1390,11 +1434,17 @@
|
|
|
1390
1434
|
this.equals = props.equals;
|
|
1391
1435
|
this.value = props.value;
|
|
1392
1436
|
}
|
|
1437
|
+
accept(visitor) {
|
|
1438
|
+
visitor.visitHTMLAttributeNode(this);
|
|
1439
|
+
}
|
|
1393
1440
|
childNodes() {
|
|
1394
1441
|
return [
|
|
1395
1442
|
this.name,
|
|
1396
1443
|
this.value,
|
|
1397
|
-
]
|
|
1444
|
+
];
|
|
1445
|
+
}
|
|
1446
|
+
compactChildNodes() {
|
|
1447
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1398
1448
|
}
|
|
1399
1449
|
recursiveErrors() {
|
|
1400
1450
|
return [
|
|
@@ -1437,8 +1487,14 @@
|
|
|
1437
1487
|
super(props.type, props.location, props.errors);
|
|
1438
1488
|
this.content = convertToUTF8(props.content);
|
|
1439
1489
|
}
|
|
1490
|
+
accept(visitor) {
|
|
1491
|
+
visitor.visitHTMLTextNode(this);
|
|
1492
|
+
}
|
|
1440
1493
|
childNodes() {
|
|
1441
|
-
return []
|
|
1494
|
+
return [];
|
|
1495
|
+
}
|
|
1496
|
+
compactChildNodes() {
|
|
1497
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1442
1498
|
}
|
|
1443
1499
|
recursiveErrors() {
|
|
1444
1500
|
return [
|
|
@@ -1481,10 +1537,16 @@
|
|
|
1481
1537
|
this.children = props.children;
|
|
1482
1538
|
this.comment_end = props.comment_end;
|
|
1483
1539
|
}
|
|
1540
|
+
accept(visitor) {
|
|
1541
|
+
visitor.visitHTMLCommentNode(this);
|
|
1542
|
+
}
|
|
1484
1543
|
childNodes() {
|
|
1485
1544
|
return [
|
|
1486
1545
|
...this.children,
|
|
1487
|
-
]
|
|
1546
|
+
];
|
|
1547
|
+
}
|
|
1548
|
+
compactChildNodes() {
|
|
1549
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1488
1550
|
}
|
|
1489
1551
|
recursiveErrors() {
|
|
1490
1552
|
return [
|
|
@@ -1532,10 +1594,16 @@
|
|
|
1532
1594
|
this.children = props.children;
|
|
1533
1595
|
this.tag_closing = props.tag_closing;
|
|
1534
1596
|
}
|
|
1597
|
+
accept(visitor) {
|
|
1598
|
+
visitor.visitHTMLDoctypeNode(this);
|
|
1599
|
+
}
|
|
1535
1600
|
childNodes() {
|
|
1536
1601
|
return [
|
|
1537
1602
|
...this.children,
|
|
1538
|
-
]
|
|
1603
|
+
];
|
|
1604
|
+
}
|
|
1605
|
+
compactChildNodes() {
|
|
1606
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1539
1607
|
}
|
|
1540
1608
|
recursiveErrors() {
|
|
1541
1609
|
return [
|
|
@@ -1577,8 +1645,14 @@
|
|
|
1577
1645
|
super(props.type, props.location, props.errors);
|
|
1578
1646
|
this.value = props.value;
|
|
1579
1647
|
}
|
|
1648
|
+
accept(visitor) {
|
|
1649
|
+
visitor.visitWhitespaceNode(this);
|
|
1650
|
+
}
|
|
1580
1651
|
childNodes() {
|
|
1581
|
-
return []
|
|
1652
|
+
return [];
|
|
1653
|
+
}
|
|
1654
|
+
compactChildNodes() {
|
|
1655
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1582
1656
|
}
|
|
1583
1657
|
recursiveErrors() {
|
|
1584
1658
|
return [
|
|
@@ -1630,8 +1704,14 @@
|
|
|
1630
1704
|
this.parsed = props.parsed;
|
|
1631
1705
|
this.valid = props.valid;
|
|
1632
1706
|
}
|
|
1707
|
+
accept(visitor) {
|
|
1708
|
+
visitor.visitERBContentNode(this);
|
|
1709
|
+
}
|
|
1633
1710
|
childNodes() {
|
|
1634
|
-
return []
|
|
1711
|
+
return [];
|
|
1712
|
+
}
|
|
1713
|
+
compactChildNodes() {
|
|
1714
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1635
1715
|
}
|
|
1636
1716
|
recursiveErrors() {
|
|
1637
1717
|
return [
|
|
@@ -1684,8 +1764,14 @@
|
|
|
1684
1764
|
this.content = props.content;
|
|
1685
1765
|
this.tag_closing = props.tag_closing;
|
|
1686
1766
|
}
|
|
1767
|
+
accept(visitor) {
|
|
1768
|
+
visitor.visitERBEndNode(this);
|
|
1769
|
+
}
|
|
1687
1770
|
childNodes() {
|
|
1688
|
-
return []
|
|
1771
|
+
return [];
|
|
1772
|
+
}
|
|
1773
|
+
compactChildNodes() {
|
|
1774
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1689
1775
|
}
|
|
1690
1776
|
recursiveErrors() {
|
|
1691
1777
|
return [
|
|
@@ -1735,10 +1821,16 @@
|
|
|
1735
1821
|
this.tag_closing = props.tag_closing;
|
|
1736
1822
|
this.statements = props.statements;
|
|
1737
1823
|
}
|
|
1824
|
+
accept(visitor) {
|
|
1825
|
+
visitor.visitERBElseNode(this);
|
|
1826
|
+
}
|
|
1738
1827
|
childNodes() {
|
|
1739
1828
|
return [
|
|
1740
1829
|
...this.statements,
|
|
1741
|
-
]
|
|
1830
|
+
];
|
|
1831
|
+
}
|
|
1832
|
+
compactChildNodes() {
|
|
1833
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1742
1834
|
}
|
|
1743
1835
|
recursiveErrors() {
|
|
1744
1836
|
return [
|
|
@@ -1797,12 +1889,18 @@
|
|
|
1797
1889
|
this.subsequent = props.subsequent;
|
|
1798
1890
|
this.end_node = props.end_node;
|
|
1799
1891
|
}
|
|
1892
|
+
accept(visitor) {
|
|
1893
|
+
visitor.visitERBIfNode(this);
|
|
1894
|
+
}
|
|
1800
1895
|
childNodes() {
|
|
1801
1896
|
return [
|
|
1802
1897
|
...this.statements,
|
|
1803
1898
|
this.subsequent,
|
|
1804
1899
|
this.end_node,
|
|
1805
|
-
]
|
|
1900
|
+
];
|
|
1901
|
+
}
|
|
1902
|
+
compactChildNodes() {
|
|
1903
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1806
1904
|
}
|
|
1807
1905
|
recursiveErrors() {
|
|
1808
1906
|
return [
|
|
@@ -1864,11 +1962,17 @@
|
|
|
1864
1962
|
this.body = props.body;
|
|
1865
1963
|
this.end_node = props.end_node;
|
|
1866
1964
|
}
|
|
1965
|
+
accept(visitor) {
|
|
1966
|
+
visitor.visitERBBlockNode(this);
|
|
1967
|
+
}
|
|
1867
1968
|
childNodes() {
|
|
1868
1969
|
return [
|
|
1869
1970
|
...this.body,
|
|
1870
1971
|
this.end_node,
|
|
1871
|
-
]
|
|
1972
|
+
];
|
|
1973
|
+
}
|
|
1974
|
+
compactChildNodes() {
|
|
1975
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1872
1976
|
}
|
|
1873
1977
|
recursiveErrors() {
|
|
1874
1978
|
return [
|
|
@@ -1924,10 +2028,16 @@
|
|
|
1924
2028
|
this.tag_closing = props.tag_closing;
|
|
1925
2029
|
this.statements = props.statements;
|
|
1926
2030
|
}
|
|
2031
|
+
accept(visitor) {
|
|
2032
|
+
visitor.visitERBWhenNode(this);
|
|
2033
|
+
}
|
|
1927
2034
|
childNodes() {
|
|
1928
2035
|
return [
|
|
1929
2036
|
...this.statements,
|
|
1930
|
-
]
|
|
2037
|
+
];
|
|
2038
|
+
}
|
|
2039
|
+
compactChildNodes() {
|
|
2040
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1931
2041
|
}
|
|
1932
2042
|
recursiveErrors() {
|
|
1933
2043
|
return [
|
|
@@ -1989,13 +2099,19 @@
|
|
|
1989
2099
|
this.else_clause = props.else_clause;
|
|
1990
2100
|
this.end_node = props.end_node;
|
|
1991
2101
|
}
|
|
2102
|
+
accept(visitor) {
|
|
2103
|
+
visitor.visitERBCaseNode(this);
|
|
2104
|
+
}
|
|
1992
2105
|
childNodes() {
|
|
1993
2106
|
return [
|
|
1994
2107
|
...this.children,
|
|
1995
2108
|
...this.conditions,
|
|
1996
2109
|
this.else_clause,
|
|
1997
2110
|
this.end_node,
|
|
1998
|
-
]
|
|
2111
|
+
];
|
|
2112
|
+
}
|
|
2113
|
+
compactChildNodes() {
|
|
2114
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1999
2115
|
}
|
|
2000
2116
|
recursiveErrors() {
|
|
2001
2117
|
return [
|
|
@@ -2034,6 +2150,89 @@
|
|
|
2034
2150
|
return output;
|
|
2035
2151
|
}
|
|
2036
2152
|
}
|
|
2153
|
+
class ERBCaseMatchNode extends Node {
|
|
2154
|
+
tag_opening;
|
|
2155
|
+
content;
|
|
2156
|
+
tag_closing;
|
|
2157
|
+
children;
|
|
2158
|
+
conditions;
|
|
2159
|
+
else_clause;
|
|
2160
|
+
end_node;
|
|
2161
|
+
static from(data) {
|
|
2162
|
+
return new ERBCaseMatchNode({
|
|
2163
|
+
type: data.type,
|
|
2164
|
+
location: Location.from(data.location),
|
|
2165
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
2166
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
2167
|
+
content: data.content ? Token.from(data.content) : null,
|
|
2168
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
2169
|
+
children: (data.children || []).map(node => fromSerializedNode(node)),
|
|
2170
|
+
conditions: (data.conditions || []).map(node => fromSerializedNode(node)),
|
|
2171
|
+
else_clause: data.else_clause ? fromSerializedNode(data.else_clause) : null,
|
|
2172
|
+
end_node: data.end_node ? fromSerializedNode(data.end_node) : null,
|
|
2173
|
+
});
|
|
2174
|
+
}
|
|
2175
|
+
constructor(props) {
|
|
2176
|
+
super(props.type, props.location, props.errors);
|
|
2177
|
+
this.tag_opening = props.tag_opening;
|
|
2178
|
+
this.content = props.content;
|
|
2179
|
+
this.tag_closing = props.tag_closing;
|
|
2180
|
+
this.children = props.children;
|
|
2181
|
+
this.conditions = props.conditions;
|
|
2182
|
+
this.else_clause = props.else_clause;
|
|
2183
|
+
this.end_node = props.end_node;
|
|
2184
|
+
}
|
|
2185
|
+
accept(visitor) {
|
|
2186
|
+
visitor.visitERBCaseMatchNode(this);
|
|
2187
|
+
}
|
|
2188
|
+
childNodes() {
|
|
2189
|
+
return [
|
|
2190
|
+
...this.children,
|
|
2191
|
+
...this.conditions,
|
|
2192
|
+
this.else_clause,
|
|
2193
|
+
this.end_node,
|
|
2194
|
+
];
|
|
2195
|
+
}
|
|
2196
|
+
compactChildNodes() {
|
|
2197
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
2198
|
+
}
|
|
2199
|
+
recursiveErrors() {
|
|
2200
|
+
return [
|
|
2201
|
+
...this.errors,
|
|
2202
|
+
...this.children.map(node => node.recursiveErrors()),
|
|
2203
|
+
...this.conditions.map(node => node.recursiveErrors()),
|
|
2204
|
+
this.else_clause ? this.else_clause.recursiveErrors() : [],
|
|
2205
|
+
this.end_node ? this.end_node.recursiveErrors() : [],
|
|
2206
|
+
].flat();
|
|
2207
|
+
}
|
|
2208
|
+
toJSON() {
|
|
2209
|
+
return {
|
|
2210
|
+
...super.toJSON(),
|
|
2211
|
+
type: "AST_ERB_CASE_MATCH_NODE",
|
|
2212
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
2213
|
+
content: this.content ? this.content.toJSON() : null,
|
|
2214
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
2215
|
+
children: this.children.map(node => node.toJSON()),
|
|
2216
|
+
conditions: this.conditions.map(node => node.toJSON()),
|
|
2217
|
+
else_clause: this.else_clause ? this.else_clause.toJSON() : null,
|
|
2218
|
+
end_node: this.end_node ? this.end_node.toJSON() : null,
|
|
2219
|
+
};
|
|
2220
|
+
}
|
|
2221
|
+
treeInspect() {
|
|
2222
|
+
let output = "";
|
|
2223
|
+
output += `@ ERBCaseMatchNode ${this.location.treeInspectWithLabel()}\n`;
|
|
2224
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
2225
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
2226
|
+
output += `├── content: ${this.content ? this.content.treeInspect() : "∅"}\n`;
|
|
2227
|
+
output += `├── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
2228
|
+
output += `├── children: ${this.inspectArray(this.children, "│ ")}`;
|
|
2229
|
+
output += `├── conditions: ${this.inspectArray(this.conditions, "│ ")}`;
|
|
2230
|
+
output += `├── else_clause: ${this.inspectNode(this.else_clause, "│ ")}`;
|
|
2231
|
+
output += `└── end_node: ${this.inspectNode(this.end_node, " ")}`;
|
|
2232
|
+
// output += "\n";
|
|
2233
|
+
return output;
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2037
2236
|
class ERBWhileNode extends Node {
|
|
2038
2237
|
tag_opening;
|
|
2039
2238
|
content;
|
|
@@ -2060,11 +2259,17 @@
|
|
|
2060
2259
|
this.statements = props.statements;
|
|
2061
2260
|
this.end_node = props.end_node;
|
|
2062
2261
|
}
|
|
2262
|
+
accept(visitor) {
|
|
2263
|
+
visitor.visitERBWhileNode(this);
|
|
2264
|
+
}
|
|
2063
2265
|
childNodes() {
|
|
2064
2266
|
return [
|
|
2065
2267
|
...this.statements,
|
|
2066
2268
|
this.end_node,
|
|
2067
|
-
]
|
|
2269
|
+
];
|
|
2270
|
+
}
|
|
2271
|
+
compactChildNodes() {
|
|
2272
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
2068
2273
|
}
|
|
2069
2274
|
recursiveErrors() {
|
|
2070
2275
|
return [
|
|
@@ -2123,11 +2328,17 @@
|
|
|
2123
2328
|
this.statements = props.statements;
|
|
2124
2329
|
this.end_node = props.end_node;
|
|
2125
2330
|
}
|
|
2331
|
+
accept(visitor) {
|
|
2332
|
+
visitor.visitERBUntilNode(this);
|
|
2333
|
+
}
|
|
2126
2334
|
childNodes() {
|
|
2127
2335
|
return [
|
|
2128
2336
|
...this.statements,
|
|
2129
2337
|
this.end_node,
|
|
2130
|
-
]
|
|
2338
|
+
];
|
|
2339
|
+
}
|
|
2340
|
+
compactChildNodes() {
|
|
2341
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
2131
2342
|
}
|
|
2132
2343
|
recursiveErrors() {
|
|
2133
2344
|
return [
|
|
@@ -2186,11 +2397,17 @@
|
|
|
2186
2397
|
this.statements = props.statements;
|
|
2187
2398
|
this.end_node = props.end_node;
|
|
2188
2399
|
}
|
|
2400
|
+
accept(visitor) {
|
|
2401
|
+
visitor.visitERBForNode(this);
|
|
2402
|
+
}
|
|
2189
2403
|
childNodes() {
|
|
2190
2404
|
return [
|
|
2191
2405
|
...this.statements,
|
|
2192
2406
|
this.end_node,
|
|
2193
|
-
]
|
|
2407
|
+
];
|
|
2408
|
+
}
|
|
2409
|
+
compactChildNodes() {
|
|
2410
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
2194
2411
|
}
|
|
2195
2412
|
recursiveErrors() {
|
|
2196
2413
|
return [
|
|
@@ -2249,11 +2466,17 @@
|
|
|
2249
2466
|
this.statements = props.statements;
|
|
2250
2467
|
this.subsequent = props.subsequent;
|
|
2251
2468
|
}
|
|
2469
|
+
accept(visitor) {
|
|
2470
|
+
visitor.visitERBRescueNode(this);
|
|
2471
|
+
}
|
|
2252
2472
|
childNodes() {
|
|
2253
2473
|
return [
|
|
2254
2474
|
...this.statements,
|
|
2255
2475
|
this.subsequent,
|
|
2256
|
-
]
|
|
2476
|
+
];
|
|
2477
|
+
}
|
|
2478
|
+
compactChildNodes() {
|
|
2479
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
2257
2480
|
}
|
|
2258
2481
|
recursiveErrors() {
|
|
2259
2482
|
return [
|
|
@@ -2309,10 +2532,16 @@
|
|
|
2309
2532
|
this.tag_closing = props.tag_closing;
|
|
2310
2533
|
this.statements = props.statements;
|
|
2311
2534
|
}
|
|
2535
|
+
accept(visitor) {
|
|
2536
|
+
visitor.visitERBEnsureNode(this);
|
|
2537
|
+
}
|
|
2312
2538
|
childNodes() {
|
|
2313
2539
|
return [
|
|
2314
2540
|
...this.statements,
|
|
2315
|
-
]
|
|
2541
|
+
];
|
|
2542
|
+
}
|
|
2543
|
+
compactChildNodes() {
|
|
2544
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
2316
2545
|
}
|
|
2317
2546
|
recursiveErrors() {
|
|
2318
2547
|
return [
|
|
@@ -2377,6 +2606,9 @@
|
|
|
2377
2606
|
this.ensure_clause = props.ensure_clause;
|
|
2378
2607
|
this.end_node = props.end_node;
|
|
2379
2608
|
}
|
|
2609
|
+
accept(visitor) {
|
|
2610
|
+
visitor.visitERBBeginNode(this);
|
|
2611
|
+
}
|
|
2380
2612
|
childNodes() {
|
|
2381
2613
|
return [
|
|
2382
2614
|
...this.statements,
|
|
@@ -2384,7 +2616,10 @@
|
|
|
2384
2616
|
this.else_clause,
|
|
2385
2617
|
this.ensure_clause,
|
|
2386
2618
|
this.end_node,
|
|
2387
|
-
]
|
|
2619
|
+
];
|
|
2620
|
+
}
|
|
2621
|
+
compactChildNodes() {
|
|
2622
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
2388
2623
|
}
|
|
2389
2624
|
recursiveErrors() {
|
|
2390
2625
|
return [
|
|
@@ -2455,12 +2690,18 @@
|
|
|
2455
2690
|
this.else_clause = props.else_clause;
|
|
2456
2691
|
this.end_node = props.end_node;
|
|
2457
2692
|
}
|
|
2693
|
+
accept(visitor) {
|
|
2694
|
+
visitor.visitERBUnlessNode(this);
|
|
2695
|
+
}
|
|
2458
2696
|
childNodes() {
|
|
2459
2697
|
return [
|
|
2460
2698
|
...this.statements,
|
|
2461
2699
|
this.else_clause,
|
|
2462
2700
|
this.end_node,
|
|
2463
|
-
]
|
|
2701
|
+
];
|
|
2702
|
+
}
|
|
2703
|
+
compactChildNodes() {
|
|
2704
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
2464
2705
|
}
|
|
2465
2706
|
recursiveErrors() {
|
|
2466
2707
|
return [
|
|
@@ -2496,6 +2737,122 @@
|
|
|
2496
2737
|
return output;
|
|
2497
2738
|
}
|
|
2498
2739
|
}
|
|
2740
|
+
class ERBYieldNode extends Node {
|
|
2741
|
+
tag_opening;
|
|
2742
|
+
content;
|
|
2743
|
+
tag_closing;
|
|
2744
|
+
static from(data) {
|
|
2745
|
+
return new ERBYieldNode({
|
|
2746
|
+
type: data.type,
|
|
2747
|
+
location: Location.from(data.location),
|
|
2748
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
2749
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
2750
|
+
content: data.content ? Token.from(data.content) : null,
|
|
2751
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
2752
|
+
});
|
|
2753
|
+
}
|
|
2754
|
+
constructor(props) {
|
|
2755
|
+
super(props.type, props.location, props.errors);
|
|
2756
|
+
this.tag_opening = props.tag_opening;
|
|
2757
|
+
this.content = props.content;
|
|
2758
|
+
this.tag_closing = props.tag_closing;
|
|
2759
|
+
}
|
|
2760
|
+
accept(visitor) {
|
|
2761
|
+
visitor.visitERBYieldNode(this);
|
|
2762
|
+
}
|
|
2763
|
+
childNodes() {
|
|
2764
|
+
return [];
|
|
2765
|
+
}
|
|
2766
|
+
compactChildNodes() {
|
|
2767
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
2768
|
+
}
|
|
2769
|
+
recursiveErrors() {
|
|
2770
|
+
return [
|
|
2771
|
+
...this.errors,
|
|
2772
|
+
].flat();
|
|
2773
|
+
}
|
|
2774
|
+
toJSON() {
|
|
2775
|
+
return {
|
|
2776
|
+
...super.toJSON(),
|
|
2777
|
+
type: "AST_ERB_YIELD_NODE",
|
|
2778
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
2779
|
+
content: this.content ? this.content.toJSON() : null,
|
|
2780
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
2781
|
+
};
|
|
2782
|
+
}
|
|
2783
|
+
treeInspect() {
|
|
2784
|
+
let output = "";
|
|
2785
|
+
output += `@ ERBYieldNode ${this.location.treeInspectWithLabel()}\n`;
|
|
2786
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
2787
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
2788
|
+
output += `├── content: ${this.content ? this.content.treeInspect() : "∅"}\n`;
|
|
2789
|
+
output += `└── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
2790
|
+
// output += "\n";
|
|
2791
|
+
return output;
|
|
2792
|
+
}
|
|
2793
|
+
}
|
|
2794
|
+
class ERBInNode extends Node {
|
|
2795
|
+
tag_opening;
|
|
2796
|
+
content;
|
|
2797
|
+
tag_closing;
|
|
2798
|
+
statements;
|
|
2799
|
+
static from(data) {
|
|
2800
|
+
return new ERBInNode({
|
|
2801
|
+
type: data.type,
|
|
2802
|
+
location: Location.from(data.location),
|
|
2803
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
2804
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
2805
|
+
content: data.content ? Token.from(data.content) : null,
|
|
2806
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
2807
|
+
statements: (data.statements || []).map(node => fromSerializedNode(node)),
|
|
2808
|
+
});
|
|
2809
|
+
}
|
|
2810
|
+
constructor(props) {
|
|
2811
|
+
super(props.type, props.location, props.errors);
|
|
2812
|
+
this.tag_opening = props.tag_opening;
|
|
2813
|
+
this.content = props.content;
|
|
2814
|
+
this.tag_closing = props.tag_closing;
|
|
2815
|
+
this.statements = props.statements;
|
|
2816
|
+
}
|
|
2817
|
+
accept(visitor) {
|
|
2818
|
+
visitor.visitERBInNode(this);
|
|
2819
|
+
}
|
|
2820
|
+
childNodes() {
|
|
2821
|
+
return [
|
|
2822
|
+
...this.statements,
|
|
2823
|
+
];
|
|
2824
|
+
}
|
|
2825
|
+
compactChildNodes() {
|
|
2826
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
2827
|
+
}
|
|
2828
|
+
recursiveErrors() {
|
|
2829
|
+
return [
|
|
2830
|
+
...this.errors,
|
|
2831
|
+
...this.statements.map(node => node.recursiveErrors()),
|
|
2832
|
+
].flat();
|
|
2833
|
+
}
|
|
2834
|
+
toJSON() {
|
|
2835
|
+
return {
|
|
2836
|
+
...super.toJSON(),
|
|
2837
|
+
type: "AST_ERB_IN_NODE",
|
|
2838
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
2839
|
+
content: this.content ? this.content.toJSON() : null,
|
|
2840
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
2841
|
+
statements: this.statements.map(node => node.toJSON()),
|
|
2842
|
+
};
|
|
2843
|
+
}
|
|
2844
|
+
treeInspect() {
|
|
2845
|
+
let output = "";
|
|
2846
|
+
output += `@ ERBInNode ${this.location.treeInspectWithLabel()}\n`;
|
|
2847
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
2848
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
2849
|
+
output += `├── content: ${this.content ? this.content.treeInspect() : "∅"}\n`;
|
|
2850
|
+
output += `├── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
2851
|
+
output += `└── statements: ${this.inspectArray(this.statements, " ")}`;
|
|
2852
|
+
// output += "\n";
|
|
2853
|
+
return output;
|
|
2854
|
+
}
|
|
2855
|
+
}
|
|
2499
2856
|
|
|
2500
2857
|
class HerbWarning {
|
|
2501
2858
|
message;
|
|
@@ -2693,23 +3050,116 @@
|
|
|
2693
3050
|
}
|
|
2694
3051
|
}
|
|
2695
3052
|
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
*/
|
|
3053
|
+
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
3054
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/visitor.ts.erb
|
|
2699
3055
|
class Visitor {
|
|
2700
|
-
/**
|
|
2701
|
-
* Visits a node and performs an action.
|
|
2702
|
-
* @param node - The node to visit.
|
|
2703
|
-
*/
|
|
2704
3056
|
visit(node) {
|
|
2705
|
-
|
|
3057
|
+
if (!node)
|
|
3058
|
+
return;
|
|
3059
|
+
node.accept(this);
|
|
3060
|
+
}
|
|
3061
|
+
visitAll(nodes) {
|
|
3062
|
+
nodes.forEach(node => node?.accept(this));
|
|
3063
|
+
}
|
|
3064
|
+
visitChildNodes(node) {
|
|
3065
|
+
node.compactChildNodes().forEach(node => node.accept(this));
|
|
3066
|
+
}
|
|
3067
|
+
visitDocumentNode(node) {
|
|
3068
|
+
this.visitChildNodes(node);
|
|
3069
|
+
}
|
|
3070
|
+
visitLiteralNode(node) {
|
|
3071
|
+
this.visitChildNodes(node);
|
|
3072
|
+
}
|
|
3073
|
+
visitHTMLOpenTagNode(node) {
|
|
3074
|
+
this.visitChildNodes(node);
|
|
3075
|
+
}
|
|
3076
|
+
visitHTMLCloseTagNode(node) {
|
|
3077
|
+
this.visitChildNodes(node);
|
|
3078
|
+
}
|
|
3079
|
+
visitHTMLSelfCloseTagNode(node) {
|
|
3080
|
+
this.visitChildNodes(node);
|
|
3081
|
+
}
|
|
3082
|
+
visitHTMLElementNode(node) {
|
|
3083
|
+
this.visitChildNodes(node);
|
|
3084
|
+
}
|
|
3085
|
+
visitHTMLAttributeValueNode(node) {
|
|
3086
|
+
this.visitChildNodes(node);
|
|
3087
|
+
}
|
|
3088
|
+
visitHTMLAttributeNameNode(node) {
|
|
3089
|
+
this.visitChildNodes(node);
|
|
3090
|
+
}
|
|
3091
|
+
visitHTMLAttributeNode(node) {
|
|
3092
|
+
this.visitChildNodes(node);
|
|
3093
|
+
}
|
|
3094
|
+
visitHTMLTextNode(node) {
|
|
3095
|
+
this.visitChildNodes(node);
|
|
3096
|
+
}
|
|
3097
|
+
visitHTMLCommentNode(node) {
|
|
3098
|
+
this.visitChildNodes(node);
|
|
3099
|
+
}
|
|
3100
|
+
visitHTMLDoctypeNode(node) {
|
|
3101
|
+
this.visitChildNodes(node);
|
|
3102
|
+
}
|
|
3103
|
+
visitWhitespaceNode(node) {
|
|
3104
|
+
this.visitChildNodes(node);
|
|
3105
|
+
}
|
|
3106
|
+
visitERBContentNode(node) {
|
|
3107
|
+
this.visitChildNodes(node);
|
|
3108
|
+
}
|
|
3109
|
+
visitERBEndNode(node) {
|
|
3110
|
+
this.visitChildNodes(node);
|
|
3111
|
+
}
|
|
3112
|
+
visitERBElseNode(node) {
|
|
3113
|
+
this.visitChildNodes(node);
|
|
3114
|
+
}
|
|
3115
|
+
visitERBIfNode(node) {
|
|
3116
|
+
this.visitChildNodes(node);
|
|
3117
|
+
}
|
|
3118
|
+
visitERBBlockNode(node) {
|
|
3119
|
+
this.visitChildNodes(node);
|
|
3120
|
+
}
|
|
3121
|
+
visitERBWhenNode(node) {
|
|
3122
|
+
this.visitChildNodes(node);
|
|
3123
|
+
}
|
|
3124
|
+
visitERBCaseNode(node) {
|
|
3125
|
+
this.visitChildNodes(node);
|
|
3126
|
+
}
|
|
3127
|
+
visitERBCaseMatchNode(node) {
|
|
3128
|
+
this.visitChildNodes(node);
|
|
3129
|
+
}
|
|
3130
|
+
visitERBWhileNode(node) {
|
|
3131
|
+
this.visitChildNodes(node);
|
|
3132
|
+
}
|
|
3133
|
+
visitERBUntilNode(node) {
|
|
3134
|
+
this.visitChildNodes(node);
|
|
3135
|
+
}
|
|
3136
|
+
visitERBForNode(node) {
|
|
3137
|
+
this.visitChildNodes(node);
|
|
3138
|
+
}
|
|
3139
|
+
visitERBRescueNode(node) {
|
|
3140
|
+
this.visitChildNodes(node);
|
|
3141
|
+
}
|
|
3142
|
+
visitERBEnsureNode(node) {
|
|
3143
|
+
this.visitChildNodes(node);
|
|
3144
|
+
}
|
|
3145
|
+
visitERBBeginNode(node) {
|
|
3146
|
+
this.visitChildNodes(node);
|
|
3147
|
+
}
|
|
3148
|
+
visitERBUnlessNode(node) {
|
|
3149
|
+
this.visitChildNodes(node);
|
|
3150
|
+
}
|
|
3151
|
+
visitERBYieldNode(node) {
|
|
3152
|
+
this.visitChildNodes(node);
|
|
3153
|
+
}
|
|
3154
|
+
visitERBInNode(node) {
|
|
3155
|
+
this.visitChildNodes(node);
|
|
2706
3156
|
}
|
|
2707
3157
|
}
|
|
2708
3158
|
|
|
2709
|
-
exports.ASTNode = ASTNode;
|
|
2710
3159
|
exports.DocumentNode = DocumentNode;
|
|
2711
3160
|
exports.ERBBeginNode = ERBBeginNode;
|
|
2712
3161
|
exports.ERBBlockNode = ERBBlockNode;
|
|
3162
|
+
exports.ERBCaseMatchNode = ERBCaseMatchNode;
|
|
2713
3163
|
exports.ERBCaseNode = ERBCaseNode;
|
|
2714
3164
|
exports.ERBContentNode = ERBContentNode;
|
|
2715
3165
|
exports.ERBElseNode = ERBElseNode;
|
|
@@ -2717,11 +3167,13 @@
|
|
|
2717
3167
|
exports.ERBEnsureNode = ERBEnsureNode;
|
|
2718
3168
|
exports.ERBForNode = ERBForNode;
|
|
2719
3169
|
exports.ERBIfNode = ERBIfNode;
|
|
3170
|
+
exports.ERBInNode = ERBInNode;
|
|
2720
3171
|
exports.ERBRescueNode = ERBRescueNode;
|
|
2721
3172
|
exports.ERBUnlessNode = ERBUnlessNode;
|
|
2722
3173
|
exports.ERBUntilNode = ERBUntilNode;
|
|
2723
3174
|
exports.ERBWhenNode = ERBWhenNode;
|
|
2724
3175
|
exports.ERBWhileNode = ERBWhileNode;
|
|
3176
|
+
exports.ERBYieldNode = ERBYieldNode;
|
|
2725
3177
|
exports.HTMLAttributeNameNode = HTMLAttributeNameNode;
|
|
2726
3178
|
exports.HTMLAttributeNode = HTMLAttributeNode;
|
|
2727
3179
|
exports.HTMLAttributeValueNode = HTMLAttributeValueNode;
|
|
@@ -2738,6 +3190,7 @@
|
|
|
2738
3190
|
exports.Location = Location;
|
|
2739
3191
|
exports.MissingClosingTagError = MissingClosingTagError;
|
|
2740
3192
|
exports.MissingOpeningTagError = MissingOpeningTagError;
|
|
3193
|
+
exports.Node = Node;
|
|
2741
3194
|
exports.ParseResult = ParseResult;
|
|
2742
3195
|
exports.Position = Position;
|
|
2743
3196
|
exports.QuotesMismatchError = QuotesMismatchError;
|