@herb-tools/core 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -164,6 +164,8 @@ class Token {
164
164
  }
165
165
  }
166
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
167
169
  class HerbError {
168
170
  type;
169
171
  message;
@@ -187,24 +189,6 @@ class HerbError {
187
189
  return this.treeInspect(0);
188
190
  }
189
191
  }
190
-
191
- // NOTE: This file is generated by the templates/template.rb script and should not
192
- // be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/errors.ts.erb
193
- function fromSerializedError(error) {
194
- switch (error.type) {
195
- case "UNEXPECTED_ERROR": return UnexpectedError.from(error);
196
- case "UNEXPECTED_TOKEN_ERROR": return UnexpectedTokenError.from(error);
197
- case "MISSING_OPENING_TAG_ERROR": return MissingOpeningTagError.from(error);
198
- case "MISSING_CLOSING_TAG_ERROR": return MissingClosingTagError.from(error);
199
- case "TAG_NAMES_MISMATCH_ERROR": return TagNamesMismatchError.from(error);
200
- case "QUOTES_MISMATCH_ERROR": return QuotesMismatchError.from(error);
201
- case "VOID_ELEMENT_CLOSING_TAG_ERROR": return VoidElementClosingTagError.from(error);
202
- case "UNCLOSED_ELEMENT_ERROR": return UnclosedElementError.from(error);
203
- case "RUBY_PARSE_ERROR": return RubyParseError.from(error);
204
- default:
205
- throw new Error(`Unknown node type: ${error.type}`);
206
- }
207
- }
208
192
  class UnexpectedError extends HerbError {
209
193
  description;
210
194
  expected;
@@ -727,9 +711,24 @@ class RubyParseError extends HerbError {
727
711
  return output;
728
712
  }
729
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
+ }
730
729
 
731
730
  var name = "@herb-tools/core";
732
- var version = "0.2.0";
731
+ var version = "0.3.1";
733
732
  var packageJSON = {
734
733
  name: name,
735
734
  version: version};
@@ -758,11 +757,19 @@ class Result {
758
757
  this.warnings = warnings || [];
759
758
  this.errors = errors || [];
760
759
  }
761
- success() {
762
- return false;
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;
763
766
  }
764
- failed() {
765
- return true;
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;
766
773
  }
767
774
  }
768
775
 
@@ -803,6 +810,18 @@ class TokenList {
803
810
  }
804
811
  }
805
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
+
806
825
  /**
807
826
  * Represents the result of a lexical analysis, extending the base `Result` class.
808
827
  * It contains the token list, source code, warnings, and errors.
@@ -816,7 +835,7 @@ class LexResult extends Result {
816
835
  * @returns A new `LexResult` instance.
817
836
  */
818
837
  static from(result) {
819
- 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)));
820
839
  }
821
840
  /**
822
841
  * Constructs a new `LexResult`.
@@ -833,14 +852,14 @@ class LexResult extends Result {
833
852
  * Determines if the lexing was successful.
834
853
  * @returns `true` if there are no errors, otherwise `false`.
835
854
  */
