@herb-tools/node 0.8.9 → 0.9.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.
Files changed (174) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/binding.gyp +26 -8
  3. package/dist/herb-node.cjs +41 -12
  4. package/dist/herb-node.cjs.map +1 -1
  5. package/dist/herb-node.esm.js +8 -1
  6. package/dist/herb-node.esm.js.map +1 -1
  7. package/dist/types/node-backend.d.ts +3 -1
  8. package/extension/error_helpers.cpp +419 -71
  9. package/extension/error_helpers.h +14 -3
  10. package/extension/extension_helpers.cpp +38 -35
  11. package/extension/extension_helpers.h +2 -2
  12. package/extension/herb.cpp +183 -64
  13. package/extension/libherb/analyze/action_view/attribute_extraction_helpers.c +290 -0
  14. package/extension/libherb/analyze/action_view/attribute_extraction_helpers.h +36 -0
  15. package/extension/libherb/analyze/action_view/content_tag.c +70 -0
  16. package/extension/libherb/analyze/action_view/link_to.c +143 -0
  17. package/extension/libherb/analyze/action_view/registry.c +60 -0
  18. package/extension/libherb/analyze/action_view/tag.c +64 -0
  19. package/extension/libherb/analyze/action_view/tag_helper_handler.h +41 -0
  20. package/extension/libherb/analyze/action_view/tag_helper_node_builders.c +305 -0
  21. package/extension/libherb/analyze/action_view/tag_helper_node_builders.h +70 -0
  22. package/extension/libherb/analyze/action_view/tag_helpers.c +748 -0
  23. package/extension/libherb/analyze/action_view/tag_helpers.h +38 -0
  24. package/extension/libherb/analyze/action_view/turbo_frame_tag.c +88 -0
  25. package/extension/libherb/analyze/analyze.c +882 -0
  26. package/extension/libherb/{include → analyze}/analyze.h +14 -4
  27. package/extension/libherb/{analyzed_ruby.c → analyze/analyzed_ruby.c} +13 -11
  28. package/extension/libherb/{analyzed_ruby.h → analyze/analyzed_ruby.h} +3 -3
  29. package/extension/libherb/analyze/builders.c +343 -0
  30. package/extension/libherb/analyze/builders.h +27 -0
  31. package/extension/libherb/analyze/conditional_elements.c +594 -0
  32. package/extension/libherb/analyze/conditional_elements.h +9 -0
  33. package/extension/libherb/analyze/conditional_open_tags.c +640 -0
  34. package/extension/libherb/analyze/conditional_open_tags.h +9 -0
  35. package/extension/libherb/analyze/control_type.c +250 -0
  36. package/extension/libherb/analyze/control_type.h +14 -0
  37. package/extension/libherb/{analyze_helpers.c → analyze/helpers.c} +79 -31
  38. package/extension/libherb/{analyze_helpers.h → analyze/helpers.h} +22 -17
  39. package/extension/libherb/analyze/invalid_structures.c +193 -0
  40. package/extension/libherb/analyze/invalid_structures.h +11 -0
  41. package/extension/libherb/{analyze_missing_end.c → analyze/missing_end.c} +33 -22
  42. package/extension/libherb/analyze/parse_errors.c +84 -0
  43. package/extension/libherb/analyze/prism_annotate.c +397 -0
  44. package/extension/libherb/analyze/prism_annotate.h +16 -0
  45. package/extension/libherb/{analyze_transform.c → analyze/transform.c} +17 -3
  46. package/extension/libherb/ast_node.c +17 -7
  47. package/extension/libherb/ast_node.h +11 -5
  48. package/extension/libherb/ast_nodes.c +663 -388
  49. package/extension/libherb/ast_nodes.h +118 -39
  50. package/extension/libherb/ast_pretty_print.c +191 -7
  51. package/extension/libherb/ast_pretty_print.h +6 -1
  52. package/extension/libherb/element_source.h +3 -8
  53. package/extension/libherb/errors.c +1100 -507
  54. package/extension/libherb/errors.h +155 -54
  55. package/extension/libherb/extract.c +148 -49
  56. package/extension/libherb/extract.h +21 -5
  57. package/extension/libherb/herb.c +52 -34
  58. package/extension/libherb/herb.h +18 -6
  59. package/extension/libherb/herb_prism_node.h +13 -0
  60. package/extension/libherb/html_util.c +241 -12
  61. package/extension/libherb/html_util.h +7 -2
  62. package/extension/libherb/include/analyze/action_view/attribute_extraction_helpers.h +36 -0
  63. package/extension/libherb/include/analyze/action_view/tag_helper_handler.h +41 -0
  64. package/extension/libherb/include/analyze/action_view/tag_helper_node_builders.h +70 -0
  65. package/extension/libherb/include/analyze/action_view/tag_helpers.h +38 -0
  66. package/extension/libherb/{analyze.h → include/analyze/analyze.h} +14 -4
  67. package/extension/libherb/include/{analyzed_ruby.h → analyze/analyzed_ruby.h} +3 -3
  68. package/extension/libherb/include/analyze/builders.h +27 -0
  69. package/extension/libherb/include/analyze/conditional_elements.h +9 -0
  70. package/extension/libherb/include/analyze/conditional_open_tags.h +9 -0
  71. package/extension/libherb/include/analyze/control_type.h +14 -0
  72. package/extension/libherb/include/{analyze_helpers.h → analyze/helpers.h} +22 -17
  73. package/extension/libherb/include/analyze/invalid_structures.h +11 -0
  74. package/extension/libherb/include/analyze/prism_annotate.h +16 -0
  75. package/extension/libherb/include/ast_node.h +11 -5
  76. package/extension/libherb/include/ast_nodes.h +118 -39
  77. package/extension/libherb/include/ast_pretty_print.h +6 -1
  78. package/extension/libherb/include/element_source.h +3 -8
  79. package/extension/libherb/include/errors.h +155 -54
  80. package/extension/libherb/include/extract.h +21 -5
  81. package/extension/libherb/include/herb.h +18 -6
  82. package/extension/libherb/include/herb_prism_node.h +13 -0
  83. package/extension/libherb/include/html_util.h +7 -2
  84. package/extension/libherb/include/io.h +3 -1
  85. package/extension/libherb/include/lex_helpers.h +29 -0
  86. package/extension/libherb/include/lexer.h +1 -1
  87. package/extension/libherb/include/lexer_peek_helpers.h +87 -13
  88. package/extension/libherb/include/lexer_struct.h +2 -0
  89. package/extension/libherb/include/location.h +2 -1
  90. package/extension/libherb/include/parser.h +27 -2
  91. package/extension/libherb/include/parser_helpers.h +19 -3
  92. package/extension/libherb/include/pretty_print.h +10 -5
  93. package/extension/libherb/include/prism_context.h +45 -0
  94. package/extension/libherb/include/prism_helpers.h +10 -7
  95. package/extension/libherb/include/prism_serialized.h +12 -0
  96. package/extension/libherb/include/token.h +16 -4
  97. package/extension/libherb/include/token_struct.h +10 -3
  98. package/extension/libherb/include/utf8.h +2 -1
  99. package/extension/libherb/include/util/hb_allocator.h +78 -0
  100. package/extension/libherb/include/util/hb_arena.h +6 -1
  101. package/extension/libherb/include/util/hb_arena_debug.h +12 -1
  102. package/extension/libherb/include/util/hb_array.h +7 -3
  103. package/extension/libherb/include/util/hb_buffer.h +6 -4
  104. package/extension/libherb/include/util/hb_foreach.h +79 -0
  105. package/extension/libherb/include/util/hb_narray.h +8 -4
  106. package/extension/libherb/include/util/hb_string.h +56 -9
  107. package/extension/libherb/include/util/string.h +11 -0
  108. package/extension/libherb/include/util.h +6 -3
  109. package/extension/libherb/include/version.h +1 -1
  110. package/extension/libherb/io.c +3 -2
  111. package/extension/libherb/io.h +3 -1
  112. package/extension/libherb/lex_helpers.h +29 -0
  113. package/extension/libherb/lexer.c +42 -30
  114. package/extension/libherb/lexer.h +1 -1
  115. package/extension/libherb/lexer_peek_helpers.c +12 -74
  116. package/extension/libherb/lexer_peek_helpers.h +87 -13
  117. package/extension/libherb/lexer_struct.h +2 -0
  118. package/extension/libherb/location.c +2 -2
  119. package/extension/libherb/location.h +2 -1
  120. package/extension/libherb/main.c +79 -66
  121. package/extension/libherb/parser.c +784 -247
  122. package/extension/libherb/parser.h +27 -2
  123. package/extension/libherb/parser_helpers.c +110 -23
  124. package/extension/libherb/parser_helpers.h +19 -3
  125. package/extension/libherb/parser_match_tags.c +110 -49
  126. package/extension/libherb/pretty_print.c +29 -24
  127. package/extension/libherb/pretty_print.h +10 -5
  128. package/extension/libherb/prism_context.h +45 -0
  129. package/extension/libherb/prism_helpers.c +30 -27
  130. package/extension/libherb/prism_helpers.h +10 -7
  131. package/extension/libherb/prism_serialized.h +12 -0
  132. package/extension/libherb/ruby_parser.c +2 -0
  133. package/extension/libherb/token.c +151 -66
  134. package/extension/libherb/token.h +16 -4
  135. package/extension/libherb/token_matchers.c +0 -1
  136. package/extension/libherb/token_struct.h +10 -3
  137. package/extension/libherb/utf8.c +7 -6
  138. package/extension/libherb/utf8.h +2 -1
  139. package/extension/libherb/util/hb_allocator.c +341 -0
  140. package/extension/libherb/util/hb_allocator.h +78 -0
  141. package/extension/libherb/util/hb_arena.c +81 -56
  142. package/extension/libherb/util/hb_arena.h +6 -1
  143. package/extension/libherb/util/hb_arena_debug.c +32 -17
  144. package/extension/libherb/util/hb_arena_debug.h +12 -1
  145. package/extension/libherb/util/hb_array.c +30 -15
  146. package/extension/libherb/util/hb_array.h +7 -3
  147. package/extension/libherb/util/hb_buffer.c +17 -21
  148. package/extension/libherb/util/hb_buffer.h +6 -4
  149. package/extension/libherb/util/hb_foreach.h +79 -0
  150. package/extension/libherb/util/hb_narray.c +22 -7
  151. package/extension/libherb/util/hb_narray.h +8 -4
  152. package/extension/libherb/util/hb_string.c +49 -35
  153. package/extension/libherb/util/hb_string.h +56 -9
  154. package/extension/libherb/util/string.h +11 -0
  155. package/extension/libherb/util.c +21 -11
  156. package/extension/libherb/util.h +6 -3
  157. package/extension/libherb/version.h +1 -1
  158. package/extension/libherb/visitor.c +48 -1
  159. package/extension/nodes.cpp +451 -6
  160. package/extension/nodes.h +8 -1
  161. package/extension/prism/include/prism/ast.h +4 -4
  162. package/extension/prism/include/prism/version.h +2 -2
  163. package/extension/prism/src/prism.c +1 -1
  164. package/package.json +12 -8
  165. package/src/node-backend.ts +11 -1
  166. package/dist/types/index-cjs.d.cts +0 -1
  167. package/extension/libherb/analyze.c +0 -1594
  168. package/extension/libherb/element_source.c +0 -12
  169. package/extension/libherb/include/util/hb_system.h +0 -9
  170. package/extension/libherb/util/hb_system.c +0 -30
  171. package/extension/libherb/util/hb_system.h +0 -9
  172. package/src/index-cjs.cts +0 -22
  173. /package/dist/types/{index-esm.d.mts → index.d.ts} +0 -0
  174. /package/src/{index-esm.mts → index.ts} +0 -0
