@herb-tools/node 0.8.10 → 0.9.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.
Files changed (171) hide show
  1. package/binding.gyp +27 -8
  2. package/dist/herb-node.cjs +41 -12
  3. package/dist/herb-node.cjs.map +1 -1
  4. package/dist/herb-node.esm.js +8 -1
  5. package/dist/herb-node.esm.js.map +1 -1
  6. package/dist/types/node-backend.d.ts +3 -1
  7. package/extension/error_helpers.cpp +598 -73
  8. package/extension/error_helpers.h +20 -3
  9. package/extension/extension_helpers.cpp +40 -35
  10. package/extension/extension_helpers.h +2 -2
  11. package/extension/herb.cpp +194 -64
  12. package/extension/libherb/analyze/action_view/attribute_extraction_helpers.c +303 -0
  13. package/extension/libherb/analyze/action_view/attribute_extraction_helpers.h +36 -0
  14. package/extension/libherb/analyze/action_view/content_tag.c +78 -0
  15. package/extension/libherb/analyze/action_view/link_to.c +167 -0
  16. package/extension/libherb/analyze/action_view/registry.c +83 -0
  17. package/extension/libherb/analyze/action_view/tag.c +70 -0
  18. package/extension/libherb/analyze/action_view/tag_helper_handler.h +43 -0
  19. package/extension/libherb/analyze/action_view/tag_helper_node_builders.c +305 -0
  20. package/extension/libherb/analyze/action_view/tag_helper_node_builders.h +70 -0
  21. package/extension/libherb/analyze/action_view/tag_helpers.c +815 -0
  22. package/extension/libherb/analyze/action_view/tag_helpers.h +38 -0
  23. package/extension/libherb/analyze/action_view/turbo_frame_tag.c +88 -0
  24. package/extension/libherb/analyze/analyze.c +885 -0
  25. package/extension/libherb/{include → analyze}/analyze.h +14 -4
  26. package/extension/libherb/{analyzed_ruby.c → analyze/analyzed_ruby.c} +13 -11
  27. package/extension/libherb/{analyzed_ruby.h → analyze/analyzed_ruby.h} +3 -3
  28. package/extension/libherb/analyze/builders.c +343 -0
  29. package/extension/libherb/analyze/builders.h +27 -0
  30. package/extension/libherb/analyze/conditional_elements.c +594 -0
  31. package/extension/libherb/analyze/conditional_elements.h +9 -0
  32. package/extension/libherb/analyze/conditional_open_tags.c +640 -0
  33. package/extension/libherb/analyze/conditional_open_tags.h +9 -0
  34. package/extension/libherb/analyze/control_type.c +250 -0
  35. package/extension/libherb/analyze/control_type.h +14 -0
  36. package/extension/libherb/{analyze_helpers.c → analyze/helpers.c} +48 -23
  37. package/extension/libherb/{analyze_helpers.h → analyze/helpers.h} +4 -2
  38. package/extension/libherb/analyze/invalid_structures.c +193 -0
  39. package/extension/libherb/analyze/invalid_structures.h +11 -0
  40. package/extension/libherb/{analyze_missing_end.c → analyze/missing_end.c} +33 -22
  41. package/extension/libherb/analyze/parse_errors.c +84 -0
  42. package/extension/libherb/analyze/prism_annotate.c +399 -0
  43. package/extension/libherb/analyze/prism_annotate.h +16 -0
  44. package/extension/libherb/analyze/render_nodes.c +761 -0
  45. package/extension/libherb/analyze/render_nodes.h +11 -0
  46. package/extension/libherb/{analyze_transform.c → analyze/transform.c} +24 -3
  47. package/extension/libherb/ast_node.c +17 -7
  48. package/extension/libherb/ast_node.h +11 -5
  49. package/extension/libherb/ast_nodes.c +760 -388
  50. package/extension/libherb/ast_nodes.h +155 -39
  51. package/extension/libherb/ast_pretty_print.c +265 -7
  52. package/extension/libherb/ast_pretty_print.h +6 -1
  53. package/extension/libherb/element_source.h +3 -8
  54. package/extension/libherb/errors.c +1455 -520
  55. package/extension/libherb/errors.h +207 -56
  56. package/extension/libherb/extract.c +145 -49
  57. package/extension/libherb/extract.h +21 -5
  58. package/extension/libherb/herb.c +52 -34
  59. package/extension/libherb/herb.h +18 -6
  60. package/extension/libherb/herb_prism_node.h +13 -0
  61. package/extension/libherb/html_util.c +241 -12
  62. package/extension/libherb/html_util.h +7 -2
  63. package/extension/libherb/include/analyze/action_view/attribute_extraction_helpers.h +36 -0
  64. package/extension/libherb/include/analyze/action_view/tag_helper_handler.h +43 -0
  65. package/extension/libherb/include/analyze/action_view/tag_helper_node_builders.h +70 -0
  66. package/extension/libherb/include/analyze/action_view/tag_helpers.h +38 -0
  67. package/extension/libherb/{analyze.h → include/analyze/analyze.h} +14 -4
  68. package/extension/libherb/include/{analyzed_ruby.h → analyze/analyzed_ruby.h} +3 -3
  69. package/extension/libherb/include/analyze/builders.h +27 -0
  70. package/extension/libherb/include/analyze/conditional_elements.h +9 -0
  71. package/extension/libherb/include/analyze/conditional_open_tags.h +9 -0
  72. package/extension/libherb/include/analyze/control_type.h +14 -0
  73. package/extension/libherb/include/{analyze_helpers.h → analyze/helpers.h} +4 -2
  74. package/extension/libherb/include/analyze/invalid_structures.h +11 -0
  75. package/extension/libherb/include/analyze/prism_annotate.h +16 -0
  76. package/extension/libherb/include/analyze/render_nodes.h +11 -0
  77. package/extension/libherb/include/ast_node.h +11 -5
  78. package/extension/libherb/include/ast_nodes.h +155 -39
  79. package/extension/libherb/include/ast_pretty_print.h +6 -1
  80. package/extension/libherb/include/element_source.h +3 -8
  81. package/extension/libherb/include/errors.h +207 -56
  82. package/extension/libherb/include/extract.h +21 -5
  83. package/extension/libherb/include/herb.h +18 -6
  84. package/extension/libherb/include/herb_prism_node.h +13 -0
  85. package/extension/libherb/include/html_util.h +7 -2
  86. package/extension/libherb/include/io.h +3 -1
  87. package/extension/libherb/include/lex_helpers.h +29 -0
  88. package/extension/libherb/include/lexer.h +1 -1
  89. package/extension/libherb/include/lexer_peek_helpers.h +87 -13
  90. package/extension/libherb/include/lexer_struct.h +2 -0
  91. package/extension/libherb/include/location.h +2 -1
  92. package/extension/libherb/include/parser.h +28 -2
  93. package/extension/libherb/include/parser_helpers.h +19 -3
  94. package/extension/libherb/include/pretty_print.h +10 -5
  95. package/extension/libherb/include/prism_context.h +45 -0
  96. package/extension/libherb/include/prism_helpers.h +10 -7
  97. package/extension/libherb/include/prism_serialized.h +12 -0
  98. package/extension/libherb/include/token.h +16 -4
  99. package/extension/libherb/include/token_struct.h +10 -3
  100. package/extension/libherb/include/utf8.h +2 -1
  101. package/extension/libherb/include/util/hb_allocator.h +78 -0
  102. package/extension/libherb/include/util/hb_arena.h +6 -1
  103. package/extension/libherb/include/util/hb_arena_debug.h +12 -1
  104. package/extension/libherb/include/util/hb_array.h +7 -3
  105. package/extension/libherb/include/util/hb_buffer.h +6 -4
  106. package/extension/libherb/include/util/hb_foreach.h +79 -0
  107. package/extension/libherb/include/util/hb_narray.h +8 -4
  108. package/extension/libherb/include/util/hb_string.h +56 -9
  109. package/extension/libherb/include/util.h +6 -3
  110. package/extension/libherb/include/version.h +1 -1
  111. package/extension/libherb/io.c +3 -2
  112. package/extension/libherb/io.h +3 -1
  113. package/extension/libherb/lex_helpers.h +29 -0
  114. package/extension/libherb/lexer.c +42 -30
  115. package/extension/libherb/lexer.h +1 -1
  116. package/extension/libherb/lexer_peek_helpers.c +12 -74
  117. package/extension/libherb/lexer_peek_helpers.h +87 -13
  118. package/extension/libherb/lexer_struct.h +2 -0
  119. package/extension/libherb/location.c +2 -2
  120. package/extension/libherb/location.h +2 -1
  121. package/extension/libherb/main.c +53 -28
  122. package/extension/libherb/parser.c +784 -247
  123. package/extension/libherb/parser.h +28 -2
  124. package/extension/libherb/parser_helpers.c +110 -23
  125. package/extension/libherb/parser_helpers.h +19 -3
  126. package/extension/libherb/parser_match_tags.c +130 -49
  127. package/extension/libherb/pretty_print.c +29 -24
  128. package/extension/libherb/pretty_print.h +10 -5
  129. package/extension/libherb/prism_context.h +45 -0
  130. package/extension/libherb/prism_helpers.c +30 -27
  131. package/extension/libherb/prism_helpers.h +10 -7
  132. package/extension/libherb/prism_serialized.h +12 -0
  133. package/extension/libherb/ruby_parser.c +2 -0
  134. package/extension/libherb/token.c +151 -66
  135. package/extension/libherb/token.h +16 -4
  136. package/extension/libherb/token_matchers.c +0 -1
  137. package/extension/libherb/token_struct.h +10 -3
  138. package/extension/libherb/utf8.c +7 -6
  139. package/extension/libherb/utf8.h +2 -1
  140. package/extension/libherb/util/hb_allocator.c +341 -0
  141. package/extension/libherb/util/hb_allocator.h +78 -0
  142. package/extension/libherb/util/hb_arena.c +81 -56
  143. package/extension/libherb/util/hb_arena.h +6 -1
  144. package/extension/libherb/util/hb_arena_debug.c +32 -17
  145. package/extension/libherb/util/hb_arena_debug.h +12 -1
  146. package/extension/libherb/util/hb_array.c +30 -15
  147. package/extension/libherb/util/hb_array.h +7 -3
  148. package/extension/libherb/util/hb_buffer.c +17 -21
  149. package/extension/libherb/util/hb_buffer.h +6 -4
  150. package/extension/libherb/util/hb_foreach.h +79 -0
  151. package/extension/libherb/util/hb_narray.c +22 -7
  152. package/extension/libherb/util/hb_narray.h +8 -4
  153. package/extension/libherb/util/hb_string.c +49 -35
  154. package/extension/libherb/util/hb_string.h +56 -9
  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 +68 -1
  159. package/extension/nodes.cpp +593 -6
  160. package/extension/nodes.h +10 -1
  161. package/package.json +12 -8
  162. package/src/node-backend.ts +11 -1
  163. package/dist/types/index-cjs.d.cts +0 -1
  164. package/extension/libherb/analyze.c +0 -1608
  165. package/extension/libherb/element_source.c +0 -12
  166. package/extension/libherb/include/util/hb_system.h +0 -9
  167. package/extension/libherb/util/hb_system.c +0 -30
  168. package/extension/libherb/util/hb_system.h +0 -9
  169. package/src/index-cjs.cts +0 -22
  170. /package/dist/types/{index-esm.d.mts → index.d.ts} +0 -0
  171. /package/src/{index-esm.mts → index.ts} +0 -0
