@herb-tools/core 0.1.1 → 0.3.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 +8 -0
- package/dist/herb-core.browser.js +576 -117
- package/dist/herb-core.browser.js.map +1 -1
- package/dist/herb-core.cjs +581 -117
- package/dist/herb-core.cjs.map +1 -1
- package/dist/herb-core.esm.js +576 -117
- package/dist/herb-core.esm.js.map +1 -1
- package/dist/herb-core.umd.js +581 -117
- package/dist/herb-core.umd.js.map +1 -1
- package/dist/types/errors.d.ts +16 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/lex-result.d.ts +13 -8
- package/dist/types/nodes.d.ts +206 -36
- package/dist/types/parse-result.d.ts +4 -4
- package/dist/types/result.d.ts +12 -4
- package/dist/types/visitor.d.ts +34 -9
- package/package.json +2 -11
- package/src/errors.ts +49 -14
- package/src/index.ts +1 -1
- package/src/lex-result.ts +15 -9
- package/src/nodes.ts +713 -95
- package/src/parse-result.ts +7 -5
- package/src/result.ts +14 -6
- package/src/visitor.ts +169 -10
- package/dist/types/ast.d.ts +0 -4
- package/dist/types/error.d.ts +0 -16
- package/dist/types/node.d.ts +0 -27
- package/src/ast.ts +0 -7
- package/src/error.ts +0 -38
- package/src/node.ts +0 -106
package/dist/herb-core.cjs
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
class ASTNode {
|
|
4
|
-
errors;
|
|
5
|
-
constructor() {
|
|
6
|
-
this.errors = [];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
3
|
const expectedFunctions = [
|
|
11
4
|
"parse",
|
|
12
5
|
"lex",
|
|
@@ -171,6 +164,8 @@ class Token {
|
|
|
171
164
|
}
|
|
172
165
|
}
|
|
173
166
|
|
|
167
|
+
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
168
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/errors.ts.erb
|
|
174
169
|
class HerbError {
|
|
175
170
|
type;
|
|
176
171
|
message;
|
|
@@ -194,24 +189,6 @@ class HerbError {
|
|
|
194
189
|
return this.treeInspect(0);
|
|
195
190
|
}
|
|
196
191
|
}
|
|
197
|
-
|
|
198
|
-
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
199
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/errors.ts.erb
|
|
200
|
-
function fromSerializedError(error) {
|
|
201
|
-
switch (error.type) {
|
|
202
|
-
case "UNEXPECTED_ERROR": return UnexpectedError.from(error);
|
|
203
|
-
case "UNEXPECTED_TOKEN_ERROR": return UnexpectedTokenError.from(error);
|
|
204
|
-
case "MISSING_OPENING_TAG_ERROR": return MissingOpeningTagError.from(error);
|
|
205
|
-
case "MISSING_CLOSING_TAG_ERROR": return MissingClosingTagError.from(error);
|
|
206
|
-
case "TAG_NAMES_MISMATCH_ERROR": return TagNamesMismatchError.from(error);
|
|
207
|
-
case "QUOTES_MISMATCH_ERROR": return QuotesMismatchError.from(error);
|
|
208
|
-
case "VOID_ELEMENT_CLOSING_TAG_ERROR": return VoidElementClosingTagError.from(error);
|
|
209
|
-
case "UNCLOSED_ELEMENT_ERROR": return UnclosedElementError.from(error);
|
|
210
|
-
case "RUBY_PARSE_ERROR": return RubyParseError.from(error);
|
|
211
|
-
default:
|
|
212
|
-
throw new Error(`Unknown node type: ${error.type}`);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
192
|
class UnexpectedError extends HerbError {
|
|
216
193
|
description;
|
|
217
194
|
expected;
|
|
@@ -734,9 +711,24 @@ class RubyParseError extends HerbError {
|
|
|
734
711
|
return output;
|
|
735
712
|
}
|
|
736
713
|
}
|
|
714
|
+
function fromSerializedError(error) {
|
|
715
|
+
switch (error.type) {
|
|
716
|
+
case "UNEXPECTED_ERROR": return UnexpectedError.from(error);
|
|
717
|
+
case "UNEXPECTED_TOKEN_ERROR": return UnexpectedTokenError.from(error);
|
|
718
|
+
case "MISSING_OPENING_TAG_ERROR": return MissingOpeningTagError.from(error);
|
|
719
|
+
case "MISSING_CLOSING_TAG_ERROR": return MissingClosingTagError.from(error);
|
|
720
|
+
case "TAG_NAMES_MISMATCH_ERROR": return TagNamesMismatchError.from(error);
|
|
721
|
+
case "QUOTES_MISMATCH_ERROR": return QuotesMismatchError.from(error);
|
|
722
|
+
case "VOID_ELEMENT_CLOSING_TAG_ERROR": return VoidElementClosingTagError.from(error);
|
|
723
|
+
case "UNCLOSED_ELEMENT_ERROR": return UnclosedElementError.from(error);
|
|
724
|
+
case "RUBY_PARSE_ERROR": return RubyParseError.from(error);
|
|
725
|
+
default:
|
|
726
|
+
throw new Error(`Unknown node type: ${error.type}`);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
737
729
|
|
|
738
730
|
var name = "@herb-tools/core";
|
|
739
|
-
var version = "0.
|
|
731
|
+
var version = "0.3.0";
|
|
740
732
|
var packageJSON = {
|
|
741
733
|
name: name,
|
|
742
734
|
version: version};
|
|
@@ -765,11 +757,19 @@ class Result {
|
|
|
765
757
|
this.warnings = warnings || [];
|
|
766
758
|
this.errors = errors || [];
|
|
767
759
|
}
|
|
768
|
-
|
|
769
|
-
|
|
760
|
+
/**
|
|
761
|
+
* Determines if the parsing was successful.
|
|
762
|
+
* @returns `true` if there are no errors, otherwise `false`.
|
|
763
|
+
*/
|
|
764
|
+
get successful() {
|
|
765
|
+
return this.errors.length === 0;
|
|
770
766
|
}
|
|
771
|
-
|
|
772
|
-
|
|
767
|
+
/**
|
|
768
|
+
* Determines if the parsing failed.
|
|
769
|
+
* @returns `true` if there are errors, otherwise `false`.
|
|
770
|
+
*/
|
|
771
|
+
get failed() {
|
|
772
|
+
return this.errors.length > 0;
|
|
773
773
|
}
|
|
774
774
|
}
|
|
775
775
|
|
|
@@ -810,6 +810,18 @@ class TokenList {
|
|
|
810
810
|
}
|
|
811
811
|
}
|
|
812
812
|
|
|
813
|
+
class HerbWarning {
|
|
814
|
+
message;
|
|
815
|
+
location;
|
|
816
|
+
static from(warning) {
|
|
817
|
+
return new HerbWarning(warning.message, Location.from(warning.location));
|
|
818
|
+
}
|
|
819
|
+
constructor(message, location) {
|
|
820
|
+
this.message = message;
|
|
821
|
+
this.location = location;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
813
825
|
/**
|
|
814
826
|
* Represents the result of a lexical analysis, extending the base `Result` class.
|
|
815
827
|
* It contains the token list, source code, warnings, and errors.
|
|
@@ -823,7 +835,7 @@ class LexResult extends Result {
|
|
|
823
835
|
* @returns A new `LexResult` instance.
|
|
824
836
|
*/
|
|
825
837
|
static from(result) {
|
|
826
|
-
return new LexResult(TokenList.from(result.tokens || []), result.source, result.warnings, result.errors);
|
|
838
|
+
return new LexResult(TokenList.from(result.tokens || []), result.source, result.warnings.map((warning) => HerbWarning.from(warning)), result.errors.map((error) => HerbError.from(error)));
|
|
827
839
|
}
|
|
828
840
|
/**
|
|
829
841
|
* Constructs a new `LexResult`.
|
|
@@ -840,14 +852,14 @@ class LexResult extends Result {
|
|
|
840
852
|
* Determines if the lexing was successful.
|
|
841
853
|
* @returns `true` if there are no errors, otherwise `false`.
|
|
842
854
|
*/
|
|
843
|
-
|
|
855
|
+
get successful() {
|
|
844
856
|
return this.errors.length === 0;
|
|
845
857
|
}
|
|
846
858
|
/**
|
|
847
859
|
* Determines if the lexing failed.
|
|
848
860
|
* @returns `true` if there are errors, otherwise `false`.
|
|
849
861
|
*/
|
|
850
|
-
failed() {
|
|
862
|
+
get failed() {
|
|
851
863
|
return this.errors.length > 0;
|
|
852
864
|
}
|
|
853
865
|
/**
|
|
@@ -864,6 +876,8 @@ class LexResult extends Result {
|
|
|
864
876
|
}
|
|
865
877
|
}
|
|
866
878
|
|
|
879
|
+
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
880
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/nodes.ts.erb
|
|
867
881
|
class Node {
|
|
868
882
|
type;
|
|
869
883
|
location;
|
|
@@ -886,6 +900,9 @@ class Node {
|
|
|
886
900
|
inspect() {
|
|
887
901
|
return this.treeInspect(0);
|
|
888
902
|
}
|
|
903
|
+
get isSingleLine() {
|
|
904
|
+
return this.location.start.line === this.location.end.line;
|
|
905
|
+
}
|
|
889
906
|
inspectArray(array, prefix) {
|
|
890
907
|
if (!array)
|
|
891
908
|
return "∅\n";
|
|
@@ -922,42 +939,6 @@ class Node {
|
|
|
922
939
|
return output;
|
|
923
940
|
}
|
|
924
941
|
}
|
|
925
|
-
|
|
926
|
-
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
927
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/nodes.ts.erb
|
|
928
|
-
function fromSerializedNode(node) {
|
|
929
|
-
switch (node.type) {
|
|
930
|
-
case "AST_DOCUMENT_NODE": return DocumentNode.from(node);
|
|
931
|
-
case "AST_LITERAL_NODE": return LiteralNode.from(node);
|
|
932
|
-
case "AST_HTML_OPEN_TAG_NODE": return HTMLOpenTagNode.from(node);
|
|
933
|
-
case "AST_HTML_CLOSE_TAG_NODE": return HTMLCloseTagNode.from(node);
|
|
934
|
-
case "AST_HTML_SELF_CLOSE_TAG_NODE": return HTMLSelfCloseTagNode.from(node);
|
|
935
|
-
case "AST_HTML_ELEMENT_NODE": return HTMLElementNode.from(node);
|
|
936
|
-
case "AST_HTML_ATTRIBUTE_VALUE_NODE": return HTMLAttributeValueNode.from(node);
|
|
937
|
-
case "AST_HTML_ATTRIBUTE_NAME_NODE": return HTMLAttributeNameNode.from(node);
|
|
938
|
-
case "AST_HTML_ATTRIBUTE_NODE": return HTMLAttributeNode.from(node);
|
|
939
|
-
case "AST_HTML_TEXT_NODE": return HTMLTextNode.from(node);
|
|
940
|
-
case "AST_HTML_COMMENT_NODE": return HTMLCommentNode.from(node);
|
|
941
|
-
case "AST_HTML_DOCTYPE_NODE": return HTMLDoctypeNode.from(node);
|
|
942
|
-
case "AST_WHITESPACE_NODE": return WhitespaceNode.from(node);
|
|
943
|
-
case "AST_ERB_CONTENT_NODE": return ERBContentNode.from(node);
|
|
944
|
-
case "AST_ERB_END_NODE": return ERBEndNode.from(node);
|
|
945
|
-
case "AST_ERB_ELSE_NODE": return ERBElseNode.from(node);
|
|
946
|
-
case "AST_ERB_IF_NODE": return ERBIfNode.from(node);
|
|
947
|
-
case "AST_ERB_BLOCK_NODE": return ERBBlockNode.from(node);
|
|
948
|
-
case "AST_ERB_WHEN_NODE": return ERBWhenNode.from(node);
|
|
949
|
-
case "AST_ERB_CASE_NODE": return ERBCaseNode.from(node);
|
|
950
|
-
case "AST_ERB_WHILE_NODE": return ERBWhileNode.from(node);
|
|
951
|
-
case "AST_ERB_UNTIL_NODE": return ERBUntilNode.from(node);
|
|
952
|
-
case "AST_ERB_FOR_NODE": return ERBForNode.from(node);
|
|
953
|
-
case "AST_ERB_RESCUE_NODE": return ERBRescueNode.from(node);
|
|
954
|
-
case "AST_ERB_ENSURE_NODE": return ERBEnsureNode.from(node);
|
|
955
|
-
case "AST_ERB_BEGIN_NODE": return ERBBeginNode.from(node);
|
|
956
|
-
case "AST_ERB_UNLESS_NODE": return ERBUnlessNode.from(node);
|
|
957
|
-
default:
|
|
958
|
-
throw new Error(`Unknown node type: ${node.type}`);
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
942
|
class DocumentNode extends Node {
|
|
962
943
|
children;
|
|
963
944
|
static from(data) {
|
|
@@ -972,10 +953,16 @@ class DocumentNode extends Node {
|
|
|
972
953
|
super(props.type, props.location, props.errors);
|
|
973
954
|
this.children = props.children;
|
|
974
955
|
}
|
|
956
|
+
accept(visitor) {
|
|
957
|
+
visitor.visitDocumentNode(this);
|
|
958
|
+
}
|
|
975
959
|
childNodes() {
|
|
976
960
|
return [
|
|
977
961
|
...this.children,
|
|
978
|
-
]
|
|
962
|
+
];
|
|
963
|
+
}
|
|
964
|
+
compactChildNodes() {
|
|
965
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
979
966
|
}
|
|
980
967
|
recursiveErrors() {
|
|
981
968
|
return [
|
|
@@ -1013,8 +1000,14 @@ class LiteralNode extends Node {
|
|
|
1013
1000
|
super(props.type, props.location, props.errors);
|
|
1014
1001
|
this.content = convertToUTF8(props.content);
|
|
1015
1002
|
}
|
|
1003
|
+
accept(visitor) {
|
|
1004
|
+
visitor.visitLiteralNode(this);
|
|
1005
|
+
}
|
|
1016
1006
|
childNodes() {
|
|
1017
|
-
return []
|
|
1007
|
+
return [];
|
|
1008
|
+
}
|
|
1009
|
+
compactChildNodes() {
|
|
1010
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1018
1011
|
}
|
|
1019
1012
|
recursiveErrors() {
|
|
1020
1013
|
return [
|
|
@@ -1063,10 +1056,16 @@ class HTMLOpenTagNode extends Node {
|
|
|
1063
1056
|
this.children = props.children;
|
|
1064
1057
|
this.is_void = props.is_void;
|
|
1065
1058
|
}
|
|
1059
|
+
accept(visitor) {
|
|
1060
|
+
visitor.visitHTMLOpenTagNode(this);
|
|
1061
|
+
}
|
|
1066
1062
|
childNodes() {
|
|
1067
1063
|
return [
|
|
1068
1064
|
...this.children,
|
|
1069
|
-
]
|
|
1065
|
+
];
|
|
1066
|
+
}
|
|
1067
|
+
compactChildNodes() {
|
|
1068
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1070
1069
|
}
|
|
1071
1070
|
recursiveErrors() {
|
|
1072
1071
|
return [
|
|
@@ -1118,8 +1117,14 @@ class HTMLCloseTagNode extends Node {
|
|
|
1118
1117
|
this.tag_name = props.tag_name;
|
|
1119
1118
|
this.tag_closing = props.tag_closing;
|
|
1120
1119
|
}
|
|
1120
|
+
accept(visitor) {
|
|
1121
|
+
visitor.visitHTMLCloseTagNode(this);
|
|
1122
|
+
}
|
|
1121
1123
|
childNodes() {
|
|
1122
|
-
return []
|
|
1124
|
+
return [];
|
|
1125
|
+
}
|
|
1126
|
+
compactChildNodes() {
|
|
1127
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1123
1128
|
}
|
|
1124
1129
|
recursiveErrors() {
|
|
1125
1130
|
return [
|
|
@@ -1172,10 +1177,16 @@ class HTMLSelfCloseTagNode extends Node {
|
|
|
1172
1177
|
this.tag_closing = props.tag_closing;
|
|
1173
1178
|
this.is_void = props.is_void;
|
|
1174
1179
|
}
|
|
1180
|
+
accept(visitor) {
|
|
1181
|
+
visitor.visitHTMLSelfCloseTagNode(this);
|
|
1182
|
+
}
|
|
1175
1183
|
childNodes() {
|
|
1176
1184
|
return [
|
|
1177
1185
|
...this.attributes,
|
|
1178
|
-
]
|
|
1186
|
+
];
|
|
1187
|
+
}
|
|
1188
|
+
compactChildNodes() {
|
|
1189
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1179
1190
|
}
|
|
1180
1191
|
recursiveErrors() {
|
|
1181
1192
|
return [
|
|
@@ -1233,12 +1244,18 @@ class HTMLElementNode extends Node {
|
|
|
1233
1244
|
this.close_tag = props.close_tag;
|
|
1234
1245
|
this.is_void = props.is_void;
|
|
1235
1246
|
}
|
|
1247
|
+
accept(visitor) {
|
|
1248
|
+
visitor.visitHTMLElementNode(this);
|
|
1249
|
+
}
|
|
1236
1250
|
childNodes() {
|
|
1237
1251
|
return [
|
|
1238
1252
|
this.open_tag,
|
|
1239
1253
|
...this.body,
|
|
1240
1254
|
this.close_tag,
|
|
1241
|
-
]
|
|
1255
|
+
];
|
|
1256
|
+
}
|
|
1257
|
+
compactChildNodes() {
|
|
1258
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1242
1259
|
}
|
|
1243
1260
|
recursiveErrors() {
|
|
1244
1261
|
return [
|
|
@@ -1295,10 +1312,16 @@ class HTMLAttributeValueNode extends Node {
|
|
|
1295
1312
|
this.close_quote = props.close_quote;
|
|
1296
1313
|
this.quoted = props.quoted;
|
|
1297
1314
|
}
|
|
1315
|
+
accept(visitor) {
|
|
1316
|
+
visitor.visitHTMLAttributeValueNode(this);
|
|
1317
|
+
}
|
|
1298
1318
|
childNodes() {
|
|
1299
1319
|
return [
|
|
1300
1320
|
...this.children,
|
|
1301
|
-
]
|
|
1321
|
+
];
|
|
1322
|
+
}
|
|
1323
|
+
compactChildNodes() {
|
|
1324
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1302
1325
|
}
|
|
1303
1326
|
recursiveErrors() {
|
|
1304
1327
|
return [
|
|
@@ -1342,8 +1365,14 @@ class HTMLAttributeNameNode extends Node {
|
|
|
1342
1365
|
super(props.type, props.location, props.errors);
|
|
1343
1366
|
this.name = props.name;
|
|
1344
1367
|
}
|
|
1368
|
+
accept(visitor) {
|
|
1369
|
+
visitor.visitHTMLAttributeNameNode(this);
|
|
1370
|
+
}
|
|
1345
1371
|
childNodes() {
|
|
1346
|
-
return []
|
|
1372
|
+
return [];
|
|
1373
|
+
}
|
|
1374
|
+
compactChildNodes() {
|
|
1375
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1347
1376
|
}
|
|
1348
1377
|
recursiveErrors() {
|
|
1349
1378
|
return [
|
|
@@ -1386,11 +1415,17 @@ class HTMLAttributeNode extends Node {
|
|
|
1386
1415
|
this.equals = props.equals;
|
|
1387
1416
|
this.value = props.value;
|
|
1388
1417
|
}
|
|
1418
|
+
accept(visitor) {
|
|
1419
|
+
visitor.visitHTMLAttributeNode(this);
|
|
1420
|
+
}
|
|
1389
1421
|
childNodes() {
|
|
1390
1422
|
return [
|
|
1391
1423
|
this.name,
|
|
1392
1424
|
this.value,
|
|
1393
|
-
]
|
|
1425
|
+
];
|
|
1426
|
+
}
|
|
1427
|
+
compactChildNodes() {
|
|
1428
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1394
1429
|
}
|
|
1395
1430
|
recursiveErrors() {
|
|
1396
1431
|
return [
|
|
@@ -1433,8 +1468,14 @@ class HTMLTextNode extends Node {
|
|
|
1433
1468
|
super(props.type, props.location, props.errors);
|
|
1434
1469
|
this.content = convertToUTF8(props.content);
|
|
1435
1470
|
}
|
|
1471
|
+
accept(visitor) {
|
|
1472
|
+
visitor.visitHTMLTextNode(this);
|
|
1473
|
+
}
|
|
1436
1474
|
childNodes() {
|
|
1437
|
-
return []
|
|
1475
|
+
return [];
|
|
1476
|
+
}
|
|
1477
|
+
compactChildNodes() {
|
|
1478
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1438
1479
|
}
|
|
1439
1480
|
recursiveErrors() {
|
|
1440
1481
|
return [
|
|
@@ -1477,10 +1518,16 @@ class HTMLCommentNode extends Node {
|
|
|
1477
1518
|
this.children = props.children;
|
|
1478
1519
|
this.comment_end = props.comment_end;
|
|
1479
1520
|
}
|
|
1521
|
+
accept(visitor) {
|
|
1522
|
+
visitor.visitHTMLCommentNode(this);
|
|
1523
|
+
}
|
|
1480
1524
|
childNodes() {
|
|
1481
1525
|
return [
|
|
1482
1526
|
...this.children,
|
|
1483
|
-
]
|
|
1527
|
+
];
|
|
1528
|
+
}
|
|
1529
|
+
compactChildNodes() {
|
|
1530
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1484
1531
|
}
|
|
1485
1532
|
recursiveErrors() {
|
|
1486
1533
|
return [
|
|
@@ -1528,10 +1575,16 @@ class HTMLDoctypeNode extends Node {
|
|
|
1528
1575
|
this.children = props.children;
|
|
1529
1576
|
this.tag_closing = props.tag_closing;
|
|
1530
1577
|
}
|
|
1578
|
+
accept(visitor) {
|
|
1579
|
+
visitor.visitHTMLDoctypeNode(this);
|
|
1580
|
+
}
|
|
1531
1581
|
childNodes() {
|
|
1532
1582
|
return [
|
|
1533
1583
|
...this.children,
|
|
1534
|
-
]
|
|
1584
|
+
];
|
|
1585
|
+
}
|
|
1586
|
+
compactChildNodes() {
|
|
1587
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1535
1588
|
}
|
|
1536
1589
|
recursiveErrors() {
|
|
1537
1590
|
return [
|
|
@@ -1573,8 +1626,14 @@ class WhitespaceNode extends Node {
|
|
|
1573
1626
|
super(props.type, props.location, props.errors);
|
|
1574
1627
|
this.value = props.value;
|
|
1575
1628
|
}
|
|
1629
|
+
accept(visitor) {
|
|
1630
|
+
visitor.visitWhitespaceNode(this);
|
|
1631
|
+
}
|
|
1576
1632
|
childNodes() {
|
|
1577
|
-
return []
|
|
1633
|
+
return [];
|
|
1634
|
+
}
|
|
1635
|
+
compactChildNodes() {
|
|
1636
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1578
1637
|
}
|
|
1579
1638
|
recursiveErrors() {
|
|
1580
1639
|
return [
|
|
@@ -1626,8 +1685,14 @@ class ERBContentNode extends Node {
|
|
|
1626
1685
|
this.parsed = props.parsed;
|
|
1627
1686
|
this.valid = props.valid;
|
|
1628
1687
|
}
|
|
1688
|
+
accept(visitor) {
|
|
1689
|
+
visitor.visitERBContentNode(this);
|
|
1690
|
+
}
|
|
1629
1691
|
childNodes() {
|
|
1630
|
-
return []
|
|
1692
|
+
return [];
|
|
1693
|
+
}
|
|
1694
|
+
compactChildNodes() {
|
|
1695
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1631
1696
|
}
|
|
1632
1697
|
recursiveErrors() {
|
|
1633
1698
|
return [
|
|
@@ -1680,8 +1745,14 @@ class ERBEndNode extends Node {
|
|
|
1680
1745
|
this.content = props.content;
|
|
1681
1746
|
this.tag_closing = props.tag_closing;
|
|
1682
1747
|
}
|
|
1748
|
+
accept(visitor) {
|
|
1749
|
+
visitor.visitERBEndNode(this);
|
|
1750
|
+
}
|
|
1683
1751
|
childNodes() {
|
|
1684
|
-
return []
|
|
1752
|
+
return [];
|
|
1753
|
+
}
|
|
1754
|
+
compactChildNodes() {
|
|
1755
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1685
1756
|
}
|
|
1686
1757
|
recursiveErrors() {
|
|
1687
1758
|
return [
|
|
@@ -1731,10 +1802,16 @@ class ERBElseNode extends Node {
|
|
|
1731
1802
|
this.tag_closing = props.tag_closing;
|
|
1732
1803
|
this.statements = props.statements;
|
|
1733
1804
|
}
|
|
1805
|
+
accept(visitor) {
|
|
1806
|
+
visitor.visitERBElseNode(this);
|
|
1807
|
+
}
|
|
1734
1808
|
childNodes() {
|
|
1735
1809
|
return [
|
|
1736
1810
|
...this.statements,
|
|
1737
|
-
]
|
|
1811
|
+
];
|
|
1812
|
+
}
|
|
1813
|
+
compactChildNodes() {
|
|
1814
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1738
1815
|
}
|
|
1739
1816
|
recursiveErrors() {
|
|
1740
1817
|
return [
|
|
@@ -1793,12 +1870,18 @@ class ERBIfNode extends Node {
|
|
|
1793
1870
|
this.subsequent = props.subsequent;
|
|
1794
1871
|
this.end_node = props.end_node;
|
|
1795
1872
|
}
|
|
1873
|
+
accept(visitor) {
|
|
1874
|
+
visitor.visitERBIfNode(this);
|
|
1875
|
+
}
|
|
1796
1876
|
childNodes() {
|
|
1797
1877
|
return [
|
|
1798
1878
|
...this.statements,
|
|
1799
1879
|
this.subsequent,
|
|
1800
1880
|
this.end_node,
|
|
1801
|
-
]
|
|
1881
|
+
];
|
|
1882
|
+
}
|
|
1883
|
+
compactChildNodes() {
|
|
1884
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1802
1885
|
}
|
|
1803
1886
|
recursiveErrors() {
|
|
1804
1887
|
return [
|
|
@@ -1860,11 +1943,17 @@ class ERBBlockNode extends Node {
|
|
|
1860
1943
|
this.body = props.body;
|
|
1861
1944
|
this.end_node = props.end_node;
|
|
1862
1945
|
}
|
|
1946
|
+
accept(visitor) {
|
|
1947
|
+
visitor.visitERBBlockNode(this);
|
|
1948
|
+
}
|
|
1863
1949
|
childNodes() {
|
|
1864
1950
|
return [
|
|
1865
1951
|
...this.body,
|
|
1866
1952
|
this.end_node,
|
|
1867
|
-
]
|
|
1953
|
+
];
|
|
1954
|
+
}
|
|
1955
|
+
compactChildNodes() {
|
|
1956
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1868
1957
|
}
|
|
1869
1958
|
recursiveErrors() {
|
|
1870
1959
|
return [
|
|
@@ -1920,10 +2009,16 @@ class ERBWhenNode extends Node {
|
|
|
1920
2009
|
this.tag_closing = props.tag_closing;
|
|
1921
2010
|
this.statements = props.statements;
|
|
1922
2011
|
}
|
|
2012
|
+
accept(visitor) {
|
|
2013
|
+
visitor.visitERBWhenNode(this);
|
|
2014
|
+
}
|
|
1923
2015
|
childNodes() {
|
|
1924
2016
|
return [
|
|
1925
2017
|
...this.statements,
|
|
1926
|
-
]
|
|
2018
|
+
];
|
|
2019
|
+
}
|
|
2020
|
+
compactChildNodes() {
|
|
2021
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1927
2022
|
}
|
|
1928
2023
|
recursiveErrors() {
|
|
1929
2024
|
return [
|
|
@@ -1985,13 +2080,19 @@ class ERBCaseNode extends Node {
|
|
|
1985
2080
|
this.else_clause = props.else_clause;
|
|
1986
2081
|
this.end_node = props.end_node;
|
|
1987
2082
|
}
|
|
2083
|
+
accept(visitor) {
|
|
2084
|
+
visitor.visitERBCaseNode(this);
|
|
2085
|
+
}
|
|
1988
2086
|
childNodes() {
|
|
1989
2087
|
return [
|
|
1990
2088
|
...this.children,
|
|
1991
2089
|
...this.conditions,
|
|
1992
2090
|
this.else_clause,
|
|
1993
2091
|
this.end_node,
|
|
1994
|
-
]
|
|
2092
|
+
];
|
|
2093
|
+
}
|
|
2094
|
+
compactChildNodes() {
|
|
2095
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
1995
2096
|
}
|
|
1996
2097
|
recursiveErrors() {
|
|
1997
2098
|
return [
|
|
@@ -2030,6 +2131,89 @@ class ERBCaseNode extends Node {
|
|
|
2030
2131
|
return output;
|
|
2031
2132
|
}
|
|
2032
2133
|
}
|
|
2134
|
+
class ERBCaseMatchNode extends Node {
|
|
2135
|
+
tag_opening;
|
|
2136
|
+
content;
|
|
2137
|
+
tag_closing;
|
|
2138
|
+
children;
|
|
2139
|
+
conditions;
|
|
2140
|
+
else_clause;
|
|
2141
|
+
end_node;
|
|
2142
|
+
static from(data) {
|
|
2143
|
+
return new ERBCaseMatchNode({
|
|
2144
|
+
type: data.type,
|
|
2145
|
+
location: Location.from(data.location),
|
|
2146
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
2147
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
2148
|
+
content: data.content ? Token.from(data.content) : null,
|
|
2149
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
2150
|
+
children: (data.children || []).map(node => fromSerializedNode(node)),
|
|
2151
|
+
conditions: (data.conditions || []).map(node => fromSerializedNode(node)),
|
|
2152
|
+
else_clause: data.else_clause ? fromSerializedNode(data.else_clause) : null,
|
|
2153
|
+
end_node: data.end_node ? fromSerializedNode(data.end_node) : null,
|
|
2154
|
+
});
|
|
2155
|
+
}
|
|
2156
|
+
constructor(props) {
|
|
2157
|
+
super(props.type, props.location, props.errors);
|
|
2158
|
+
this.tag_opening = props.tag_opening;
|
|
2159
|
+
this.content = props.content;
|
|
2160
|
+
this.tag_closing = props.tag_closing;
|
|
2161
|
+
this.children = props.children;
|
|
2162
|
+
this.conditions = props.conditions;
|
|
2163
|
+
this.else_clause = props.else_clause;
|
|
2164
|
+
this.end_node = props.end_node;
|
|
2165
|
+
}
|
|
2166
|
+
accept(visitor) {
|
|
2167
|
+
visitor.visitERBCaseMatchNode(this);
|
|
2168
|
+
}
|
|
2169
|
+
childNodes() {
|
|
2170
|
+
return [
|
|
2171
|
+
...this.children,
|
|
2172
|
+
...this.conditions,
|
|
2173
|
+
this.else_clause,
|
|
2174
|
+
this.end_node,
|
|
2175
|
+
];
|
|
2176
|
+
}
|
|
2177
|
+
compactChildNodes() {
|
|
2178
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
2179
|
+
}
|
|
2180
|
+
recursiveErrors() {
|
|
2181
|
+
return [
|
|
2182
|
+
...this.errors,
|
|
2183
|
+
...this.children.map(node => node.recursiveErrors()),
|
|
2184
|
+
...this.conditions.map(node => node.recursiveErrors()),
|
|
2185
|
+
this.else_clause ? this.else_clause.recursiveErrors() : [],
|
|
2186
|
+
this.end_node ? this.end_node.recursiveErrors() : [],
|
|
2187
|
+
].flat();
|
|
2188
|
+
}
|
|
2189
|
+
toJSON() {
|
|
2190
|
+
return {
|
|
2191
|
+
...super.toJSON(),
|
|
2192
|
+
type: "AST_ERB_CASE_MATCH_NODE",
|
|
2193
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
2194
|
+
content: this.content ? this.content.toJSON() : null,
|
|
2195
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
2196
|
+
children: this.children.map(node => node.toJSON()),
|
|
2197
|
+
conditions: this.conditions.map(node => node.toJSON()),
|
|
2198
|
+
else_clause: this.else_clause ? this.else_clause.toJSON() : null,
|
|
2199
|
+
end_node: this.end_node ? this.end_node.toJSON() : null,
|
|
2200
|
+
};
|
|
2201
|
+
}
|
|
2202
|
+
treeInspect() {
|
|
2203
|
+
let output = "";
|
|
2204
|
+
output += `@ ERBCaseMatchNode ${this.location.treeInspectWithLabel()}\n`;
|
|
2205
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
2206
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
2207
|
+
output += `├── content: ${this.content ? this.content.treeInspect() : "∅"}\n`;
|
|
2208
|
+
output += `├── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
2209
|
+
output += `├── children: ${this.inspectArray(this.children, "│ ")}`;
|
|
2210
|
+
output += `├── conditions: ${this.inspectArray(this.conditions, "│ ")}`;
|
|
2211
|
+
output += `├── else_clause: ${this.inspectNode(this.else_clause, "│ ")}`;
|
|
2212
|
+
output += `└── end_node: ${this.inspectNode(this.end_node, " ")}`;
|
|
2213
|
+
// output += "\n";
|
|
2214
|
+
return output;
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
2033
2217
|
class ERBWhileNode extends Node {
|
|
2034
2218
|
tag_opening;
|
|
2035
2219
|
content;
|
|
@@ -2056,11 +2240,17 @@ class ERBWhileNode extends Node {
|
|
|
2056
2240
|
this.statements = props.statements;
|
|
2057
2241
|
this.end_node = props.end_node;
|
|
2058
2242
|
}
|
|
2243
|
+
accept(visitor) {
|
|
2244
|
+
visitor.visitERBWhileNode(this);
|
|
2245
|
+
}
|
|
2059
2246
|
childNodes() {
|
|
2060
2247
|
return [
|
|
2061
2248
|
...this.statements,
|
|
2062
2249
|
this.end_node,
|
|
2063
|
-
]
|
|
2250
|
+
];
|
|
2251
|
+
}
|
|
2252
|
+
compactChildNodes() {
|
|
2253
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
2064
2254
|
}
|
|
2065
2255
|
recursiveErrors() {
|
|
2066
2256
|
return [
|
|
@@ -2119,11 +2309,17 @@ class ERBUntilNode extends Node {
|
|
|
2119
2309
|
this.statements = props.statements;
|
|
2120
2310
|
this.end_node = props.end_node;
|
|
2121
2311
|
}
|
|
2312
|
+
accept(visitor) {
|
|
2313
|
+
visitor.visitERBUntilNode(this);
|
|
2314
|
+
}
|
|
2122
2315
|
childNodes() {
|
|
2123
2316
|
return [
|
|
2124
2317
|
...this.statements,
|
|
2125
2318
|
this.end_node,
|
|
2126
|
-
]
|
|
2319
|
+
];
|
|
2320
|
+
}
|
|
2321
|
+
compactChildNodes() {
|
|
2322
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
2127
2323
|
}
|
|
2128
2324
|
recursiveErrors() {
|
|
2129
2325
|
return [
|
|
@@ -2182,11 +2378,17 @@ class ERBForNode extends Node {
|
|
|
2182
2378
|
this.statements = props.statements;
|
|
2183
2379
|
this.end_node = props.end_node;
|
|
2184
2380
|
}
|
|
2381
|
+
accept(visitor) {
|
|
2382
|
+
visitor.visitERBForNode(this);
|
|
2383
|
+
}
|
|
2185
2384
|
childNodes() {
|
|
2186
2385
|
return [
|
|
2187
2386
|
...this.statements,
|
|
2188
2387
|
this.end_node,
|
|
2189
|
-
]
|
|
2388
|
+
];
|
|
2389
|
+
}
|
|
2390
|
+
compactChildNodes() {
|
|
2391
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
2190
2392
|
}
|
|
2191
2393
|
recursiveErrors() {
|
|
2192
2394
|
return [
|
|
@@ -2245,11 +2447,17 @@ class ERBRescueNode extends Node {
|
|
|
2245
2447
|
this.statements = props.statements;
|
|
2246
2448
|
this.subsequent = props.subsequent;
|
|
2247
2449
|
}
|
|
2450
|
+
accept(visitor) {
|
|
2451
|
+
visitor.visitERBRescueNode(this);
|
|
2452
|
+
}
|
|
2248
2453
|
childNodes() {
|
|
2249
2454
|
return [
|
|
2250
2455
|
...this.statements,
|
|
2251
2456
|
this.subsequent,
|
|
2252
|
-
]
|
|
2457
|
+
];
|
|
2458
|
+
}
|
|
2459
|
+
compactChildNodes() {
|
|
2460
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
2253
2461
|
}
|
|
2254
2462
|
recursiveErrors() {
|
|
2255
2463
|
return [
|
|
@@ -2305,10 +2513,16 @@ class ERBEnsureNode extends Node {
|
|
|
2305
2513
|
this.tag_closing = props.tag_closing;
|
|
2306
2514
|
this.statements = props.statements;
|
|
2307
2515
|
}
|
|
2516
|
+
accept(visitor) {
|
|
2517
|
+
visitor.visitERBEnsureNode(this);
|
|
2518
|
+
}
|
|
2308
2519
|
childNodes() {
|
|
2309
2520
|
return [
|
|
2310
2521
|
...this.statements,
|
|
2311
|
-
]
|
|
2522
|
+
];
|
|
2523
|
+
}
|
|
2524
|
+
compactChildNodes() {
|
|
2525
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
2312
2526
|
}
|
|
2313
2527
|
recursiveErrors() {
|
|
2314
2528
|
return [
|
|
@@ -2373,6 +2587,9 @@ class ERBBeginNode extends Node {
|
|
|
2373
2587
|
this.ensure_clause = props.ensure_clause;
|
|
2374
2588
|
this.end_node = props.end_node;
|
|
2375
2589
|
}
|
|
2590
|
+
accept(visitor) {
|
|
2591
|
+
visitor.visitERBBeginNode(this);
|
|
2592
|
+
}
|
|
2376
2593
|
childNodes() {
|
|
2377
2594
|
return [
|
|
2378
2595
|
...this.statements,
|
|
@@ -2380,7 +2597,10 @@ class ERBBeginNode extends Node {
|
|
|
2380
2597
|
this.else_clause,
|
|
2381
2598
|
this.ensure_clause,
|
|
2382
2599
|
this.end_node,
|
|
2383
|
-
]
|
|
2600
|
+
];
|
|
2601
|
+
}
|
|
2602
|
+
compactChildNodes() {
|
|
2603
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
2384
2604
|
}
|
|
2385
2605
|
recursiveErrors() {
|
|
2386
2606
|
return [
|
|
@@ -2451,12 +2671,18 @@ class ERBUnlessNode extends Node {
|
|
|
2451
2671
|
this.else_clause = props.else_clause;
|
|
2452
2672
|
this.end_node = props.end_node;
|
|
2453
2673
|
}
|
|
2674
|
+
accept(visitor) {
|
|
2675
|
+
visitor.visitERBUnlessNode(this);
|
|
2676
|
+
}
|
|
2454
2677
|
childNodes() {
|
|
2455
2678
|
return [
|
|
2456
2679
|
...this.statements,
|
|
2457
2680
|
this.else_clause,
|
|
2458
2681
|
this.end_node,
|
|
2459
|
-
]
|
|
2682
|
+
];
|
|
2683
|
+
}
|
|
2684
|
+
compactChildNodes() {
|
|
2685
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
2460
2686
|
}
|
|
2461
2687
|
recursiveErrors() {
|
|
2462
2688
|
return [
|
|
@@ -2492,16 +2718,156 @@ class ERBUnlessNode extends Node {
|
|
|
2492
2718
|
return output;
|
|
2493
2719
|
}
|
|
2494
2720
|
}
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
static from(
|
|
2500
|
-
return new
|
|
2721
|
+
class ERBYieldNode extends Node {
|
|
2722
|
+
tag_opening;
|
|
2723
|
+
content;
|
|
2724
|
+
tag_closing;
|
|
2725
|
+
static from(data) {
|
|
2726
|
+
return new ERBYieldNode({
|
|
2727
|
+
type: data.type,
|
|
2728
|
+
location: Location.from(data.location),
|
|
2729
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
2730
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
2731
|
+
content: data.content ? Token.from(data.content) : null,
|
|
2732
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
2733
|
+
});
|
|
2501
2734
|
}
|
|
2502
|
-
constructor(
|
|
2503
|
-
|
|
2504
|
-
this.
|
|
2735
|
+
constructor(props) {
|
|
2736
|
+
super(props.type, props.location, props.errors);
|
|
2737
|
+
this.tag_opening = props.tag_opening;
|
|
2738
|
+
this.content = props.content;
|
|
2739
|
+
this.tag_closing = props.tag_closing;
|
|
2740
|
+
}
|
|
2741
|
+
accept(visitor) {
|
|
2742
|
+
visitor.visitERBYieldNode(this);
|
|
2743
|
+
}
|
|
2744
|
+
childNodes() {
|
|
2745
|
+
return [];
|
|
2746
|
+
}
|
|
2747
|
+
compactChildNodes() {
|
|
2748
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
2749
|
+
}
|
|
2750
|
+
recursiveErrors() {
|
|
2751
|
+
return [
|
|
2752
|
+
...this.errors,
|
|
2753
|
+
].flat();
|
|
2754
|
+
}
|
|
2755
|
+
toJSON() {
|
|
2756
|
+
return {
|
|
2757
|
+
...super.toJSON(),
|
|
2758
|
+
type: "AST_ERB_YIELD_NODE",
|
|
2759
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
2760
|
+
content: this.content ? this.content.toJSON() : null,
|
|
2761
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
2762
|
+
};
|
|
2763
|
+
}
|
|
2764
|
+
treeInspect() {
|
|
2765
|
+
let output = "";
|
|
2766
|
+
output += `@ ERBYieldNode ${this.location.treeInspectWithLabel()}\n`;
|
|
2767
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
2768
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
2769
|
+
output += `├── content: ${this.content ? this.content.treeInspect() : "∅"}\n`;
|
|
2770
|
+
output += `└── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
2771
|
+
// output += "\n";
|
|
2772
|
+
return output;
|
|
2773
|
+
}
|
|
2774
|
+
}
|
|
2775
|
+
class ERBInNode extends Node {
|
|
2776
|
+
tag_opening;
|
|
2777
|
+
content;
|
|
2778
|
+
tag_closing;
|
|
2779
|
+
statements;
|
|
2780
|
+
static from(data) {
|
|
2781
|
+
return new ERBInNode({
|
|
2782
|
+
type: data.type,
|
|
2783
|
+
location: Location.from(data.location),
|
|
2784
|
+
errors: (data.errors || []).map(error => HerbError.from(error)),
|
|
2785
|
+
tag_opening: data.tag_opening ? Token.from(data.tag_opening) : null,
|
|
2786
|
+
content: data.content ? Token.from(data.content) : null,
|
|
2787
|
+
tag_closing: data.tag_closing ? Token.from(data.tag_closing) : null,
|
|
2788
|
+
statements: (data.statements || []).map(node => fromSerializedNode(node)),
|
|
2789
|
+
});
|
|
2790
|
+
}
|
|
2791
|
+
constructor(props) {
|
|
2792
|
+
super(props.type, props.location, props.errors);
|
|
2793
|
+
this.tag_opening = props.tag_opening;
|
|
2794
|
+
this.content = props.content;
|
|
2795
|
+
this.tag_closing = props.tag_closing;
|
|
2796
|
+
this.statements = props.statements;
|
|
2797
|
+
}
|
|
2798
|
+
accept(visitor) {
|
|
2799
|
+
visitor.visitERBInNode(this);
|
|
2800
|
+
}
|
|
2801
|
+
childNodes() {
|
|
2802
|
+
return [
|
|
2803
|
+
...this.statements,
|
|
2804
|
+
];
|
|
2805
|
+
}
|
|
2806
|
+
compactChildNodes() {
|
|
2807
|
+
return this.childNodes().filter(node => node !== null && node !== undefined);
|
|
2808
|
+
}
|
|
2809
|
+
recursiveErrors() {
|
|
2810
|
+
return [
|
|
2811
|
+
...this.errors,
|
|
2812
|
+
...this.statements.map(node => node.recursiveErrors()),
|
|
2813
|
+
].flat();
|
|
2814
|
+
}
|
|
2815
|
+
toJSON() {
|
|
2816
|
+
return {
|
|
2817
|
+
...super.toJSON(),
|
|
2818
|
+
type: "AST_ERB_IN_NODE",
|
|
2819
|
+
tag_opening: this.tag_opening ? this.tag_opening.toJSON() : null,
|
|
2820
|
+
content: this.content ? this.content.toJSON() : null,
|
|
2821
|
+
tag_closing: this.tag_closing ? this.tag_closing.toJSON() : null,
|
|
2822
|
+
statements: this.statements.map(node => node.toJSON()),
|
|
2823
|
+
};
|
|
2824
|
+
}
|
|
2825
|
+
treeInspect() {
|
|
2826
|
+
let output = "";
|
|
2827
|
+
output += `@ ERBInNode ${this.location.treeInspectWithLabel()}\n`;
|
|
2828
|
+
output += `├── errors: ${this.inspectArray(this.errors, "│ ")}`;
|
|
2829
|
+
output += `├── tag_opening: ${this.tag_opening ? this.tag_opening.treeInspect() : "∅"}\n`;
|
|
2830
|
+
output += `├── content: ${this.content ? this.content.treeInspect() : "∅"}\n`;
|
|
2831
|
+
output += `├── tag_closing: ${this.tag_closing ? this.tag_closing.treeInspect() : "∅"}\n`;
|
|
2832
|
+
output += `└── statements: ${this.inspectArray(this.statements, " ")}`;
|
|
2833
|
+
// output += "\n";
|
|
2834
|
+
return output;
|
|
2835
|
+
}
|
|
2836
|
+
}
|
|
2837
|
+
function fromSerializedNode(node) {
|
|
2838
|
+
switch (node.type) {
|
|
2839
|
+
case "AST_DOCUMENT_NODE": return DocumentNode.from(node);
|
|
2840
|
+
case "AST_LITERAL_NODE": return LiteralNode.from(node);
|
|
2841
|
+
case "AST_HTML_OPEN_TAG_NODE": return HTMLOpenTagNode.from(node);
|
|
2842
|
+
case "AST_HTML_CLOSE_TAG_NODE": return HTMLCloseTagNode.from(node);
|
|
2843
|
+
case "AST_HTML_SELF_CLOSE_TAG_NODE": return HTMLSelfCloseTagNode.from(node);
|
|
2844
|
+
case "AST_HTML_ELEMENT_NODE": return HTMLElementNode.from(node);
|
|
2845
|
+
case "AST_HTML_ATTRIBUTE_VALUE_NODE": return HTMLAttributeValueNode.from(node);
|
|
2846
|
+
case "AST_HTML_ATTRIBUTE_NAME_NODE": return HTMLAttributeNameNode.from(node);
|
|
2847
|
+
case "AST_HTML_ATTRIBUTE_NODE": return HTMLAttributeNode.from(node);
|
|
2848
|
+
case "AST_HTML_TEXT_NODE": return HTMLTextNode.from(node);
|
|
2849
|
+
case "AST_HTML_COMMENT_NODE": return HTMLCommentNode.from(node);
|
|
2850
|
+
case "AST_HTML_DOCTYPE_NODE": return HTMLDoctypeNode.from(node);
|
|
2851
|
+
case "AST_WHITESPACE_NODE": return WhitespaceNode.from(node);
|
|
2852
|
+
case "AST_ERB_CONTENT_NODE": return ERBContentNode.from(node);
|
|
2853
|
+
case "AST_ERB_END_NODE": return ERBEndNode.from(node);
|
|
2854
|
+
case "AST_ERB_ELSE_NODE": return ERBElseNode.from(node);
|
|
2855
|
+
case "AST_ERB_IF_NODE": return ERBIfNode.from(node);
|
|
2856
|
+
case "AST_ERB_BLOCK_NODE": return ERBBlockNode.from(node);
|
|
2857
|
+
case "AST_ERB_WHEN_NODE": return ERBWhenNode.from(node);
|
|
2858
|
+
case "AST_ERB_CASE_NODE": return ERBCaseNode.from(node);
|
|
2859
|
+
case "AST_ERB_CASE_MATCH_NODE": return ERBCaseMatchNode.from(node);
|
|
2860
|
+
case "AST_ERB_WHILE_NODE": return ERBWhileNode.from(node);
|
|
2861
|
+
case "AST_ERB_UNTIL_NODE": return ERBUntilNode.from(node);
|
|
2862
|
+
case "AST_ERB_FOR_NODE": return ERBForNode.from(node);
|
|
2863
|
+
case "AST_ERB_RESCUE_NODE": return ERBRescueNode.from(node);
|
|
2864
|
+
case "AST_ERB_ENSURE_NODE": return ERBEnsureNode.from(node);
|
|
2865
|
+
case "AST_ERB_BEGIN_NODE": return ERBBeginNode.from(node);
|
|
2866
|
+
case "AST_ERB_UNLESS_NODE": return ERBUnlessNode.from(node);
|
|
2867
|
+
case "AST_ERB_YIELD_NODE": return ERBYieldNode.from(node);
|
|
2868
|
+
case "AST_ERB_IN_NODE": return ERBInNode.from(node);
|
|
2869
|
+
default:
|
|
2870
|
+
throw new Error(`Unknown node type: ${node.type}`);
|
|
2505
2871
|
}
|
|
2506
2872
|
}
|
|
2507
2873
|
|
|
@@ -2535,7 +2901,7 @@ class ParseResult extends Result {
|
|
|
2535
2901
|
* Determines if the parsing failed.
|
|
2536
2902
|
* @returns `true` if there are errors, otherwise `false`.
|
|
2537
2903
|
*/
|
|
2538
|
-
failed() {
|
|
2904
|
+
get failed() {
|
|
2539
2905
|
// TODO: this should probably be recursive as noted in the Ruby version
|
|
2540
2906
|
return this.errors.length > 0 || this.value.errors.length > 0;
|
|
2541
2907
|
}
|
|
@@ -2543,8 +2909,8 @@ class ParseResult extends Result {
|
|
|
2543
2909
|
* Determines if the parsing was successful.
|
|
2544
2910
|
* @returns `true` if there are no errors, otherwise `false`.
|
|
2545
2911
|
*/
|
|
2546
|
-
|
|
2547
|
-
return
|
|
2912
|
+
get successful() {
|
|
2913
|
+
return this.errors.length === 0;
|
|
2548
2914
|
}
|
|
2549
2915
|
/**
|
|
2550
2916
|
* Returns a pretty-printed JSON string of the errors.
|
|
@@ -2689,23 +3055,116 @@ class HerbBackend {
|
|
|
2689
3055
|
}
|
|
2690
3056
|
}
|
|
2691
3057
|
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
*/
|
|
3058
|
+
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
3059
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/visitor.ts.erb
|
|
2695
3060
|
class Visitor {
|
|
2696
|
-
/**
|
|
2697
|
-
* Visits a node and performs an action.
|
|
2698
|
-
* @param node - The node to visit.
|
|
2699
|
-
*/
|
|
2700
3061
|
visit(node) {
|
|
2701
|
-
|
|
3062
|
+
if (!node)
|
|
3063
|
+
return;
|
|
3064
|
+
node.accept(this);
|
|
3065
|
+
}
|
|
3066
|
+
visitAll(nodes) {
|
|
3067
|
+
nodes.forEach(node => node?.accept(this));
|
|
3068
|
+
}
|
|
3069
|
+
visitChildNodes(node) {
|
|
3070
|
+
node.compactChildNodes().forEach(node => node.accept(this));
|
|
3071
|
+
}
|
|
3072
|
+
visitDocumentNode(node) {
|
|
3073
|
+
this.visitChildNodes(node);
|
|
3074
|
+
}
|
|
3075
|
+
visitLiteralNode(node) {
|
|
3076
|
+
this.visitChildNodes(node);
|
|
3077
|
+
}
|
|
3078
|
+
visitHTMLOpenTagNode(node) {
|
|
3079
|
+
this.visitChildNodes(node);
|
|
3080
|
+
}
|
|
3081
|
+
visitHTMLCloseTagNode(node) {
|
|
3082
|
+
this.visitChildNodes(node);
|
|
3083
|
+
}
|
|
3084
|
+
visitHTMLSelfCloseTagNode(node) {
|
|
3085
|
+
this.visitChildNodes(node);
|
|
3086
|
+
}
|
|
3087
|
+
visitHTMLElementNode(node) {
|
|
3088
|
+
this.visitChildNodes(node);
|
|
3089
|
+
}
|
|
3090
|
+
visitHTMLAttributeValueNode(node) {
|
|
3091
|
+
this.visitChildNodes(node);
|
|
3092
|
+
}
|
|
3093
|
+
visitHTMLAttributeNameNode(node) {
|
|
3094
|
+
this.visitChildNodes(node);
|
|
3095
|
+
}
|
|
3096
|
+
visitHTMLAttributeNode(node) {
|
|
3097
|
+
this.visitChildNodes(node);
|
|
3098
|
+
}
|
|
3099
|
+
visitHTMLTextNode(node) {
|
|
3100
|
+
this.visitChildNodes(node);
|
|
3101
|
+
}
|
|
3102
|
+
visitHTMLCommentNode(node) {
|
|
3103
|
+
this.visitChildNodes(node);
|
|
3104
|
+
}
|
|
3105
|
+
visitHTMLDoctypeNode(node) {
|
|
3106
|
+
this.visitChildNodes(node);
|
|
3107
|
+
}
|
|
3108
|
+
visitWhitespaceNode(node) {
|
|
3109
|
+
this.visitChildNodes(node);
|
|
3110
|
+
}
|
|
3111
|
+
visitERBContentNode(node) {
|
|
3112
|
+
this.visitChildNodes(node);
|
|
3113
|
+
}
|
|
3114
|
+
visitERBEndNode(node) {
|
|
3115
|
+
this.visitChildNodes(node);
|
|
3116
|
+
}
|
|
3117
|
+
visitERBElseNode(node) {
|
|
3118
|
+
this.visitChildNodes(node);
|
|
3119
|
+
}
|
|
3120
|
+
visitERBIfNode(node) {
|
|
3121
|
+
this.visitChildNodes(node);
|
|
3122
|
+
}
|
|
3123
|
+
visitERBBlockNode(node) {
|
|
3124
|
+
this.visitChildNodes(node);
|
|
3125
|
+
}
|
|
3126
|
+
visitERBWhenNode(node) {
|
|
3127
|
+
this.visitChildNodes(node);
|
|
3128
|
+
}
|
|
3129
|
+
visitERBCaseNode(node) {
|
|
3130
|
+
this.visitChildNodes(node);
|
|
3131
|
+
}
|
|
3132
|
+
visitERBCaseMatchNode(node) {
|
|
3133
|
+
this.visitChildNodes(node);
|
|
3134
|
+
}
|
|
3135
|
+
visitERBWhileNode(node) {
|
|
3136
|
+
this.visitChildNodes(node);
|
|
3137
|
+
}
|
|
3138
|
+
visitERBUntilNode(node) {
|
|
3139
|
+
this.visitChildNodes(node);
|
|
3140
|
+
}
|
|
3141
|
+
visitERBForNode(node) {
|
|
3142
|
+
this.visitChildNodes(node);
|
|
3143
|
+
}
|
|
3144
|
+
visitERBRescueNode(node) {
|
|
3145
|
+
this.visitChildNodes(node);
|
|
3146
|
+
}
|
|
3147
|
+
visitERBEnsureNode(node) {
|
|
3148
|
+
this.visitChildNodes(node);
|
|
3149
|
+
}
|
|
3150
|
+
visitERBBeginNode(node) {
|
|
3151
|
+
this.visitChildNodes(node);
|
|
3152
|
+
}
|
|
3153
|
+
visitERBUnlessNode(node) {
|
|
3154
|
+
this.visitChildNodes(node);
|
|
3155
|
+
}
|
|
3156
|
+
visitERBYieldNode(node) {
|
|
3157
|
+
this.visitChildNodes(node);
|
|
3158
|
+
}
|
|
3159
|
+
visitERBInNode(node) {
|
|
3160
|
+
this.visitChildNodes(node);
|
|
2702
3161
|
}
|
|
2703
3162
|
}
|
|
2704
3163
|
|
|
2705
|
-
exports.ASTNode = ASTNode;
|
|
2706
3164
|
exports.DocumentNode = DocumentNode;
|
|
2707
3165
|
exports.ERBBeginNode = ERBBeginNode;
|
|
2708
3166
|
exports.ERBBlockNode = ERBBlockNode;
|
|
3167
|
+
exports.ERBCaseMatchNode = ERBCaseMatchNode;
|
|
2709
3168
|
exports.ERBCaseNode = ERBCaseNode;
|
|
2710
3169
|
exports.ERBContentNode = ERBContentNode;
|
|
2711
3170
|
exports.ERBElseNode = ERBElseNode;
|
|
@@ -2713,11 +3172,13 @@ exports.ERBEndNode = ERBEndNode;
|
|
|
2713
3172
|
exports.ERBEnsureNode = ERBEnsureNode;
|
|
2714
3173
|
exports.ERBForNode = ERBForNode;
|
|
2715
3174
|
exports.ERBIfNode = ERBIfNode;
|
|
3175
|
+
exports.ERBInNode = ERBInNode;
|
|
2716
3176
|
exports.ERBRescueNode = ERBRescueNode;
|
|
2717
3177
|
exports.ERBUnlessNode = ERBUnlessNode;
|
|
2718
3178
|
exports.ERBUntilNode = ERBUntilNode;
|
|
2719
3179
|
exports.ERBWhenNode = ERBWhenNode;
|
|
2720
3180
|
exports.ERBWhileNode = ERBWhileNode;
|
|
3181
|
+
exports.ERBYieldNode = ERBYieldNode;
|
|
2721
3182
|
exports.HTMLAttributeNameNode = HTMLAttributeNameNode;
|
|
2722
3183
|
exports.HTMLAttributeNode = HTMLAttributeNode;
|
|
2723
3184
|
exports.HTMLAttributeValueNode = HTMLAttributeValueNode;
|
|
@@ -2729,11 +3190,14 @@ exports.HTMLOpenTagNode = HTMLOpenTagNode;
|
|
|
2729
3190
|
exports.HTMLSelfCloseTagNode = HTMLSelfCloseTagNode;
|
|
2730
3191
|
exports.HTMLTextNode = HTMLTextNode;
|
|
2731
3192
|
exports.HerbBackend = HerbBackend;
|
|
3193
|
+
exports.HerbError = HerbError;
|
|
3194
|
+
exports.HerbWarning = HerbWarning;
|
|
2732
3195
|
exports.LexResult = LexResult;
|
|
2733
3196
|
exports.LiteralNode = LiteralNode;
|
|
2734
3197
|
exports.Location = Location;
|
|
2735
3198
|
exports.MissingClosingTagError = MissingClosingTagError;
|
|
2736
3199
|
exports.MissingOpeningTagError = MissingOpeningTagError;
|
|
3200
|
+
exports.Node = Node;
|
|
2737
3201
|
exports.ParseResult = ParseResult;
|
|
2738
3202
|
exports.Position = Position;
|
|
2739
3203
|
exports.QuotesMismatchError = QuotesMismatchError;
|