@@ -4,26 +4,73 @@
4
4
  #include <stdbool.h>
5
5
  #include <stddef.h>
6
6
  #include <stdint.h>
7
+ #include <string.h>
8
+ #include <strings.h>
7
9
 
8
- #include "hb_arena.h"
10
+ #include "hb_allocator.h"
11
+ #include "hb_foreach.h"
9
12
 
10
13
  typedef struct HB_STRING_STRUCT {
11
14
  char* data;
12
15
  uint32_t length;
13
16
  } hb_string_T;
14
17
 
15
- hb_string_T hb_string(const char* null_terminated_c_string);
16
- hb_string_T hb_string_slice(hb_string_T string, uint32_t offset);
17
- bool hb_string_equals(hb_string_T a, hb_string_T b);
18
- bool hb_string_equals_case_insensitive(hb_string_T a, hb_string_T b);
19
- bool hb_string_starts_with(hb_string_T string, hb_string_T expected_prefix);
20
- bool hb_string_is_empty(hb_string_T string);
21
- hb_string_T hb_string_truncate(hb_string_T string, uint32_t max_length);
18
+ #define HB_STRING_EMPTY ((hb_string_T) { .data = "", .length = 0 })
19
+ #define HB_STRING_NULL ((hb_string_T) { .data = NULL, .length = 0 })
20
+
21
+ #define HB_STRING_LITERAL(string) { .data = (char*) (string), .length = (uint32_t) (sizeof(string) - 1) }
22
+
23
+ #define HB_STRING_LIST(...) { HB_FOR_EACH(HB_STRING_LITERAL, __VA_ARGS__) }
24
+
25
+ #define hb_string(string) \
26
+ (__builtin_constant_p(string) \
27
+ ? ((hb_string_T) { .data = (char*) (string), .length = (uint32_t) __builtin_strlen(string) }) \
28
+ : hb_string_from_c_string(string))
29
+
30
+ hb_string_T hb_string_from_c_string(const char* null_terminated_c_string);
31
+
32
+ static inline bool hb_string_is_null(hb_string_T string) {
33
+ return string.data == NULL;
34
+ }
35
+
36
+ static inline bool hb_string_is_empty(hb_string_T string) {
37
+ return string.data == NULL || string.length == 0;
38
+ }
39
+
40
+ static inline hb_string_T hb_string_slice(hb_string_T string, uint32_t offset) {
41
+ if (string.length < offset) { return HB_STRING_NULL; }
42
+
43
+ return (hb_string_T) { .data = string.data + offset, .length = string.length - offset };
44
+ }
22
45
 