836
- success() {
855
+ get successful() {
837
856
  return this.errors.length === 0;
838
857
  }
839
858
  /**
840
859
  * Determines if the lexing failed.
841
860
  * @returns `true` if there are errors, otherwise `false`.
842
861
  */
843
- failed() {
862
+ get failed() {
844
863
  return this.errors.length > 0;
845
864
  }
846
865
  /**
@@ -857,6 +876,8 @@ class LexResult extends Result {
857
876
  }
858
877
  }
859
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
860
881
  class Node {
861
882
  type;
862
883
  location;
@@ -879,6 +900,9 @@ class Node {
879
900
  inspect() {
880
901
  return this.treeInspect(0);
881
902
  }
903
+ get isSingleLine() {
904
+ return this.location.start.line === this.location.end.line;
905
+ }
882
906
  inspectArray(array, prefix) {
883
907
  if (!array)
884
908
  return "∅\n";
@@ -915,45 +939,6 @@ class Node {
915
939
  return output;
916
940
  }
917
941
  }
918
-
919
- // NOTE: This file is generated by the templates/template.rb script and should not
920
- // be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/nodes.ts.erb
921
- function fromSerializedNode(node) {
922
- switch (node.type) {
923
- case "AST_DOCUMENT_NODE": return DocumentNode.from(node);
924
- case "AST_LITERAL_NODE": return LiteralNode.from(node);
925
- case "AST_HTML_OPEN_TAG_NODE": return HTMLOpenTagNode.from(node);
926
- case "AST_HTML_CLOSE_TAG_NODE": return HTMLCloseTagNode.from(node);
927
- case "AST_HTML_SELF_CLOSE_TAG_NODE": return HTMLSelfCloseTagNode.from(node);
928
- case "AST_HTML_ELEMENT_NODE": return HTMLElementNode.from(node);
929
- case "AST_HTML_ATTRIBUTE_VALUE_NODE": return HTMLAttributeValueNode.from(node);
930
- case "AST_HTML_ATTRIBUTE_NAME_NODE": return HTMLAttributeNameNode.from(node);
931
- case "AST_HTML_ATTRIBUTE_NODE": return HTMLAttributeNode.from(node);
932
- case "AST_HTML_TEXT_NODE": return HTMLTextNode.from(node);
933
- case "AST_HTML_COMMENT_NODE": return HTMLCommentNode.from(node);
934
- case "AST_HTML_DOCTYPE_NODE": return HTMLDoctypeNode.from(node);
935
- case "AST_WHITESPACE_NODE": return WhitespaceNode.from(node);
936
- case "AST_ERB_CONTENT_NODE": return ERBContentNode.from(node);
937
- case "AST_ERB_END_NODE": return ERBEndNode.from(node);
938
- case "AST_ERB_ELSE_NODE": return ERBElseNode.from(node);
939
- case "AST_ERB_IF_NODE": return ERBIfNode.from(node);
940
- case "AST_ERB_BLOCK_NODE": return ERBBlockNode.from(node);
941
- case "AST_ERB_WHEN_NODE": return ERBWhenNode.from(node);
942
- case "AST_ERB_CASE_NODE": return ERBCaseNode.from(node);
943
- case "AST_ERB_CASE_MATCH_NODE": return ERBCaseMatchNode.from(node);
944
- case "AST_ERB_WHILE_NODE": return ERBWhileNode.from(node);
945
- case "AST_ERB_UNTIL_NODE": return ERBUntilNode.from(node);
946
- case "AST_ERB_FOR_NODE": return ERBForNode.from(node);
947
- case "AST_ERB_RESCUE_NODE": return ERBRescueNode.from(node);
948
- case "AST_ERB_ENSURE_NODE": return ERBEnsureNode.from(node);
949
- case "AST_ERB_BEGIN_NODE": return ERBBeginNode.from(node);
950
- case "AST_ERB_UNLESS_NODE": return ERBUnlessNode.from(node);
951
- case "AST_ERB_YIELD_NODE": return ERBYieldNode.from(node);
952
- case "AST_ERB_IN_NODE": return ERBInNode.from(node);
953
- default:
954
- throw new Error(`Unknown node type: ${node.type}`);
955
- }
956
- }
957
942
  class DocumentNode extends Node {
958
943
  children;
959
944
  static from(data) {
@@ -2849,16 +2834,40 @@ class ERBInNode extends Node {
2849
2834
  return output;
2850
2835
  }
2851
2836
  }
2852
-
2853
- class HerbWarning {
2854
- message;
2855
- location;
2856
- static from(warning) {
2857
- return new HerbWarning(warning.message, Location.from(warning.location));
2858
- }
2859
- constructor(message, location) {
2860
- this.message = message;
2861
- this.location = location;
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}`);
2862
2871
  }
2863
2872
  }
2864
2873
 
@@ -2892,7 +2901,7 @@ class ParseResult extends Result {
2892
2901
  * Determines if the parsing failed.
2893
2902
  * @returns `true` if there are errors, otherwise `false`.
2894
2903
  */
2895
- failed() {
2904
+ get failed() {
2896
2905
  // TODO: this should probably be recursive as noted in the Ruby version
2897
2906
  return this.errors.length > 0 || this.value.errors.length > 0;
2898
2907
  }
@@ -2900,8 +2909,8 @@ class ParseResult extends Result {
2900
2909
  * Determines if the parsing was successful.
2901
2910
  * @returns `true` if there are no errors, otherwise `false`.
2902
2911
  */
2903
- success() {
2904
- return !this.failed();
2912
+ get successful() {
2913
+ return this.errors.length === 0;
2905
2914
  }
2906
2915
  /**
2907
2916
  * Returns a pretty-printed JSON string of the errors.
@@ -3181,6 +3190,8 @@ exports.HTMLOpenTagNode = HTMLOpenTagNode;
3181
3190
  exports.HTMLSelfCloseTagNode = HTMLSelfCloseTagNode;
3182
3191
  exports.HTMLTextNode = HTMLTextNode;
3183
3192
  exports.HerbBackend = HerbBackend;
3193
+ exports.HerbError = HerbError;
3194
+ exports.HerbWarning = HerbWarning;
3184
3195
  exports.LexResult = LexResult;
3185
3196
  exports.LiteralNode = LiteralNode;
3186
3197
  exports.Location = Location;