@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.
@@ -162,6 +162,8 @@ class Token {
162
162
  }
163
163
  }
164
164
 
165
+ // NOTE: This file is generated by the templates/template.rb script and should not
166
+ // be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/errors.ts.erb
165
167
  class HerbError {
166
168
  type;
167
169
  message;
@@ -185,24 +187,6 @@ class HerbError {
185
187
  return this.treeInspect(0);
186
188
  }
187
189
  }
188
-
189
- // NOTE: This file is generated by the templates/template.rb script and should not
190
- // be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/errors.ts.erb
191
- function fromSerializedError(error) {
192
- switch (error.type) {
193
- case "UNEXPECTED_ERROR": return UnexpectedError.from(error);
194
- case "UNEXPECTED_TOKEN_ERROR": return UnexpectedTokenError.from(error);
195
- case "MISSING_OPENING_TAG_ERROR": return MissingOpeningTagError.from(error);
196
- case "MISSING_CLOSING_TAG_ERROR": return MissingClosingTagError.from(error);
197
- case "TAG_NAMES_MISMATCH_ERROR": return TagNamesMismatchError.from(error);
198
- case "QUOTES_MISMATCH_ERROR": return QuotesMismatchError.from(error);
199
- case "VOID_ELEMENT_CLOSING_TAG_ERROR": return VoidElementClosingTagError.from(error);
200
- case "UNCLOSED_ELEMENT_ERROR": return UnclosedElementError.from(error);
201
- case "RUBY_PARSE_ERROR": return RubyParseError.from(error);
202
- default:
203
- throw new Error(`Unknown node type: ${error.type}`);
204
- }
205
- }
206
190
  class UnexpectedError extends HerbError {
207
191
  description;
208
192
  expected;
@@ -725,9 +709,24 @@ class RubyParseError extends HerbError {
725
709
  return output;
726
710
  }
727
711
  }
712
+ function fromSerializedError(error) {
713
+ switch (error.type) {
714
+ case "UNEXPECTED_ERROR": return UnexpectedError.from(error);
715
+ case "UNEXPECTED_TOKEN_ERROR": return UnexpectedTokenError.from(error);
716
+ case "MISSING_OPENING_TAG_ERROR": return MissingOpeningTagError.from(error);
717
+ case "MISSING_CLOSING_TAG_ERROR": return MissingClosingTagError.from(error);
718
+ case "TAG_NAMES_MISMATCH_ERROR": return TagNamesMismatchError.from(error);
719
+ case "QUOTES_MISMATCH_ERROR": return QuotesMismatchError.from(error);
720
+ case "VOID_ELEMENT_CLOSING_TAG_ERROR": return VoidElementClosingTagError.from(error);
721
+ case "UNCLOSED_ELEMENT_ERROR": return UnclosedElementError.from(error);
722
+ case "RUBY_PARSE_ERROR": return RubyParseError.from(error);
723
+ default:
724
+ throw new Error(`Unknown node type: ${error.type}`);
725
+ }
726
+ }
728
727
 
729
728
  var name = "@herb-tools/core";
730
- var version = "0.2.0";
729
+ var version = "0.3.1";
731
730
  var packageJSON = {
732
731
  name: name,
733
732
  version: version};
@@ -756,11 +755,19 @@ class Result {
756
755
  this.warnings = warnings || [];
757
756
  this.errors = errors || [];
758
757
  }
759
- success() {
760
- return false;
758
+ /**
759
+ * Determines if the parsing was successful.
760
+ * @returns `true` if there are no errors, otherwise `false`.
761
+ */
762
+ get successful() {
763
+ return this.errors.length === 0;
761
764
  }
762
- failed() {
763
- return true;
765
+ /**
766
+ * Determines if the parsing failed.
767
+ * @returns `true` if there are errors, otherwise `false`.
768
+ */
769
+ get failed() {
770
+ return this.errors.length > 0;
764
771
  }
765
772
  }
766
773
 
@@ -801,6 +808,18 @@ class TokenList {
801
808
  }
802
809
  }
803
810
 
