@herb-tools/core 0.2.0 → 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 +4 -0
- package/dist/herb-core.browser.js +88 -79
- package/dist/herb-core.browser.js.map +1 -1
- package/dist/herb-core.cjs +89 -78
- package/dist/herb-core.cjs.map +1 -1
- package/dist/herb-core.esm.js +88 -79
- package/dist/herb-core.esm.js.map +1 -1
- package/dist/herb-core.umd.js +89 -78
- 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 +32 -4
- package/dist/types/parse-result.d.ts +4 -4
- package/dist/types/result.d.ts +12 -4
- package/dist/types/visitor.d.ts +1 -2
- package/package.json +1 -1
- package/src/errors.ts +49 -14
- package/src/index.ts +1 -1
- package/src/lex-result.ts +15 -9
- package/src/nodes.ts +149 -39
- package/src/parse-result.ts +7 -5
- package/src/result.ts +14 -6
- package/src/visitor.ts +1 -2
- package/dist/types/error.d.ts +0 -16
- package/dist/types/node.d.ts +0 -30
- package/src/error.ts +0 -38
- package/src/node.ts +0 -109
package/dist/herb-core.umd.js
CHANGED
|
@@ -168,6 +168,8 @@
|
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
+
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
172
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/errors.ts.erb
|
|
171
173
|
class HerbError {
|
|
172
174
|
type;
|
|
173
175
|
message;
|
|
@@ -191,24 +193,6 @@
|
|
|
191
193
|
return this.treeInspect(0);
|
|
192
194
|
}
|
|
193
195
|
}
|
|
194
|
-
|
|
195
|
-
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
196
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/errors.ts.erb
|
|
197
|
-
function fromSerializedError(error) {
|
|
198
|
-
switch (error.type) {
|
|
199
|
-
case "UNEXPECTED_ERROR": return UnexpectedError.from(error);
|
|
200
|
-
case "UNEXPECTED_TOKEN_ERROR": return UnexpectedTokenError.from(error);
|
|
201
|
-
case "MISSING_OPENING_TAG_ERROR": return MissingOpeningTagError.from(error);
|
|
202
|
-
case "MISSING_CLOSING_TAG_ERROR": return MissingClosingTagError.from(error);
|
|
203
|
-
case "TAG_NAMES_MISMATCH_ERROR": return TagNamesMismatchError.from(error);
|
|
204
|
-
case "QUOTES_MISMATCH_ERROR": return QuotesMismatchError.from(error);
|
|
205
|
-
case "VOID_ELEMENT_CLOSING_TAG_ERROR": return VoidElementClosingTagError.from(error);
|
|
206
|
-
case "UNCLOSED_ELEMENT_ERROR": return UnclosedElementError.from(error);
|
|
207
|
-
case "RUBY_PARSE_ERROR": return RubyParseError.from(error);
|
|
208
|
-
default:
|
|
209
|
-
throw new Error(`Unknown node type: ${error.type}`);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
196
|
class UnexpectedError extends HerbError {
|
|
213
197
|
description;
|
|
214
198
|
expected;
|
|
@@ -731,9 +715,24 @@
|
|
|
731
715
|
return output;
|
|
732
716
|
}
|
|
733
717
|
}
|
|
718
|
+
function fromSerializedError(error) {
|
|
719
|
+
switch (error.type) {
|
|
720
|
+
case "UNEXPECTED_ERROR": return UnexpectedError.from(error);
|
|
721
|
+
case "UNEXPECTED_TOKEN_ERROR": return UnexpectedTokenError.from(error);
|
|
722
|
+
case "MISSING_OPENING_TAG_ERROR": return MissingOpeningTagError.from(error);
|
|
723
|
+
case "MISSING_CLOSING_TAG_ERROR": return MissingClosingTagError.from(error);
|
|
724
|
+
case "TAG_NAMES_MISMATCH_ERROR": return TagNamesMismatchError.from(error);
|
|
725
|
+
case "QUOTES_MISMATCH_ERROR": return QuotesMismatchError.from(error);
|
|
726
|
+
case "VOID_ELEMENT_CLOSING_TAG_ERROR": return VoidElementClosingTagError.from(error);
|
|
727
|
+
case "UNCLOSED_ELEMENT_ERROR": return UnclosedElementError.from(error);
|
|
728
|
+
case "RUBY_PARSE_ERROR": return RubyParseError.from(error);
|
|
729
|
+
default:
|
|
730
|
+
throw new Error(`Unknown node type: ${error.type}`);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
734
733
|
|
|
735
734
|
var name = "@herb-tools/core";
|
|
736
|
-
var version = "0.
|
|
735
|
+
var version = "0.3.0";
|
|
737
736
|
var packageJSON = {
|
|
738
737
|
name: name,
|
|
739
738
|
version: version};
|
|
@@ -762,11 +761,19 @@
|
|
|
762
761
|
this.warnings = warnings || [];
|
|
763
762
|
this.errors = errors || [];
|
|
764
763
|
}
|
|
765
|
-
|
|
766
|
-
|
|
764
|
+
/**
|
|
765
|
+
* Determines if the parsing was successful.
|
|
766
|
+
* @returns `true` if there are no errors, otherwise `false`.
|
|
767
|
+
*/
|
|
768
|
+
get successful() {
|
|
769
|
+
return this.errors.length === 0;
|
|
767
770
|
}
|
|
768
|
-
|
|
769
|
-
|
|
771
|
+
/**
|
|
772
|
+
* Determines if the parsing failed.
|
|
773
|
+
* @returns `true` if there are errors, otherwise `false`.
|
|
774
|
+
*/
|
|
775
|
+
get failed() {
|
|
776
|
+
return this.errors.length > 0;
|
|
770
777
|
}
|
|
771
778
|
}
|
|
772
779
|
|
|
@@ -807,6 +814,18 @@
|
|
|
807
814
|
}
|
|
808
815
|
}
|
|
809
816
|
|
|
817
|
+
class HerbWarning {
|
|
818
|
+
message;
|
|
819
|
+
location;
|
|
820
|
+
static from(warning) {
|
|
821
|
+
return new HerbWarning(warning.message, Location.from(warning.location));
|
|
822
|
+
}
|
|
823
|
+
constructor(message, location) {
|
|
824
|
+
this.message = message;
|
|
825
|
+
this.location = location;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
|
|
810
829
|
/**
|
|
811
830
|
* Represents the result of a lexical analysis, extending the base `Result` class.
|
|
812
831
|
* It contains the token list, source code, warnings, and errors.
|
|
@@ -820,7 +839,7 @@
|
|
|
820
839
|
* @returns A new `LexResult` instance.
|
|
821
840
|
*/
|
|
822
841
|
static from(result) {
|
|
823
|
-
return new LexResult(TokenList.from(result.tokens || []), result.source, result.warnings, result.errors);
|
|
842
|
+
return new LexResult(TokenList.from(result.tokens || []), result.source, result.warnings.map((warning) => HerbWarning.from(warning)), result.errors.map((error) => HerbError.from(error)));
|
|
824
843
|
}
|
|
825
844
|
/**
|
|
826
845
|
* Constructs a new `LexResult`.
|
|
@@ -837,14 +856,14 @@
|
|
|
837
856
|
* Determines if the lexing was successful.
|
|
838
857
|
* @returns `true` if there are no errors, otherwise `false`.
|
|
839
858
|
*/
|
|
840
|
-
|
|
859
|
+
get successful() {
|
|
841
860
|
return this.errors.length === 0;
|
|
842
861
|
}
|
|
843
862
|
/**
|
|
844
863
|
* Determines if the lexing failed.
|
|
845
864
|
* @returns `true` if there are errors, otherwise `false`.
|
|
846
865
|
*/
|
|
847
|
-
failed() {
|
|
866
|
+
get failed() {
|
|
848
867
|
return this.errors.length > 0;
|
|
849
868
|
}
|
|
850
869
|
/**
|
|
@@ -861,6 +880,8 @@
|
|
|
861
880
|
}
|
|
862
881
|
}
|
|
863
882
|
|
|
883
|
+
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
884
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/nodes.ts.erb
|
|
864
885
|
class Node {
|
|
865
886
|
type;
|
|
866
887
|
location;
|
|
@@ -883,6 +904,9 @@
|
|
|
883
904
|
inspect() {
|
|
884
905
|
return this.treeInspect(0);
|
|
885
906
|
}
|
|
907
|
+
get isSingleLine() {
|
|
908
|
+
return this.location.start.line === this.location.end.line;
|
|
909
|
+
}
|
|
886
910
|
inspectArray(array, prefix) {
|
|
887
911
|
if (!array)
|
|
888
912
|
return "∅\n";
|
|
@@ -919,45 +943,6 @@
|
|
|
919
943
|
return output;
|
|
920
944
|
}
|
|
921
945
|
}
|
|
922
|
-
|
|
923
|
-
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
924
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/nodes.ts.erb
|
|
925
|
-
function fromSerializedNode(node) {
|
|
926
|
-
switch (node.type) {
|
|
927
|
-
case "AST_DOCUMENT_NODE": return DocumentNode.from(node);
|
|
928
|
-
case "AST_LITERAL_NODE": return LiteralNode.from(node);
|
|
929
|
-
case "AST_HTML_OPEN_TAG_NODE": return HTMLOpenTagNode.from(node);
|
|
930
|
-
case "AST_HTML_CLOSE_TAG_NODE": return HTMLCloseTagNode.from(node);
|
|
931
|
-
case "AST_HTML_SELF_CLOSE_TAG_NODE": return HTMLSelfCloseTagNode.from(node);
|
|
932
|
-
case "AST_HTML_ELEMENT_NODE": return HTMLElementNode.from(node);
|
|
933
|
-
case "AST_HTML_ATTRIBUTE_VALUE_NODE": return HTMLAttributeValueNode.from(node);
|
|
934
|
-
case "AST_HTML_ATTRIBUTE_NAME_NODE": return HTMLAttributeNameNode.from(node);
|
|
935
|
-
case "AST_HTML_ATTRIBUTE_NODE": return HTMLAttributeNode.from(node);
|
|
936
|
-
case "AST_HTML_TEXT_NODE": return HTMLTextNode.from(node);
|
|
937
|
-
case "AST_HTML_COMMENT_NODE": return HTMLCommentNode.from(node);
|
|
938
|
-
case "AST_HTML_DOCTYPE_NODE": return HTMLDoctypeNode.from(node);
|
|
939
|
-
case "AST_WHITESPACE_NODE": return WhitespaceNode.from(node);
|
|
940
|
-
case "AST_ERB_CONTENT_NODE": return ERBContentNode.from(node);
|
|
941
|
-
case "AST_ERB_END_NODE": return ERBEndNode.from(node);
|
|
942
|
-
case "AST_ERB_ELSE_NODE": return ERBElseNode.from(node);
|
|
943
|
-
case "AST_ERB_IF_NODE": return ERBIfNode.from(node);
|
|
944
|
-
case "AST_ERB_BLOCK_NODE": return ERBBlockNode.from(node);
|
|
945
|
-
case "AST_ERB_WHEN_NODE": return ERBWhenNode.from(node);
|
|
946
|
-
case "AST_ERB_CASE_NODE": return ERBCaseNode.from(node);
|
|
947
|
-
case "AST_ERB_CASE_MATCH_NODE": return ERBCaseMatchNode.from(node);
|
|
948
|
-
case "AST_ERB_WHILE_NODE": return ERBWhileNode.from(node);
|
|
949
|
-
case "AST_ERB_UNTIL_NODE": return ERBUntilNode.from(node);
|
|
950
|
-
case "AST_ERB_FOR_NODE": return ERBForNode.from(node);
|
|
951
|
-
case "AST_ERB_RESCUE_NODE": return ERBRescueNode.from(node);
|
|
952
|
-
case "AST_ERB_ENSURE_NODE": return ERBEnsureNode.from(node);
|
|
953
|
-
case "AST_ERB_BEGIN_NODE": return ERBBeginNode.from(node);
|
|
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);
|
|
957
|
-
default:
|
|
958
|
-
throw new Error(`Unknown node type: ${node.type}`);
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
946
|
class DocumentNode extends Node {
|
|
962
947
|
children;
|
|
963
948
|
static from(data) {
|
|
@@ -2853,16 +2838,40 @@
|
|
|
2853
2838
|
return output;
|
|
2854
2839
|
}
|
|
2855
2840
|
}
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2841
|
+
function fromSerializedNode(node) {
|
|
2842
|
+
switch (node.type) {
|
|
2843
|
+
case "AST_DOCUMENT_NODE": return DocumentNode.from(node);
|
|
2844
|
+
case "AST_LITERAL_NODE": return LiteralNode.from(node);
|
|
2845
|
+
case "AST_HTML_OPEN_TAG_NODE": return HTMLOpenTagNode.from(node);
|
|
2846
|
+
case "AST_HTML_CLOSE_TAG_NODE": return HTMLCloseTagNode.from(node);
|
|
2847
|
+
case "AST_HTML_SELF_CLOSE_TAG_NODE": return HTMLSelfCloseTagNode.from(node);
|
|
2848
|
+
case "AST_HTML_ELEMENT_NODE": return HTMLElementNode.from(node);
|
|
2849
|
+
case "AST_HTML_ATTRIBUTE_VALUE_NODE": return HTMLAttributeValueNode.from(node);
|
|
2850
|
+
case "AST_HTML_ATTRIBUTE_NAME_NODE": return HTMLAttributeNameNode.from(node);
|
|
2851
|
+
case "AST_HTML_ATTRIBUTE_NODE": return HTMLAttributeNode.from(node);
|
|
2852
|
+
case "AST_HTML_TEXT_NODE": return HTMLTextNode.from(node);
|
|
2853
|
+
case "AST_HTML_COMMENT_NODE": return HTMLCommentNode.from(node);
|
|
2854
|
+
case "AST_HTML_DOCTYPE_NODE": return HTMLDoctypeNode.from(node);
|
|
2855
|
+
case "AST_WHITESPACE_NODE": return WhitespaceNode.from(node);
|
|
2856
|
+
case "AST_ERB_CONTENT_NODE": return ERBContentNode.from(node);
|
|
2857
|
+
case "AST_ERB_END_NODE": return ERBEndNode.from(node);
|
|
2858
|
+
case "AST_ERB_ELSE_NODE": return ERBElseNode.from(node);
|
|
2859
|
+
case "AST_ERB_IF_NODE": return ERBIfNode.from(node);
|
|
2860
|
+
case "AST_ERB_BLOCK_NODE": return ERBBlockNode.from(node);
|
|
2861
|
+
case "AST_ERB_WHEN_NODE": return ERBWhenNode.from(node);
|
|
2862
|
+
case "AST_ERB_CASE_NODE": return ERBCaseNode.from(node);
|
|
2863
|
+
case "AST_ERB_CASE_MATCH_NODE": return ERBCaseMatchNode.from(node);
|
|
2864
|
+
case "AST_ERB_WHILE_NODE": return ERBWhileNode.from(node);
|
|
2865
|
+
case "AST_ERB_UNTIL_NODE": return ERBUntilNode.from(node);
|
|
2866
|
+
case "AST_ERB_FOR_NODE": return ERBForNode.from(node);
|
|
2867
|
+
case "AST_ERB_RESCUE_NODE": return ERBRescueNode.from(node);
|
|
2868
|
+
case "AST_ERB_ENSURE_NODE": return ERBEnsureNode.from(node);
|
|
2869
|
+
case "AST_ERB_BEGIN_NODE": return ERBBeginNode.from(node);
|
|
2870
|
+
case "AST_ERB_UNLESS_NODE": return ERBUnlessNode.from(node);
|
|
2871
|
+
case "AST_ERB_YIELD_NODE": return ERBYieldNode.from(node);
|
|
2872
|
+
case "AST_ERB_IN_NODE": return ERBInNode.from(node);
|
|
2873
|
+
default:
|
|
2874
|
+
throw new Error(`Unknown node type: ${node.type}`);
|
|
2866
2875
|
}
|
|
2867
2876
|
}
|
|
2868
2877
|
|
|
@@ -2896,7 +2905,7 @@
|
|
|
2896
2905
|
* Determines if the parsing failed.
|
|
2897
2906
|
* @returns `true` if there are errors, otherwise `false`.
|
|
2898
2907
|
*/
|
|
2899
|
-
failed() {
|
|
2908
|
+
get failed() {
|
|
2900
2909
|
// TODO: this should probably be recursive as noted in the Ruby version
|
|
2901
2910
|
return this.errors.length > 0 || this.value.errors.length > 0;
|
|
2902
2911
|
}
|
|
@@ -2904,8 +2913,8 @@
|
|
|
2904
2913
|
* Determines if the parsing was successful.
|
|
2905
2914
|
* @returns `true` if there are no errors, otherwise `false`.
|
|
2906
2915
|
*/
|
|
2907
|
-
|
|
2908
|
-
return
|
|
2916
|
+
get successful() {
|
|
2917
|
+
return this.errors.length === 0;
|
|
2909
2918
|
}
|
|
2910
2919
|
/**
|
|
2911
2920
|
* Returns a pretty-printed JSON string of the errors.
|
|
@@ -3185,6 +3194,8 @@
|
|
|
3185
3194
|
exports.HTMLSelfCloseTagNode = HTMLSelfCloseTagNode;
|
|
3186
3195
|
exports.HTMLTextNode = HTMLTextNode;
|
|
3187
3196
|
exports.HerbBackend = HerbBackend;
|
|
3197
|
+
exports.HerbError = HerbError;
|
|
3198
|
+
exports.HerbWarning = HerbWarning;
|
|
3188
3199
|
exports.LexResult = LexResult;
|
|
3189
3200
|
exports.LiteralNode = LiteralNode;
|
|
3190
3201
|
exports.Location = Location;
|