@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.
- package/CHANGELOG.md +19 -0
- package/binding.gyp +26 -8
- package/dist/herb-node.cjs +41 -12
- package/dist/herb-node.cjs.map +1 -1
- package/dist/herb-node.esm.js +8 -1
- package/dist/herb-node.esm.js.map +1 -1
- package/dist/types/node-backend.d.ts +3 -1
- package/extension/error_helpers.cpp +419 -71
- package/extension/error_helpers.h +14 -3
- package/extension/extension_helpers.cpp +38 -35
- package/extension/extension_helpers.h +2 -2
- package/extension/herb.cpp +183 -64
- package/extension/libherb/analyze/action_view/attribute_extraction_helpers.c +290 -0
- package/extension/libherb/analyze/action_view/attribute_extraction_helpers.h +36 -0
- package/extension/libherb/analyze/action_view/content_tag.c +70 -0
- package/extension/libherb/analyze/action_view/link_to.c +143 -0
- package/extension/libherb/analyze/action_view/registry.c +60 -0
- package/extension/libherb/analyze/action_view/tag.c +64 -0
- package/extension/libherb/analyze/action_view/tag_helper_handler.h +41 -0
- package/extension/libherb/analyze/action_view/tag_helper_node_builders.c +305 -0
- package/extension/libherb/analyze/action_view/tag_helper_node_builders.h +70 -0
- package/extension/libherb/analyze/action_view/tag_helpers.c +748 -0
- package/extension/libherb/analyze/action_view/tag_helpers.h +38 -0
- package/extension/libherb/analyze/action_view/turbo_frame_tag.c +88 -0
- package/extension/libherb/analyze/analyze.c +882 -0
- package/extension/libherb/{include → analyze}/analyze.h +14 -4
- package/extension/libherb/{analyzed_ruby.c → analyze/analyzed_ruby.c} +13 -11
- package/extension/libherb/{analyzed_ruby.h → analyze/analyzed_ruby.h} +3 -3
- package/extension/libherb/analyze/builders.c +343 -0
- package/extension/libherb/analyze/builders.h +27 -0
- package/extension/libherb/analyze/conditional_elements.c +594 -0
- package/extension/libherb/analyze/conditional_elements.h +9 -0
- package/extension/libherb/analyze/conditional_open_tags.c +640 -0
- package/extension/libherb/analyze/conditional_open_tags.h +9 -0
- package/extension/libherb/analyze/control_type.c +250 -0
- package/extension/libherb/analyze/control_type.h +14 -0
- package/extension/libherb/{analyze_helpers.c → analyze/helpers.c} +79 -31
- package/extension/libherb/{analyze_helpers.h → analyze/helpers.h} +22 -17
- package/extension/libherb/analyze/invalid_structures.c +193 -0
- package/extension/libherb/analyze/invalid_structures.h +11 -0
- package/extension/libherb/{analyze_missing_end.c → analyze/missing_end.c} +33 -22
- package/extension/libherb/analyze/parse_errors.c +84 -0
- package/extension/libherb/analyze/prism_annotate.c +397 -0
- package/extension/libherb/analyze/prism_annotate.h +16 -0
- package/extension/libherb/{analyze_transform.c → analyze/transform.c} +17 -3
- package/extension/libherb/ast_node.c +17 -7
- package/extension/libherb/ast_node.h +11 -5
- package/extension/libherb/ast_nodes.c +663 -388
- package/extension/libherb/ast_nodes.h +118 -39
- package/extension/libherb/ast_pretty_print.c +191 -7
- package/extension/libherb/ast_pretty_print.h +6 -1
- package/extension/libherb/element_source.h +3 -8
- package/extension/libherb/errors.c +1100 -507
- package/extension/libherb/errors.h +155 -54
- package/extension/libherb/extract.c +148 -49
- package/extension/libherb/extract.h +21 -5
- package/extension/libherb/herb.c +52 -34
- package/extension/libherb/herb.h +18 -6
- package/extension/libherb/herb_prism_node.h +13 -0
- package/extension/libherb/html_util.c +241 -12
- package/extension/libherb/html_util.h +7 -2
- package/extension/libherb/include/analyze/action_view/attribute_extraction_helpers.h +36 -0
- package/extension/libherb/include/analyze/action_view/tag_helper_handler.h +41 -0
- package/extension/libherb/include/analyze/action_view/tag_helper_node_builders.h +70 -0
- package/extension/libherb/include/analyze/action_view/tag_helpers.h +38 -0
- package/extension/libherb/{analyze.h → include/analyze/analyze.h} +14 -4
- package/extension/libherb/include/{analyzed_ruby.h → analyze/analyzed_ruby.h} +3 -3
- package/extension/libherb/include/analyze/builders.h +27 -0
- package/extension/libherb/include/analyze/conditional_elements.h +9 -0
- package/extension/libherb/include/analyze/conditional_open_tags.h +9 -0
- package/extension/libherb/include/analyze/control_type.h +14 -0
- package/extension/libherb/include/{analyze_helpers.h → analyze/helpers.h} +22 -17
- package/extension/libherb/include/analyze/invalid_structures.h +11 -0
- package/extension/libherb/include/analyze/prism_annotate.h +16 -0
- package/extension/libherb/include/ast_node.h +11 -5
- package/extension/libherb/include/ast_nodes.h +118 -39
- package/extension/libherb/include/ast_pretty_print.h +6 -1
- package/extension/libherb/include/element_source.h +3 -8
- package/extension/libherb/include/errors.h +155 -54
- package/extension/libherb/include/extract.h +21 -5
- package/extension/libherb/include/herb.h +18 -6
- package/extension/libherb/include/herb_prism_node.h +13 -0
- package/extension/libherb/include/html_util.h +7 -2
- package/extension/libherb/include/io.h +3 -1
- package/extension/libherb/include/lex_helpers.h +29 -0
- package/extension/libherb/include/lexer.h +1 -1
- package/extension/libherb/include/lexer_peek_helpers.h +87 -13
- package/extension/libherb/include/lexer_struct.h +2 -0
- package/extension/libherb/include/location.h +2 -1
- package/extension/libherb/include/parser.h +27 -2
- package/extension/libherb/include/parser_helpers.h +19 -3
- package/extension/libherb/include/pretty_print.h +10 -5
- package/extension/libherb/include/prism_context.h +45 -0
- package/extension/libherb/include/prism_helpers.h +10 -7
- package/extension/libherb/include/prism_serialized.h +12 -0
- package/extension/libherb/include/token.h +16 -4
- package/extension/libherb/include/token_struct.h +10 -3
- package/extension/libherb/include/utf8.h +2 -1
- package/extension/libherb/include/util/hb_allocator.h +78 -0
- package/extension/libherb/include/util/hb_arena.h +6 -1
- package/extension/libherb/include/util/hb_arena_debug.h +12 -1
- package/extension/libherb/include/util/hb_array.h +7 -3
- package/extension/libherb/include/util/hb_buffer.h +6 -4
- package/extension/libherb/include/util/hb_foreach.h +79 -0
- package/extension/libherb/include/util/hb_narray.h +8 -4
- package/extension/libherb/include/util/hb_string.h +56 -9
- package/extension/libherb/include/util/string.h +11 -0
- package/extension/libherb/include/util.h +6 -3
- package/extension/libherb/include/version.h +1 -1
- package/extension/libherb/io.c +3 -2
- package/extension/libherb/io.h +3 -1
- package/extension/libherb/lex_helpers.h +29 -0
- package/extension/libherb/lexer.c +42 -30
- package/extension/libherb/lexer.h +1 -1
- package/extension/libherb/lexer_peek_helpers.c +12 -74
- package/extension/libherb/lexer_peek_helpers.h +87 -13
- package/extension/libherb/lexer_struct.h +2 -0
- package/extension/libherb/location.c +2 -2
- package/extension/libherb/location.h +2 -1
- package/extension/libherb/main.c +79 -66
- package/extension/libherb/parser.c +784 -247
- package/extension/libherb/parser.h +27 -2
- package/extension/libherb/parser_helpers.c +110 -23
- package/extension/libherb/parser_helpers.h +19 -3
- package/extension/libherb/parser_match_tags.c +110 -49
- package/extension/libherb/pretty_print.c +29 -24
- package/extension/libherb/pretty_print.h +10 -5
- package/extension/libherb/prism_context.h +45 -0
- package/extension/libherb/prism_helpers.c +30 -27
- package/extension/libherb/prism_helpers.h +10 -7
- package/extension/libherb/prism_serialized.h +12 -0
- package/extension/libherb/ruby_parser.c +2 -0
- package/extension/libherb/token.c +151 -66
- package/extension/libherb/token.h +16 -4
- package/extension/libherb/token_matchers.c +0 -1
- package/extension/libherb/token_struct.h +10 -3
- package/extension/libherb/utf8.c +7 -6
- package/extension/libherb/utf8.h +2 -1
- package/extension/libherb/util/hb_allocator.c +341 -0
- package/extension/libherb/util/hb_allocator.h +78 -0
- package/extension/libherb/util/hb_arena.c +81 -56
- package/extension/libherb/util/hb_arena.h +6 -1
- package/extension/libherb/util/hb_arena_debug.c +32 -17
- package/extension/libherb/util/hb_arena_debug.h +12 -1
- package/extension/libherb/util/hb_array.c +30 -15
- package/extension/libherb/util/hb_array.h +7 -3
- package/extension/libherb/util/hb_buffer.c +17 -21
- package/extension/libherb/util/hb_buffer.h +6 -4
- package/extension/libherb/util/hb_foreach.h +79 -0
- package/extension/libherb/util/hb_narray.c +22 -7
- package/extension/libherb/util/hb_narray.h +8 -4
- package/extension/libherb/util/hb_string.c +49 -35
- package/extension/libherb/util/hb_string.h +56 -9
- package/extension/libherb/util/string.h +11 -0
- package/extension/libherb/util.c +21 -11
- package/extension/libherb/util.h +6 -3
- package/extension/libherb/version.h +1 -1
- package/extension/libherb/visitor.c +48 -1
- package/extension/nodes.cpp +451 -6
- package/extension/nodes.h +8 -1
- package/extension/prism/include/prism/ast.h +4 -4
- package/extension/prism/include/prism/version.h +2 -2
- package/extension/prism/src/prism.c +1 -1
- package/package.json +12 -8
- package/src/node-backend.ts +11 -1
- package/dist/types/index-cjs.d.cts +0 -1
- package/extension/libherb/analyze.c +0 -1594
- package/extension/libherb/element_source.c +0 -12
- package/extension/libherb/include/util/hb_system.h +0 -9
- package/extension/libherb/util/hb_system.c +0 -30
- package/extension/libherb/util/hb_system.h +0 -9
- package/src/index-cjs.cts +0 -22
- /package/dist/types/{index-esm.d.mts → index.d.ts} +0 -0
- /package/src/{index-esm.mts → index.ts} +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#ifndef HERB_ANALYZE_TAG_HELPERS_H
|
|
2
|
+
#define HERB_ANALYZE_TAG_HELPERS_H
|
|
3
|
+
|
|
4
|
+
#include "../../ast_nodes.h"
|
|
5
|
+
#include "../../position.h"
|
|
6
|
+
#include "../../util/hb_array.h"
|
|
7
|
+
#include "../analyze.h"
|
|
8
|
+
#include "tag_helper_handler.h"
|
|
9
|
+
|
|
10
|
+
#include <prism.h>
|
|
11
|
+
#include <stdbool.h>
|
|
12
|
+
|
|
13
|
+
typedef struct {
|
|
14
|
+
const pm_node_t* tag_helper_node;
|
|
15
|
+
const uint8_t* source;
|
|
16
|
+
pm_parser_t* parser;
|
|
17
|
+
tag_helper_info_T* info;
|
|
18
|
+
const tag_helper_handler_T* matched_handler;
|
|
19
|
+
bool found;
|
|
20
|
+
} tag_helper_search_data_T;
|
|
21
|
+
|
|
22
|
+
bool search_tag_helper_node(const pm_node_t* node, void* data);
|
|
23
|
+
|
|
24
|
+
position_T prism_location_to_position_with_offset(
|
|
25
|
+
const pm_location_t* pm_location,
|
|
26
|
+
const char* original_source,
|
|
27
|
+
size_t erb_content_offset,
|
|
28
|
+
const uint8_t* erb_content_source
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
position_T byte_offset_to_position(const char* source, size_t offset);
|
|
32
|
+
|
|
33
|
+
size_t calculate_byte_offset_from_position(const char* source, position_T position);
|
|
34
|
+
|
|
35
|
+
void transform_tag_helper_blocks(const AST_NODE_T* node, analyze_ruby_context_T* context);
|
|
36
|
+
bool transform_tag_helper_nodes(const AST_NODE_T* node, void* data);
|
|
37
|
+
|
|
38
|
+
#endif
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#include "../../include/analyze/action_view/tag_helper_handler.h"
|
|
2
|
+
|
|
3
|
+
#include <prism.h>
|
|
4
|
+
#include <stdbool.h>
|
|
5
|
+
#include <stdlib.h>
|
|
6
|
+
#include <string.h>
|
|
7
|
+
|
|
8
|
+
bool detect_turbo_frame_tag(pm_call_node_t* call_node, pm_parser_t* parser) {
|
|
9
|
+
if (!call_node || !call_node->name) { return false; }
|
|
10
|
+
|
|
11
|
+
pm_constant_t* constant = pm_constant_pool_id_to_constant(&parser->constant_pool, call_node->name);
|
|
12
|
+
return constant && constant->length == 15 && strncmp((const char*) constant->start, "turbo_frame_tag", 15) == 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
char* extract_turbo_frame_tag_name(pm_call_node_t* call_node, pm_parser_t* parser, hb_allocator_T* allocator) {
|
|
16
|
+
(void) call_node;
|
|
17
|
+
(void) parser;
|
|
18
|
+
|
|
19
|
+
return hb_allocator_strdup(allocator, "turbo-frame");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
char* extract_turbo_frame_tag_content(pm_call_node_t* call_node, pm_parser_t* parser, hb_allocator_T* allocator) {
|
|
23
|
+
(void) call_node;
|
|
24
|
+
(void) parser;
|
|
25
|
+
(void) allocator;
|
|
26
|
+
|
|
27
|
+
return NULL;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
char* extract_turbo_frame_tag_id(pm_call_node_t* call_node, pm_parser_t* parser, hb_allocator_T* allocator) {
|
|
31
|
+
if (!call_node || !call_node->arguments) { return NULL; }
|
|
32
|
+
|
|
33
|
+
pm_arguments_node_t* arguments = call_node->arguments;
|
|
34
|
+
if (!arguments->arguments.size) { return NULL; }
|
|
35
|
+
|
|
36
|
+
pm_node_t* first_argument = arguments->arguments.nodes[0];
|
|
37
|
+
|
|
38
|
+
if (first_argument->type == PM_STRING_NODE) {
|
|
39
|
+
pm_string_node_t* string_node = (pm_string_node_t*) first_argument;
|
|
40
|
+
size_t length = pm_string_length(&string_node->unescaped);
|
|
41
|
+
|
|
42
|
+
return hb_allocator_strndup(allocator, (const char*) pm_string_source(&string_node->unescaped), length);
|
|
43
|
+
} else if (first_argument->type == PM_SYMBOL_NODE) {
|
|
44
|
+
pm_symbol_node_t* symbol_node = (pm_symbol_node_t*) first_argument;
|
|
45
|
+
size_t length = pm_string_length(&symbol_node->unescaped);
|
|
46
|
+
|
|
47
|
+
return hb_allocator_strndup(allocator, (const char*) pm_string_source(&symbol_node->unescaped), length);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
size_t source_length = first_argument->location.end - first_argument->location.start;
|
|
51
|
+
const char* source = (const char*) first_argument->location.start;
|
|
52
|
+
|
|
53
|
+
if (first_argument->type == PM_CALL_NODE) {
|
|
54
|
+
pm_call_node_t* call = (pm_call_node_t*) first_argument;
|
|
55
|
+
pm_constant_t* call_constant = pm_constant_pool_id_to_constant(&parser->constant_pool, call->name);
|
|
56
|
+
|
|
57
|
+
if (call_constant && call_constant->length == 6 && strncmp((const char*) call_constant->start, "dom_id", 6) == 0) {
|
|
58
|
+
return hb_allocator_strndup(allocator, source, source_length);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const char* prefix = "dom_id(";
|
|
63
|
+
const char* suffix = ")";
|
|
64
|
+
|
|
65
|
+
size_t prefix_length = strlen(prefix);
|
|
66
|
+
size_t suffix_length = strlen(suffix);
|
|
67
|
+
size_t total_length = prefix_length + source_length + suffix_length;
|
|
68
|
+
char* result = hb_allocator_alloc(allocator, total_length + 1);
|
|
69
|
+
|
|
70
|
+
memcpy(result, prefix, prefix_length);
|
|
71
|
+
memcpy(result + prefix_length, source, source_length);
|
|
72
|
+
memcpy(result + prefix_length + source_length, suffix, suffix_length);
|
|
73
|
+
result[total_length] = '\0';
|
|
74
|
+
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
bool turbo_frame_tag_supports_block(void) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const tag_helper_handler_T turbo_frame_tag_handler = { .name = "turbo_frame_tag",
|
|
83
|
+
.source =
|
|
84
|
+
HB_STRING_LITERAL("Turbo::FramesHelper#turbo_frame_tag"),
|
|
85
|
+
.detect = detect_turbo_frame_tag,
|
|
86
|
+
.extract_tag_name = extract_turbo_frame_tag_name,
|
|
87
|
+
.extract_content = extract_turbo_frame_tag_content,
|
|
88
|
+
.supports_block = turbo_frame_tag_supports_block };
|