@@ -0,0 +1,11 @@
1
+ #ifndef HERB_ANALYZE_RENDER_NODES_H
2
+ #define HERB_ANALYZE_RENDER_NODES_H
3
+
4
+ #include "../ast_nodes.h"
5
+ #include "analyze.h"
6
+
7
+ #include <stdbool.h>
8
+
9
+ bool transform_render_nodes(const AST_NODE_T* node, void* data);
10
+
11
+ #endif
@@ -1,8 +1,8 @@
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.10/templates/src/analyze_transform.c.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.9.1/templates/src/analyze/transform.c.erb
3
3
 
4
- #include "include/analyze.h"
5
- #include "include/visitor.h"
4
+ #include "../include/analyze/analyze.h"
5
+ #include "../include/visitor.h"
6
6
 
7
7
  bool transform_erb_nodes(const AST_NODE_T* node, void* data) {
8
8
  analyze_ruby_context_T* context = (analyze_ruby_context_T*) data;
@@ -36,6 +36,13 @@ bool transform_erb_nodes(const AST_NODE_T* node, void* data) {
36
36
  hb_array_free(&old_array);
37
37
  }
38
38
 
39
+ if (node->type == AST_HTML_CONDITIONAL_ELEMENT_NODE) {
40
+ AST_HTML_CONDITIONAL_ELEMENT_NODE_T* html_conditional_element_node = (AST_HTML_CONDITIONAL_ELEMENT_NODE_T*) node;
41
+ hb_array_T* old_array = html_conditional_element_node->body;
42
+ html_conditional_element_node->body = rewrite_node_array((AST_NODE_T*) node, html_conditional_element_node->body, context);
43
+ hb_array_free(&old_array);
44
+ }
45
+
39
46
  if (node->type == AST_HTML_ATTRIBUTE_VALUE_NODE) {
40
47
  AST_HTML_ATTRIBUTE_VALUE_NODE_T* html_attribute_value_node = (AST_HTML_ATTRIBUTE_VALUE_NODE_T*) node;
41
48
  hb_array_T* old_array = html_attribute_value_node->children;
@@ -50,6 +57,13 @@ bool transform_erb_nodes(const AST_NODE_T* node, void* data) {
50
57
  hb_array_free(&old_array);
51
58
  }
52
59
 
60
+ if (node->type == AST_ERB_OPEN_TAG_NODE) {
61
+ AST_ERB_OPEN_TAG_NODE_T* erb_open_tag_node = (AST_ERB_OPEN_TAG_NODE_T*) node;
62
+ hb_array_T* old_array = erb_open_tag_node->children;
63
+ erb_open_tag_node->children = rewrite_node_array((AST_NODE_T*) node, erb_open_tag_node->children, context);
64
+ hb_array_free(&old_array);
65
+ }
66
+
53
67
  if (node->type == AST_HTML_COMMENT_NODE) {
54
68
  AST_HTML_COMMENT_NODE_T* html_comment_node = (AST_HTML_COMMENT_NODE_T*) node;
55
69
  hb_array_T* old_array = html_comment_node->children;
@@ -183,6 +197,13 @@ bool transform_erb_nodes(const AST_NODE_T* node, void* data) {
183
197
  hb_array_free(&old_array);
184
198
  }
185
199
 
200
+ if (node->type == AST_ERB_RENDER_NODE) {
201
+ AST_ERB_RENDER_NODE_T* erb_render_node = (AST_ERB_RENDER_NODE_T*) node;
202
+ hb_array_T* old_array = erb_render_node->locals;
203
+ erb_render_node->locals = rewrite_node_array((AST_NODE_T*) node, erb_render_node->locals, context);
204
+ hb_array_free(&old_array);
205
+ }
206
+
186
207
  if (node->type == AST_ERB_IN_NODE) {
187
208
  AST_ERB_IN_NODE_T* erb_in_node = (AST_ERB_IN_NODE_T*) node;
188
209
  hb_array_T* old_array = erb_in_node->statements;
@@ -2,8 +2,9 @@
2
2
  #include "include/ast_nodes.h"
3
3
  #include "include/errors.h"
4
4
  #include "include/position.h"
5
- #include "include/token.h"
6
5
  #include "include/util.h"
6
+ #include "include/util/hb_allocator.h"
7
+ #include "include/util/hb_string.h"
7
8
  #include "include/visitor.h"
8
9
 
9
10
  #include <prism.h>
@@ -14,7 +15,14 @@ size_t ast_node_sizeof(void) {
14
15
  return sizeof(struct AST_NODE_STRUCT);
15
16
  }
16
17
 
17
- void ast_node_init(AST_NODE_T* node, const ast_node_type_T type, position_T start, position_T end, hb_array_T* errors) {
18
+ void ast_node_init(
19
+ AST_NODE_T* node,
20
+ const ast_node_type_T type,
21
+ position_T start,
22
+ position_T end,
23
+ hb_array_T* errors,
24
+ hb_allocator_T* allocator
25
+ ) {
18
26
  if (!node) { return; }
19
27
 
20
28
  node->type = type;
@@ -22,18 +30,20 @@ void ast_node_init(AST_NODE_T* node, const ast_node_type_T type, position_T star
22
30
  node->location.end = end;
23
31
 
24
32
  if (errors == NULL) {
25
- node->errors = hb_array_init(8);
33
+ node->errors = hb_array_init(0, allocator);
26
34
  } else {
27
35
  node->errors = errors;
28
36
  }
29
37
  }
30
38
 
31
- AST_LITERAL_NODE_T* ast_literal_node_init_from_token(const token_T* token) {
32
- AST_LITERAL_NODE_T* literal = malloc(sizeof(AST_LITERAL_NODE_T));
39
+ AST_LITERAL_NODE_T* ast_literal_node_init_from_token(const token_T* token, hb_allocator_T* allocator) {
40
+ AST_LITERAL_NODE_T* literal = hb_allocator_alloc(allocator, sizeof(AST_LITERAL_NODE_T));
33
41
 
34
- ast_node_init(&literal->base, AST_LITERAL_NODE, token->location.start, token->location.end, NULL);
42
+ if (!literal) { return NULL; }
35
43
 
36
- literal->content = herb_strdup(token->value);
44
+ ast_node_init(&literal->base, AST_LITERAL_NODE, token->location.start, token->location.end, NULL, allocator);
45
+
46
+ literal->content = hb_string_copy(token->value, allocator);
37
47
 
38
48
  return literal;
39
49
  }
@@ -5,19 +5,25 @@
5
5
  #include "errors.h"
6
6
  #include "position.h"
7
7
  #include "token_struct.h"
8
+ #include "util/hb_allocator.h"
8
9
 
9
- void ast_node_init(AST_NODE_T* node, ast_node_type_T type, position_T start, position_T end, hb_array_T* errors);
10
- void ast_node_free(AST_NODE_T* node);
10
+ void ast_node_init(
11
+ AST_NODE_T* node,
12
+ ast_node_type_T type,
13
+ position_T start,
14
+ position_T end,
15
+ hb_array_T* errors,
16
+ hb_allocator_T* allocator
17
+ );
18
+ void ast_node_free(AST_NODE_T* node, hb_allocator_T* allocator);
11
19
 
12
- AST_LITERAL_NODE_T* ast_literal_node_init_from_token(const token_T* token);
20
+ AST_LITERAL_NODE_T* ast_literal_node_init_from_token(const token_T* token, hb_allocator_T* allocator);
13
21
 
14
22
  size_t ast_node_sizeof(void);
15
23
  size_t ast_node_child_count(AST_NODE_T* node);
16
24
 
17
25
  ast_node_type_T ast_node_type(const AST_NODE_T* node);
18
26
 
19
- char* ast_node_name(AST_NODE_T* node);
20
-
21
27
  void ast_node_set_start(AST_NODE_T* node, position_T position);
22
28
  void ast_node_set_end(AST_NODE_T* node, position_T position);
23
29