46
+ static inline bool hb_string_equals(hb_string_T a, hb_string_T b) {
47
+ if (a.length != b.length) { return false; }
48
+
49
+ return strncmp(a.data, b.data, a.length) == 0;
50
+ }
51
+
52
+ static inline bool hb_string_equals_case_insensitive(hb_string_T a, hb_string_T b) {
53
+ if (a.length != b.length) { return false; }
54
+
55
+ return strncasecmp(a.data, b.data, a.length) == 0;
56
+ }
57
+
58
+ static inline bool hb_string_starts_with(hb_string_T string, hb_string_T expected_prefix) {
59
+ if (hb_string_is_empty(string) || hb_string_is_empty(expected_prefix)) { return false; }
60
+ if (string.length < expected_prefix.length) { return false; }
61
+
62
+ return strncmp(string.data, expected_prefix.data, expected_prefix.length) == 0;
63
+ }
64
+
65
+ hb_string_T hb_string_truncate(hb_string_T string, uint32_t max_length);
23
66
  hb_string_T hb_string_range(hb_string_T string, uint32_t from, uint32_t to);
67
+ hb_string_T hb_string_trim_start(hb_string_T string);
68
+ hb_string_T hb_string_trim_end(hb_string_T string);
69
+ hb_string_T hb_string_trim(hb_string_T string);
70
+ bool hb_string_is_blank(hb_string_T string);
71
+ hb_string_T hb_string_copy(hb_string_T string, hb_allocator_T* allocator);
24
72
 