811
+ class HerbWarning {
812
+ message;
813
+ location;
814
+ static from(warning) {
815
+ return new HerbWarning(warning.message, Location.from(warning.location));
816
+ }
817
+ constructor(message, location) {
818
+ this.message = message;
819
+ this.location = location;
820
+ }
821
+ }
822
+
804
823
  /**
805
824
  * Represents the result of a lexical analysis, extending the base `Result` class.
806
825
  * It contains the token list, source code, warnings, and errors.
@@ -814,7 +833,7 @@ class LexResult extends Result {
814
833
  * @returns A new `LexResult` instance.
815
834
  */
816
835
  static from(result) {
817
- return new LexResult(TokenList.from(result.tokens || []), result.source, result.warnings, result.errors);
836
+ return new LexResult(TokenList.from(result.tokens || []), result.source, result.warnings.map((warning) => HerbWarning.from(warning)), result.errors.map((error) => HerbError.from(error)));
818
837
  }
819
838
  /**
820
839
  * Constructs a new `LexResult`.
@@ -831,14 +850,14 @@ class LexResult extends Result {
831
850
  * Determines if the lexing was successful.
832
851
  * @returns `true` if there are no errors, otherwise `false`.
833
852
  */
834
- success() {
853
+ get successful() {
835
854
  return this.errors.length === 0;
836
855
  }
837
856
  /**
838
857
  * Determines if the lexing failed.
839
858
  * @returns `true` if there are errors, otherwise `false`.
840
859
  */
841
- failed() {
860
+ get failed() {
842
861
  return this.errors.length > 0;
843
862
  }
844
863
  /**
@@ -855,6 +874,8 @@ class LexResult extends Result {
855
874
  }
856
875
  }
857
876
 
877
+ // NOTE: This file is generated by the templates/template.rb script and should not
878
+ // be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/nodes.ts.erb
858
879
  class Node {
859
880
  type;
860
881
  location;
@@ -877,6 +898,9 @@ class Node {
877
898
  inspect() {
878
899
  return this.treeInspect(0);
879
900
  }
901
+ get isSingleLine() {
902
+ return this.location.start.line === this.location.end.line;
903
+ }
880
904
  inspectArray(array, prefix) {
881
905
  if (!array)
882
906
  return "∅\n";
@@ -913,45 +937,6 @@ class Node {
913
937
  return output;
914
938
  }
915
939
  }
916
-
917
- // NOTE: This file is generated by the templates/template.rb script and should not
918
- // be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/nodes.ts.erb
919
- function fromSerializedNode(node) {
920
- switch (node.type) {
921
- case "AST_DOCUMENT_NODE": return DocumentNode.from(node);
922
- case "AST_LITERAL_NODE": return LiteralNode.from(node);
923
- case "AST_HTML_OPEN_TAG_NODE": return HTMLOpenTagNode.from(node);
924
- case "AST_HTML_CLOSE_TAG_NODE": return HTMLCloseTagNode.from(node);
925
- case "AST_HTML_SELF_CLOSE_TAG_NODE": return HTMLSelfCloseTagNode.from(node);
926
- case "AST_HTML_ELEMENT_NODE": return HTMLElementNode.from(node);
927
- case "AST_HTML_ATTRIBUTE_VALUE_NODE": return HTMLAttributeValueNode.from(node);
928
- case "AST_HTML_ATTRIBUTE_NAME_NODE": return HTMLAttributeNameNode.from(node);
929
- case "AST_HTML_ATTRIBUTE_NODE": return HTMLAttributeNode.from(node);
930
- case "AST_HTML_TEXT_NODE": return HTMLTextNode.from(node);
931
- case "AST_HTML_COMMENT_NODE": return HTMLCommentNode.from(node);
932
- case "AST_HTML_DOCTYPE_NODE": return HTMLDoctypeNode.from(node);
933
- case "AST_WHITESPACE_NODE": return WhitespaceNode.from(node);
934
- case "AST_ERB_CONTENT_NODE": return ERBContentNode.from(node);
935
- case "AST_ERB_END_NODE": return ERBEndNode.from(node);
936
- case "AST_ERB_ELSE_NODE": return ERBElseNode.from(node);
937
- case "AST_ERB_IF_NODE": return ERBIfNode.from(node);
938
- case "AST_ERB_BLOCK_NODE": return ERBBlockNode.from(node);
939
- case "AST_ERB_WHEN_NODE": return ERBWhenNode.from(node);
940
- case "AST_ERB_CASE_NODE": return ERBCaseNode.from(node);
941
- case "AST_ERB_CASE_MATCH_NODE": return ERBCaseMatchNode.from(node);
942
- case "AST_ERB_WHILE_NODE": return ERBWhileNode.from(node);
943
- case "AST_ERB_UNTIL_NODE": return ERBUntilNode.from(node);
944
- case "AST_ERB_FOR_NODE": return ERBForNode.from(node);
945
- case "AST_ERB_RESCUE_NODE": return ERBRescueNode.from(node);
946
- case "AST_ERB_ENSURE_NODE": return ERBEnsureNode.from(node);
947
- case "AST_ERB_BEGIN_NODE": return ERBBeginNode.from(node);
948
- case "AST_ERB_UNLESS_NODE": return ERBUnlessNode.from(node);
949
- case "AST_ERB_YIELD_NODE": return ERBYieldNode.from(node);
950
- case "AST_ERB_IN_NODE": return ERBInNode.from(node);
951
- default:
952
- throw new Error(`Unknown node type: ${node.type}`);
953
- }
954
- }
955
940
  class DocumentNode extends Node {
956
941
  children;
957
942
  static from(data) {
@@ -2847,16 +2832,40 @@ class ERBInNode extends Node {
2847
2832
  return output;
2848
2833
  }
2849
2834
  }
2850
-
2851
- class HerbWarning {
2852
- message;
2853
- location;
2854
- static from(warning) {
2855
- return new HerbWarning(warning.message, Location.from(warning.location));
2856
- }
2857
- constructor(message, location) {
2858
- this.message = message;
2859
- this.location = location;
2835
+ function fromSerializedNode(node) {
2836
+ switch (node.type) {
2837
+ case "AST_DOCUMENT_NODE": return DocumentNode.from(node);
2838
+ case "AST_LITERAL_NODE": return LiteralNode.from(node);
2839
+ case "AST_HTML_OPEN_TAG_NODE": return HTMLOpenTagNode.from(node);
2840
+ case "AST_HTML_CLOSE_TAG_NODE": return HTMLCloseTagNode.from(node);
2841
+ case "AST_HTML_SELF_CLOSE_TAG_NODE": return HTMLSelfCloseTagNode.from(node);
2842
+ case "AST_HTML_ELEMENT_NODE": return HTMLElementNode.from(node);
2843
+ case "AST_HTML_ATTRIBUTE_VALUE_NODE": return HTMLAttributeValueNode.from(node);
2844
+ case "AST_HTML_ATTRIBUTE_NAME_NODE": return HTMLAttributeNameNode.from(node);
2845
+ case "AST_HTML_ATTRIBUTE_NODE": return HTMLAttributeNode.from(node);
2846
+ case "AST_HTML_TEXT_NODE": return HTMLTextNode.from(node);
2847
+ case "AST_HTML_COMMENT_NODE": return HTMLCommentNode.from(node);
2848
+ case "AST_HTML_DOCTYPE_NODE": return HTMLDoctypeNode.from(node);
2849
+ case "AST_WHITESPACE_NODE": return WhitespaceNode.from(node);
2850
+ case "AST_ERB_CONTENT_NODE": return ERBContentNode.from(node);
2851
+ case "AST_ERB_END_NODE": return ERBEndNode.from(node);
2852
+ case "AST_ERB_ELSE_NODE": return ERBElseNode.from(node);
2853
+ case "AST_ERB_IF_NODE": return ERBIfNode.from(node);
2854
+ case "AST_ERB_BLOCK_NODE": return ERBBlockNode.from(node);
2855
+ case "AST_ERB_WHEN_NODE": return ERBWhenNode.from(node);
2856
+ case "AST_ERB_CASE_NODE": return ERBCaseNode.from(node);
2857
+ case "AST_ERB_CASE_MATCH_NODE": return ERBCaseMatchNode.from(node);
2858
+ case "AST_ERB_WHILE_NODE": return ERBWhileNode.from(node);
2859
+ case "AST_ERB_UNTIL_NODE": return ERBUntilNode.from(node);
2860
+ case "AST_ERB_FOR_NODE": return ERBForNode.from(node);
2861
+ case "AST_ERB_RESCUE_NODE": return ERBRescueNode.from(node);
2862
+ case "AST_ERB_ENSURE_NODE": return ERBEnsureNode.from(node);
2863
+ case "AST_ERB_BEGIN_NODE": return ERBBeginNode.from(node);
2864
+ case "AST_ERB_UNLESS_NODE": return ERBUnlessNode.from(node);
2865
+ case "AST_ERB_YIELD_NODE": return ERBYieldNode.from(node);
2866
+ case "AST_ERB_IN_NODE": return ERBInNode.from(node);
2867
+ default:
2868
+ throw new Error(`Unknown node type: ${node.type}`);
2860
2869
  }
2861
2870
  }
2862
2871
 
@@ -2890,7 +2899,7 @@ class ParseResult extends Result {
2890
2899
  * Determines if the parsing failed.
2891
2900
  * @returns `true` if there are errors, otherwise `false`.
2892
2901
  */
2893
- failed() {
2902
+ get failed() {
2894
2903
  // TODO: this should probably be recursive as noted in the Ruby version
2895
2904
  return this.errors.length > 0 || this.value.errors.length > 0;
2896
2905
  }
@@ -2898,8 +2907,8 @@ class ParseResult extends Result {
2898
2907
  * Determines if the parsing was successful.
2899
2908
  * @returns `true` if there are no errors, otherwise `false`.
2900
2909
  */
2901
- success() {
2902
- return !this.failed();
2910
+ get successful() {
2911
+ return this.errors.length === 0;
2903
2912
  }
2904
2913
  /**
2905
2914
  * Returns a pretty-printed JSON string of the errors.
@@ -3150,5 +3159,5 @@ class Visitor {
3150
3159
  }
3151
3160
  }
3152
3161
 
3153
- export { DocumentNode, ERBBeginNode, ERBBlockNode, ERBCaseMatchNode, ERBCaseNode, ERBContentNode, ERBElseNode, ERBEndNode, ERBEnsureNode, ERBForNode, ERBIfNode, ERBInNode, ERBRescueNode, ERBUnlessNode, ERBUntilNode, ERBWhenNode, ERBWhileNode, ERBYieldNode, HTMLAttributeNameNode, HTMLAttributeNode, HTMLAttributeValueNode, HTMLCloseTagNode, HTMLCommentNode, HTMLDoctypeNode, HTMLElementNode, HTMLOpenTagNode, HTMLSelfCloseTagNode, HTMLTextNode, HerbBackend, LexResult, LiteralNode, Location, MissingClosingTagError, MissingOpeningTagError, Node, ParseResult, Position, QuotesMismatchError, Range, Result, RubyParseError, TagNamesMismatchError, Token, TokenList, UnclosedElementError, UnexpectedError, UnexpectedTokenError, Visitor, VoidElementClosingTagError, WhitespaceNode, _TYPECHECK, convertToUTF8, ensureLibHerbBackend, ensureString, fromSerializedError, fromSerializedNode, isLibHerbBackend };
3162
+ export { DocumentNode, ERBBeginNode, ERBBlockNode, ERBCaseMatchNode, ERBCaseNode, ERBContentNode, ERBElseNode, ERBEndNode, ERBEnsureNode, ERBForNode, ERBIfNode, ERBInNode, ERBRescueNode, ERBUnlessNode, ERBUntilNode, ERBWhenNode, ERBWhileNode, ERBYieldNode, HTMLAttributeNameNode, HTMLAttributeNode, HTMLAttributeValueNode, HTMLCloseTagNode, HTMLCommentNode, HTMLDoctypeNode, HTMLElementNode, HTMLOpenTagNode, HTMLSelfCloseTagNode, HTMLTextNode, HerbBackend, HerbError, HerbWarning, LexResult, LiteralNode, Location, MissingClosingTagError, MissingOpeningTagError, Node, ParseResult, Position, QuotesMismatchError, Range, Result, RubyParseError, TagNamesMismatchError, Token, TokenList, UnclosedElementError, UnexpectedError, UnexpectedTokenError, Visitor, VoidElementClosingTagError, WhitespaceNode, _TYPECHECK, convertToUTF8, ensureLibHerbBackend, ensureString, fromSerializedError, fromSerializedNode, isLibHerbBackend };
3154
3163
  //# sourceMappingURL=herb-core.esm.js.map