25
73
  char* hb_string_to_c_string_using_malloc(hb_string_T string);
26
-
27
74
  char* hb_string_to_c_string(hb_arena_T* allocator, hb_string_T string);
28
75
 
29
76
  #endif
@@ -0,0 +1,11 @@
1
+ #ifndef HERB_UTILS_STRING_H
2
+ #define HERB_UTILS_STRING_H
3
+
4
+ #include <stdbool.h>
5
+ #include <string.h>
6
+
7
+ static inline bool string_equals(const char* a, const char* b) {
8
+ return strcmp(a, b) == 0;
9
+ }
10
+
11
+ #endif
@@ -1,4 +1,5 @@
1
1
  #include "include/util.h"
2
+ #include "include/util/hb_allocator.h"
2
3
  #include "include/util/hb_buffer.h"
3
4
  #include "include/util/hb_string.h"
4
5
 
@@ -10,10 +11,14 @@ int is_newline(int character) {
10
11
  return character == '\n' || character == '\r';
11
12
  }
12
13
 
13
- hb_string_T escape_newlines(hb_string_T input) {
14
+ int is_whitespace(int character) {
15
+ return character == ' ' || character == '\t' || character == '\n' || character == '\r';
16
+ }
17
+
18
+ hb_string_T escape_newlines(hb_allocator_T* allocator, hb_string_T input) {
14
19
  hb_buffer_T buffer;
15
20
 
16
- hb_buffer_init(&buffer, input.length);
21
+ hb_buffer_init(&buffer, input.length, allocator);
17
22
 
18
23
  for (size_t i = 0; i < input.length; ++i) {
19
24
  switch (input.data[i]) {
@@ -34,10 +39,10 @@ hb_string_T escape_newlines(hb_string_T input) {
34
39
  return hb_string(buffer.value);
35
40
  }
36
41
 
37
- static hb_string_T wrap_string(hb_string_T input, char character) {
42
+ static hb_string_T wrap_string(hb_allocator_T* allocator, hb_string_T input, char character) {
38
43
  hb_buffer_T buffer;
39
44
 
40
- hb_buffer_init(&buffer, input.length + 2);
45
+ hb_buffer_init(&buffer, input.length + 2, allocator);
41
46
 
42
47
  hb_buffer_append_char(&buffer, character);
43
48
  hb_buffer_append_string(&buffer, input);
@@ -46,15 +51,20 @@ static hb_string_T wrap_string(hb_string_T input, char character) {
46
51
  return hb_string(buffer.value);
47
52
  }
48
53
 
49
- hb_string_T quoted_string(hb_string_T input) {
50
- return wrap_string(input, '"');
54
+ hb_string_T quoted_string(hb_allocator_T* allocator, hb_string_T input) {
55
+ return wrap_string(allocator, input, '"');
51
56
  }
52
57
 
53
- char* herb_strdup(const char* s) {
54
- size_t len = strlen(s) + 1;
55
- char* copy = malloc(len);
58
+ char* convert_underscores_to_dashes(const char* input) {
59
+ if (!input) { return NULL; }
56
60
 
57
- if (copy) { memcpy(copy, s, len); }
61
+ size_t len = strlen(input);
62
+ char* output = calloc(len + 1, sizeof(char));
63
+ if (!output) { return NULL; }
64
+
65
+ for (size_t i = 0; i < len; i++) {
66
+ output[i] = (input[i] == '_') ? '-' : input[i];
67
+ }
58
68
 
59
- return copy;
69
+ return output;
60
70
  }
@@ -5,10 +5,13 @@
5
5
  #include <stdbool.h>
6
6
  #include <stdlib.h>
7
7
 
8
+ struct hb_allocator;
9
+
8
10
  int is_newline(int character);
11
+ int is_whitespace(int character);
12
+ hb_string_T escape_newlines(struct hb_allocator* allocator, hb_string_T input);
13
+ hb_string_T quoted_string(struct hb_allocator* allocator, hb_string_T input);
9
14
 
10
- hb_string_T escape_newlines(hb_string_T input);
11
- hb_string_T quoted_string(hb_string_T input);
12
- char* herb_strdup(const char* s);
15
+ char* convert_underscores_to_dashes(const char* input);
13
16
 
14
17
  #endif
@@ -1,6 +1,6 @@
1
1
  #ifndef HERB_VERSION_H
2
2
  #define HERB_VERSION_H
3
3
 
4
- #define HERB_VERSION "0.8.9"
4
+ #define HERB_VERSION "0.9.0"
5
5
 
6
6
  #endif
@@ -1,5 +1,5 @@
1
1
  // NOTE: This file is generated by the templates/template.rb script and should not
2
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.9/templates/src/visitor.c.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.9.0/templates/src/visitor.c.erb
3
3
 
4
4
  #include <stdio.h>
5
5
 
@@ -42,6 +42,15 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
42
42
 
43
43
  } break;
44
44
 
45
+ case AST_HTML_CONDITIONAL_OPEN_TAG_NODE: {
46
+ const AST_HTML_CONDITIONAL_OPEN_TAG_NODE_T* html_conditional_open_tag_node = ((const AST_HTML_CONDITIONAL_OPEN_TAG_NODE_T *) node);
47
+
48
+ if (html_conditional_open_tag_node->conditional != NULL) {
49
+ herb_visit_node((AST_NODE_T *) html_conditional_open_tag_node->conditional, visitor, data);
50
+ }
51
+
52
+ } break;
53
+
45
54
  case AST_HTML_CLOSE_TAG_NODE: {
46
55
  const AST_HTML_CLOSE_TAG_NODE_T* html_close_tag_node = ((const AST_HTML_CLOSE_TAG_NODE_T *) node);
47
56
 
@@ -72,6 +81,33 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
72
81
 
73
82
  } break;
74
83
 
84
+ case AST_HTML_CONDITIONAL_ELEMENT_NODE: {
85
+ const AST_HTML_CONDITIONAL_ELEMENT_NODE_T* html_conditional_element_node = ((const AST_HTML_CONDITIONAL_ELEMENT_NODE_T *) node);
86
+
87
+ if (html_conditional_element_node->open_conditional != NULL) {
88
+ herb_visit_node((AST_NODE_T *) html_conditional_element_node->open_conditional, visitor, data);
89
+ }
90
+
91
+ if (html_conditional_element_node->open_tag != NULL) {
92
+ herb_visit_node((AST_NODE_T *) html_conditional_element_node->open_tag, visitor, data);
93
+ }
94
+
95
+ if (html_conditional_element_node->body != NULL) {
96
+ for (size_t index = 0; index < hb_array_size(html_conditional_element_node->body); index++) {
97
+ herb_visit_node(hb_array_get(html_conditional_element_node->body, index), visitor, data);
98
+ }
99
+ }
100
+
101
+ if (html_conditional_element_node->close_tag != NULL) {
102
+ herb_visit_node((AST_NODE_T *) html_conditional_element_node->close_tag, visitor, data);
103
+ }
104
+
105
+ if (html_conditional_element_node->close_conditional != NULL) {
106
+ herb_visit_node((AST_NODE_T *) html_conditional_element_node->close_conditional, visitor, data);
107
+ }
108
+
109
+ } break;
110
+
75
111
  case AST_HTML_ATTRIBUTE_VALUE_NODE: {
76
112
  const AST_HTML_ATTRIBUTE_VALUE_NODE_T* html_attribute_value_node = ((const AST_HTML_ATTRIBUTE_VALUE_NODE_T *) node);
77
113
 
@@ -107,6 +143,17 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
107
143
 
108
144
  } break;
109
145
 
146
+ case AST_ERB_OPEN_TAG_NODE: {
147
+ const AST_ERB_OPEN_TAG_NODE_T* erb_open_tag_node = ((const AST_ERB_OPEN_TAG_NODE_T *) node);
148
+
149
+ if (erb_open_tag_node->children != NULL) {
150
+ for (size_t index = 0; index < hb_array_size(erb_open_tag_node->children); index++) {
151
+ herb_visit_node(hb_array_get(erb_open_tag_node->children, index), visitor, data);
152
+ }
153
+ }
154
+
155
+ } break;
156
+
110
157
  case AST_HTML_COMMENT_NODE: {
111
158
  const AST_HTML_COMMENT_NODE_T* html_comment_node = ((const AST_HTML_COMMENT_NODE_T *) node);
112
159