herb 0.11.1-x86-linux-gnu → 0.11.3-x86-linux-gnu
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.
- checksums.yaml +4 -4
- data/Makefile +2 -0
- data/Rakefile +4 -2
- data/config.yml +13 -8
- data/ext/herb/error_helpers.c +3 -3
- data/ext/herb/extconf.rb +8 -31
- data/ext/herb/nodes.c +75 -75
- data/ext/herb/parser_options_helpers.c +26 -0
- data/lib/herb/3.2/herb.so +0 -0
- data/lib/herb/3.3/herb.so +0 -0
- data/lib/herb/3.4/herb.so +0 -0
- data/lib/herb/4.0/herb.so +0 -0
- data/lib/herb/analysis/partial_index.rb +1 -1
- data/lib/herb/analysis/partial_resolution.rb +27 -0
- data/lib/herb/ast/erb_render_node.rb +6 -2
- data/lib/herb/ast/helpers.rb +1 -1
- data/lib/herb/cli.rb +7 -3
- data/lib/herb/configuration.rb +11 -1
- data/lib/herb/dev/classifier.rb +1 -1
- data/lib/herb/dev/runner.rb +5 -2
- data/lib/herb/engine/compiler.rb +44 -12
- data/lib/herb/engine/slots/dynamics_compiler.rb +54 -15
- data/lib/herb/engine/slots/state_compiler.rb +9 -1
- data/lib/herb/engine/slots/state_overrides.rb +17 -3
- data/lib/herb/engine/slots/subtree_compiler.rb +1 -1
- data/lib/herb/engine/slots/visitor.rb +69 -11
- data/lib/herb/engine/visitors/instrumentation_visitor.rb +18 -6
- data/lib/herb/engine.rb +11 -1
- data/lib/herb/errors.rb +7 -7
- data/lib/herb/parser_options.rb +6 -3
- data/lib/herb/project.rb +19 -8
- data/lib/herb/version.rb +1 -1
- data/lib/herb.rb +1 -1
- data/sig/herb/analysis/partial_resolution.rbs +8 -0
- data/sig/herb/ast/erb_render_node.rbs +2 -0
- data/sig/herb/configuration.rbs +3 -0
- data/sig/herb/dev/runner.rbs +2 -2
- data/sig/herb/engine/compiler.rbs +9 -0
- data/sig/herb/engine/slots/dynamics_compiler.rbs +24 -7
- data/sig/herb/engine/slots/state_compiler.rbs +3 -0
- data/sig/herb/engine/slots/state_overrides.rbs +11 -2
- data/sig/herb/engine/slots/visitor.rbs +21 -0
- data/sig/herb/engine/visitors/instrumentation_visitor.rbs +5 -1
- data/sig/herb/engine.rbs +2 -0
- data/sig/herb/errors.rbs +2 -2
- data/sig/herb/parser_options.rbs +6 -4
- data/sig/herb.rbs +2 -2
- data/sig/serialized_ast_errors.rbs +1 -1
- data/src/analyze/action_view/attribute_extraction_helpers.c +40 -21
- data/src/analyze/action_view/generated_handlers.c +36 -36
- data/src/analyze/action_view/image_tag.c +7 -3
- data/src/analyze/action_view/javascript_include_tag.c +6 -3
- data/src/analyze/action_view/link_to.c +23 -23
- data/src/analyze/action_view/registry.c +7 -3
- data/src/analyze/action_view/tag_helper_node_builders.c +6 -13
- data/src/analyze/action_view/tag_helpers.c +160 -97
- data/src/analyze/action_view/turbo_frame_tag.c +5 -4
- data/src/analyze/analyze.c +52 -29
- data/src/analyze/analyze_helpers.c +161 -188
- data/src/analyze/analyzed_ruby.c +8 -7
- data/src/analyze/control_type.c +29 -22
- data/src/analyze/herb_directives.c +16 -20
- data/src/analyze/iteration_nodes.c +69 -24
- data/src/analyze/parse_errors.c +32 -22
- data/src/analyze/postfix_conditionals.c +23 -13
- data/src/analyze/prism_annotate.c +29 -28
- data/src/analyze/render_nodes.c +239 -78
- data/src/analyze/strict_locals.c +14 -15
- data/src/analyze/ternary_conditionals.c +14 -10
- data/src/diff/herb_diff_children.c +1 -1
- data/src/diff/herb_diff_nodes.c +1 -9
- data/src/diff/herb_hash_tree.c +1 -1
- data/src/errors.c +17 -22
- data/src/extract.c +47 -7
- data/src/herb.c +10 -8
- data/src/include/analyze/action_view/tag_helper_handler.h +1 -1
- data/src/include/analyze/action_view/tag_helper_node_builders.h +1 -0
- data/src/include/analyze/action_view/tag_helpers.h +1 -1
- data/src/include/analyze/analyze.h +3 -2
- data/src/include/analyze/analyzed_ruby.h +4 -2
- data/src/include/analyze/helpers.h +6 -6
- data/src/include/errors.h +3 -3
- data/src/include/herb.h +3 -2
- data/src/include/parser/parser_options.h +5 -0
- data/src/include/prism/prism_context.h +12 -12
- data/src/include/prism/prism_helpers.h +30 -0
- data/src/include/prism_version.h +11 -0
- data/src/include/version.h +1 -1
- data/src/lexer/token.c +2 -2
- data/src/parser/dot_notation.c +15 -5
- data/src/parser/parser_helpers.c +1 -2
- data/src/parser.c +9 -8
- data/src/parser_options_defaults.c +1 -0
- data/src/prism/prism_helpers.c +84 -50
- data/src/prism/ruby_parser.c +20 -20
- data/templates/ext/herb/nodes.c.erb +5 -5
- data/templates/ext/herb/parser_options_helpers.c.erb +33 -0
- data/templates/java/nodes.c.erb +6 -6
- data/templates/java/parser_options_helpers.c.erb +41 -2
- data/templates/java/parser_options_helpers.h.erb +2 -1
- data/templates/javascript/packages/node/extension/nodes.cpp.erb +5 -5
- data/templates/javascript/packages/node/extension/parser_options_helpers.cpp.erb +34 -2
- data/templates/javascript/packages/node/extension/parser_options_helpers.h.erb +1 -1
- data/templates/lib/herb/parser_options.rb.erb +1 -1
- data/templates/rust/src/prism/generated_deserialize.rs.erb +90 -44
- data/templates/rust/src/prism/generated_prettyprint.rs.erb +18 -27
- data/templates/src/analyze/action_view/generated_handlers.c.erb +23 -22
- data/templates/src/diff/herb_diff_nodes.c.erb +1 -9
- data/templates/src/diff/herb_hash_tree.c.erb +1 -1
- data/templates/src/errors.c.erb +2 -2
- data/templates/src/include/parser/parser_options.h.erb +10 -0
- data/templates/src/include/prism_version.h.erb +17 -0
- data/templates/src/parser_options_defaults.c.erb +1 -1
- data/templates/template.rb +17 -2
- data/templates/wasm/nodes.cpp.erb +5 -5
- data/templates/wasm/parser_options_helpers.cpp.erb +24 -0
- data/vendor/prism/Rakefile +76 -7
- data/vendor/prism/config.yml +174 -161
- data/vendor/prism/include/prism/arena.h +45 -0
- data/vendor/prism/include/prism/arena.hpp +42 -0
- data/vendor/prism/include/prism/ast.h +2738 -611
- data/vendor/prism/include/prism/ast.hpp +641 -0
- data/vendor/prism/include/prism/buffer.h +60 -0
- data/vendor/prism/include/prism/buffer.hpp +55 -0
- data/vendor/prism/include/prism/comments.h +72 -0
- data/vendor/prism/include/prism/compiler/accel.h +26 -0
- data/vendor/prism/include/prism/compiler/align.h +36 -0
- data/vendor/prism/include/prism/compiler/assume.h +25 -0
- data/vendor/prism/include/prism/compiler/branch.h +26 -0
- data/vendor/prism/include/prism/compiler/bswap.h +46 -0
- data/vendor/prism/include/prism/compiler/cplusplus.hpp +16 -0
- data/vendor/prism/include/prism/compiler/endianness.h +34 -0
- data/vendor/prism/include/prism/compiler/exceptions.hpp +17 -0
- data/vendor/prism/include/prism/compiler/exported.h +24 -0
- data/vendor/prism/include/prism/compiler/fallthrough.h +22 -0
- data/vendor/prism/include/prism/compiler/filesystem.h +32 -0
- data/vendor/prism/include/prism/compiler/flex_array.h +19 -0
- data/vendor/prism/include/prism/compiler/force_inline.h +21 -0
- data/vendor/prism/include/prism/compiler/format.h +27 -0
- data/vendor/prism/include/prism/compiler/inline.h +17 -0
- data/vendor/prism/include/prism/compiler/lifetimebound.hpp +25 -0
- data/vendor/prism/include/prism/compiler/nodiscard.h +22 -0
- data/vendor/prism/include/prism/compiler/nonnull.h +18 -0
- data/vendor/prism/include/prism/compiler/unused.h +18 -0
- data/vendor/prism/include/prism/constant_pool.h +106 -0
- data/vendor/prism/include/prism/diagnostic.h +55 -402
- data/vendor/prism/include/prism/errors_format.h +61 -0
- data/vendor/prism/include/prism/excludes.h +29 -0
- data/vendor/prism/include/prism/integer.h +41 -0
- data/vendor/prism/include/prism/internal/allocator.h +68 -0
- data/vendor/prism/include/prism/internal/allocator_debug.h +88 -0
- data/vendor/prism/include/prism/internal/arena.h +108 -0
- data/vendor/prism/include/prism/internal/bit.h +42 -0
- data/vendor/prism/include/prism/internal/buffer.h +94 -0
- data/vendor/prism/include/prism/internal/char.h +145 -0
- data/vendor/prism/include/prism/internal/comments.h +54 -0
- data/vendor/prism/include/prism/internal/constant_pool.h +152 -0
- data/vendor/prism/include/prism/internal/diagnostic.h +389 -0
- data/vendor/prism/include/prism/{encoding.h → internal/encoding.h} +27 -68
- data/vendor/prism/include/prism/internal/integer.h +68 -0
- data/vendor/prism/include/prism/internal/isinf.h +16 -0
- data/vendor/prism/include/prism/internal/line_offset_list.h +34 -0
- data/vendor/prism/include/prism/{util/pm_list.h → internal/list.h} +11 -52
- data/vendor/prism/include/prism/internal/magic_comments.h +23 -0
- data/vendor/prism/include/prism/internal/memchr.h +15 -0
- data/vendor/prism/include/prism/internal/node.h +42 -0
- data/vendor/prism/include/prism/internal/options.h +232 -0
- data/vendor/prism/include/prism/internal/parser.h +1015 -0
- data/vendor/prism/include/prism/internal/regexp.h +26 -0
- data/vendor/prism/include/prism/internal/serialize.h +39 -0
- data/vendor/prism/include/prism/internal/source.h +72 -0
- data/vendor/prism/include/prism/internal/static_literals.h +60 -0
- data/vendor/prism/include/prism/internal/stringy.h +30 -0
- data/vendor/prism/include/prism/{util/pm_strncasecmp.h → internal/strncasecmp.h} +3 -17
- data/vendor/prism/include/prism/{util/pm_strpbrk.h → internal/strpbrk.h} +7 -20
- data/vendor/prism/include/prism/internal/tokens.h +11 -0
- data/vendor/prism/include/prism/internal/xxh3.h +16 -0
- data/vendor/prism/include/prism/json.h +40 -0
- data/vendor/prism/include/prism/line_offset_list.h +69 -0
- data/vendor/prism/include/prism/magic_comments.h +53 -0
- data/vendor/prism/include/prism/node.h +59 -49
- data/vendor/prism/include/prism/node.hpp +272 -0
- data/vendor/prism/include/prism/node_type.hpp +38 -0
- data/vendor/prism/include/prism/options.h +154 -279
- data/vendor/prism/include/prism/options.hpp +43 -0
- data/vendor/prism/include/prism/parser.h +367 -870
- data/vendor/prism/include/prism/parser.hpp +274 -0
- data/vendor/prism/include/prism/prettyprint.h +14 -9
- data/vendor/prism/include/prism/serialize.h +123 -0
- data/vendor/prism/include/prism/source.h +163 -0
- data/vendor/prism/include/prism/stream.h +36 -0
- data/vendor/prism/include/prism/string_query.h +82 -0
- data/vendor/prism/include/prism/stringy.h +61 -0
- data/vendor/prism/include/prism/stringy.hpp +31 -0
- data/vendor/prism/include/prism/version.h +20 -3
- data/vendor/prism/include/prism.h +35 -320
- data/vendor/prism/include/prism.hpp +24 -0
- data/vendor/prism/src/arena.c +122 -0
- data/vendor/prism/src/{util/pm_buffer.c → buffer.c} +53 -21
- data/vendor/prism/src/{util/pm_char.c → char.c} +28 -57
- data/vendor/prism/src/comments.c +455 -0
- data/vendor/prism/src/constant_pool.c +406 -0
- data/vendor/prism/src/diagnostic.c +120 -68
- data/vendor/prism/src/encoding.c +8 -3
- data/vendor/prism/src/errors_format.c +519 -0
- data/vendor/prism/src/{util/pm_integer.c → integer.c} +38 -22
- data/vendor/prism/src/json.c +5733 -0
- data/vendor/prism/src/line_offset_list.c +100 -0
- data/vendor/prism/src/list.c +24 -0
- data/vendor/prism/src/{util/pm_memchr.c → memchr.c} +8 -6
- data/vendor/prism/src/node.c +3465 -7787
- data/vendor/prism/src/options.c +161 -54
- data/vendor/prism/src/parser.c +371 -0
- data/vendor/prism/src/prettyprint.c +421 -354
- data/vendor/prism/src/prism.c +8522 -7280
- data/vendor/prism/src/regexp.c +960 -45
- data/vendor/prism/src/serialize.c +2434 -2048
- data/vendor/prism/src/source.c +524 -0
- data/vendor/prism/src/static_literals.c +303 -360
- data/vendor/prism/src/string_query.c +180 -0
- data/vendor/prism/src/stringy.c +61 -0
- data/vendor/prism/src/{util/pm_strncasecmp.c → strncasecmp.c} +5 -4
- data/vendor/prism/src/strpbrk.c +447 -0
- data/vendor/prism/src/{token_type.c → tokens.c} +39 -18
- data/vendor/prism/src/xxh3.c +292 -0
- data/vendor/prism/templates/ext/prism/api_node.c.erb +58 -44
- data/vendor/prism/templates/include/prism/ast.h.erb +67 -17
- data/vendor/prism/templates/include/prism/ast.hpp.erb +31 -0
- data/vendor/prism/templates/include/prism/internal/diagnostic.h.erb +60 -0
- data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/AbstractNodeVisitor.java.erb +1 -1
- data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/Loader.java.erb +232 -133
- data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/Nodes.java.erb +62 -23
- data/vendor/prism/templates/javascript/src/deserialize.js.erb +153 -146
- data/vendor/prism/templates/javascript/src/nodes.js.erb +4 -9
- data/vendor/prism/templates/lib/prism/compiler.rb.erb +14 -5
- data/vendor/prism/templates/lib/prism/dispatcher.rb.erb +20 -12
- data/vendor/prism/templates/lib/prism/dot_visitor.rb.erb +37 -11
- data/vendor/prism/templates/lib/prism/dsl.rb.erb +43 -4
- data/vendor/prism/templates/lib/prism/inspect_visitor.rb.erb +26 -10
- data/vendor/prism/templates/lib/prism/mutation_compiler.rb.erb +5 -2
- data/vendor/prism/templates/lib/prism/node.rb.erb +283 -105
- data/vendor/prism/templates/lib/prism/reflection.rb.erb +11 -2
- data/vendor/prism/templates/lib/prism/serialize.rb.erb +291 -134
- data/vendor/prism/templates/lib/prism/visitor.rb.erb +18 -0
- data/vendor/prism/templates/src/diagnostic.c.erb +114 -63
- data/vendor/prism/templates/src/json.c.erb +130 -0
- data/vendor/prism/templates/src/node.c.erb +79 -236
- data/vendor/prism/templates/src/prettyprint.c.erb +24 -13
- data/vendor/prism/templates/src/serialize.c.erb +369 -183
- data/vendor/prism/templates/src/{token_type.c.erb → tokens.c.erb} +22 -11
- data/vendor/prism/templates/template.rb +193 -91
- metadata +100 -42
- data/vendor/prism/include/prism/defines.h +0 -260
- data/vendor/prism/include/prism/pack.h +0 -163
- data/vendor/prism/include/prism/regexp.h +0 -43
- data/vendor/prism/include/prism/static_literals.h +0 -121
- data/vendor/prism/include/prism/util/pm_buffer.h +0 -236
- data/vendor/prism/include/prism/util/pm_char.h +0 -204
- data/vendor/prism/include/prism/util/pm_constant_pool.h +0 -218
- data/vendor/prism/include/prism/util/pm_integer.h +0 -130
- data/vendor/prism/include/prism/util/pm_memchr.h +0 -29
- data/vendor/prism/include/prism/util/pm_newline_list.h +0 -113
- data/vendor/prism/include/prism/util/pm_string.h +0 -200
- data/vendor/prism/src/pack.c +0 -509
- data/vendor/prism/src/util/pm_constant_pool.c +0 -342
- data/vendor/prism/src/util/pm_list.c +0 -49
- data/vendor/prism/src/util/pm_newline_list.c +0 -125
- data/vendor/prism/src/util/pm_string.c +0 -381
- data/vendor/prism/src/util/pm_strpbrk.c +0 -206
- data/vendor/prism/templates/include/prism/diagnostic.h.erb +0 -130
- data/vendor/prism/templates/rbi/prism/dsl.rbi.erb +0 -68
- data/vendor/prism/templates/rbi/prism/node.rbi.erb +0 -167
- data/vendor/prism/templates/rbi/prism/visitor.rbi.erb +0 -18
- data/vendor/prism/templates/sig/prism/_private/dot_visitor.rbs.erb +0 -45
- data/vendor/prism/templates/sig/prism/dsl.rbs.erb +0 -31
- data/vendor/prism/templates/sig/prism/mutation_compiler.rbs.erb +0 -7
- data/vendor/prism/templates/sig/prism/node.rbs.erb +0 -136
- data/vendor/prism/templates/sig/prism/visitor.rbs.erb +0 -17
- data/vendor/prism/templates/sig/prism.rbs.erb +0 -92
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
#include "../../include/util/util.h"
|
|
19
19
|
#include "../../include/visitor.h"
|
|
20
20
|
|
|
21
|
+
#include "../../include/prism/prism_helpers.h"
|
|
22
|
+
|
|
21
23
|
#include <prism.h>
|
|
22
24
|
#include <stdbool.h>
|
|
23
25
|
#include <stdlib.h>
|
|
@@ -42,7 +44,9 @@ extern char* wrap_in_stylesheet_path(const char*, size_t, const char*, hb_alloca
|
|
|
42
44
|
extern bool stylesheet_link_tag_source_is_url(const char*, size_t);
|
|
43
45
|
|
|
44
46
|
typedef struct {
|
|
45
|
-
|
|
47
|
+
pm_arena_t* arena;
|
|
48
|
+
pm_parser_t* parser;
|
|
49
|
+
pm_options_t* options;
|
|
46
50
|
pm_node_t* root;
|
|
47
51
|
const uint8_t* prism_source;
|
|
48
52
|
char* content_string;
|
|
@@ -60,46 +64,42 @@ typedef struct {
|
|
|
60
64
|
} local_read_search_T;
|
|
61
65
|
|
|
62
66
|
static void append_local_read_constant(local_read_search_T* search, pm_constant_id_t constant_id) {
|
|
63
|
-
pm_constant_t* constant =
|
|
67
|
+
const pm_constant_t* constant = pm_parser_constant(search->scope->parser, constant_id);
|
|
68
|
+
|
|
69
|
+
if (!constant || pm_constant_length(constant) == 0) { return; }
|
|
64
70
|
|
|
65
|
-
|
|
71
|
+
size_t length = pm_constant_length(constant);
|
|
66
72
|
|
|
67
73
|
for (size_t index = 0; index < hb_array_size(search->constants); index++) {
|
|
68
|
-
pm_constant_t* existing = hb_array_get(search->constants, index);
|
|
74
|
+
const pm_constant_t* existing = hb_array_get(search->constants, index);
|
|
69
75
|
|
|
70
|
-
if (existing && existing
|
|
71
|
-
&& memcmp(existing
|
|
76
|
+
if (existing && pm_constant_length(existing) == length
|
|
77
|
+
&& memcmp(pm_constant_start(existing), pm_constant_start(constant), length) == 0) {
|
|
72
78
|
return;
|
|
73
79
|
}
|
|
74
80
|
}
|
|
75
81
|
|
|
76
|
-
hb_array_append(search->constants, constant);
|
|
82
|
+
hb_array_append(search->constants, (void*) constant);
|
|
77
83
|
}
|
|
78
84
|
|
|
79
|
-
static
|
|
85
|
+
static pm_visit_result_t search_local_variable_reads(const pm_node_t* node, void* data) {
|
|
80
86
|
local_read_search_T* search = (local_read_search_T*) data;
|
|
81
|
-
const uint8_t* base = (const uint8_t*) search->scope->buffer.value;
|
|
82
87
|
|
|
83
|
-
size_t start =
|
|
84
|
-
size_t end = (
|
|
88
|
+
size_t start = node->location.start;
|
|
89
|
+
size_t end = herb_prism_location_end(node->location);
|
|
85
90
|
|
|
86
|
-
if (end <= search->from || start >= search->to) { return
|
|
91
|
+
if (end <= search->from || start >= search->to) { return PM_VISIT_SKIP; }
|
|
87
92
|
|
|
88
93
|
if (PM_NODE_TYPE(node) == PM_LOCAL_VARIABLE_READ_NODE && start >= search->from && end <= search->to) {
|
|
89
94
|
append_local_read_constant(search, ((pm_local_variable_read_node_t*) node)->name);
|
|
90
95
|
}
|
|
91
96
|
|
|
92
|
-
return
|
|
97
|
+
return PM_VISIT_DESCEND;
|
|
93
98
|
}
|
|
94
99
|
|
|
95
|
-
static
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
size_t from,
|
|
99
|
-
size_t to
|
|
100
|
-
) {
|
|
101
|
-
if (!context || !context->tag_helper_scope || !context->tag_helper_scope->root) { return false; }
|
|
102
|
-
if (to <= from) { return false; }
|
|
100
|
+
static pm_options_t* build_scope_options_from_context(analyze_ruby_context_T* context, size_t from, size_t to) {
|
|
101
|
+
if (!context || !context->tag_helper_scope || !context->tag_helper_scope->root) { return NULL; }
|
|
102
|
+
if (to <= from) { return NULL; }
|
|
103
103
|
|
|
104
104
|
local_read_search_T search = { .scope = context->tag_helper_scope,
|
|
105
105
|
.constants = hb_array_init(4, context->allocator),
|
|
@@ -109,27 +109,34 @@ static bool build_scope_options_from_context(
|
|
|
109
109
|
pm_visit_node(context->tag_helper_scope->root, search_local_variable_reads, &search);
|
|
110
110
|
|
|
111
111
|
size_t locals_count = hb_array_size(search.constants);
|
|
112
|
-
|
|
112
|
+
pm_options_t* options = NULL;
|
|
113
113
|
|
|
114
|
-
if (locals_count > 0
|
|
115
|
-
|
|
114
|
+
if (locals_count > 0) {
|
|
115
|
+
options = pm_options_new();
|
|
116
|
+
herb_prism_options_set_ruby_version(options, context->options);
|
|
117
|
+
|
|
118
|
+
if (pm_options_scopes_init(options, 1)) {
|
|
119
|
+
pm_options_scope_t* scope = pm_options_scope_mut(options, 0);
|
|
120
|
+
pm_options_scope_init(scope, locals_count);
|
|
116
121
|
|
|
117
|
-
if (pm_options_scope_init(scope, locals_count)) {
|
|
118
122
|
for (size_t index = 0; index < locals_count; index++) {
|
|
119
|
-
pm_constant_t* constant = hb_array_get(search.constants, index);
|
|
123
|
+
const pm_constant_t* constant = hb_array_get(search.constants, index);
|
|
120
124
|
|
|
121
|
-
|
|
125
|
+
pm_string_init(
|
|
126
|
+
pm_options_scope_local_mut(scope, index),
|
|
127
|
+
pm_constant_start(constant),
|
|
128
|
+
pm_constant_length(constant)
|
|
129
|
+
);
|
|
122
130
|
}
|
|
123
|
-
|
|
124
|
-
built = true;
|
|
125
131
|
} else {
|
|
126
132
|
pm_options_free(options);
|
|
133
|
+
options = NULL;
|
|
127
134
|
}
|
|
128
135
|
}
|
|
129
136
|
|
|
130
137
|
hb_array_free(&search.constants);
|
|
131
138
|
|
|
132
|
-
return
|
|
139
|
+
return options;
|
|
133
140
|
}
|
|
134
141
|
|
|
135
142
|
static bool symbol_node_equals(pm_node_t* node, const char* name) {
|
|
@@ -176,6 +183,15 @@ static bool asset_tag_resolves_at_render_time(pm_call_node_t* call_node, const c
|
|
|
176
183
|
return false;
|
|
177
184
|
}
|
|
178
185
|
|
|
186
|
+
static const pm_node_t* sole_top_level_expression(const pm_node_t* root) {
|
|
187
|
+
if (!root || root->type != PM_PROGRAM_NODE) { return NULL; }
|
|
188
|
+
|
|
189
|
+
const pm_statements_node_t* statements = ((const pm_program_node_t*) root)->statements;
|
|
190
|
+
if (!statements || statements->body.size != 1) { return NULL; }
|
|
191
|
+
|
|
192
|
+
return statements->body.nodes[0];
|
|
193
|
+
}
|
|
194
|
+
|
|
179
195
|
static tag_helper_parse_context_T* parse_tag_helper_content(
|
|
180
196
|
const char* content_string,
|
|
181
197
|
const char* original_source,
|
|
@@ -195,22 +211,27 @@ static tag_helper_parse_context_T* parse_tag_helper_content(
|
|
|
195
211
|
|
|
196
212
|
size_t content_length = strlen(parse_context->content_string);
|
|
197
213
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
build_scope_options_from_context(context, &options, erb_content_offset, erb_content_offset + content_length);
|
|
201
|
-
|
|
202
|
-
pm_parser_init(
|
|
203
|
-
&parse_context->parser,
|
|
204
|
-
parse_context->prism_source,
|
|
205
|
-
content_length,
|
|
206
|
-
has_scope_options ? &options : NULL
|
|
207
|
-
);
|
|
208
|
-
parse_context->root = pm_parse(&parse_context->parser);
|
|
214
|
+
parse_context->options =
|
|
215
|
+
build_scope_options_from_context(context, erb_content_offset, erb_content_offset + content_length);
|
|
209
216
|
|
|
210
|
-
|
|
217
|
+
parse_context->arena = pm_arena_new();
|
|
218
|
+
if (parse_context->options) {
|
|
219
|
+
parse_context->parser =
|
|
220
|
+
pm_parser_new(parse_context->arena, parse_context->prism_source, content_length, parse_context->options);
|
|
221
|
+
} else {
|
|
222
|
+
parse_context->parser = herb_prism_parser_new(
|
|
223
|
+
parse_context->arena,
|
|
224
|
+
parse_context->prism_source,
|
|
225
|
+
content_length,
|
|
226
|
+
context ? context->options : NULL
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
parse_context->root = pm_parse(parse_context->parser);
|
|
211
230
|
|
|
212
231
|
if (!parse_context->root) {
|
|
213
|
-
pm_parser_free(
|
|
232
|
+
pm_parser_free(parse_context->parser);
|
|
233
|
+
pm_arena_free(parse_context->arena);
|
|
234
|
+
if (parse_context->options) { pm_options_free(parse_context->options); }
|
|
214
235
|
hb_allocator_dealloc(allocator, parse_context->content_string);
|
|
215
236
|
hb_allocator_dealloc(allocator, parse_context);
|
|
216
237
|
return NULL;
|
|
@@ -220,16 +241,20 @@ static tag_helper_parse_context_T* parse_tag_helper_content(
|
|
|
220
241
|
|
|
221
242
|
tag_helper_search_data_T search = { .tag_helper_node = NULL,
|
|
222
243
|
.source = parse_context->prism_source,
|
|
223
|
-
.parser =
|
|
244
|
+
.parser = parse_context->parser,
|
|
224
245
|
.info = parse_context->info,
|
|
225
246
|
.found = false };
|
|
226
|
-
|
|
247
|
+
|
|
248
|
+
const pm_node_t* expression = sole_top_level_expression(parse_context->root);
|
|
249
|
+
|
|
250
|
+
if (expression) { search_tag_helper_node(expression, &search); }
|
|
227
251
|
|
|
228
252
|
if (!search.found
|
|
229
253
|
|| asset_tag_resolves_at_render_time(parse_context->info->call_node, search.matched_handler->name)) {
|
|
230
254
|
tag_helper_info_free(&parse_context->info);
|
|
231
|
-
|
|
232
|
-
|
|
255
|
+
pm_parser_free(parse_context->parser);
|
|
256
|
+
pm_arena_free(parse_context->arena);
|
|
257
|
+
if (parse_context->options) { pm_options_free(parse_context->options); }
|
|
233
258
|
hb_allocator_dealloc(allocator, parse_context->content_string);
|
|
234
259
|
hb_allocator_dealloc(allocator, parse_context);
|
|
235
260
|
return NULL;
|
|
@@ -245,8 +270,9 @@ static void free_tag_helper_parse_context(tag_helper_parse_context_T* parse_cont
|
|
|
245
270
|
hb_allocator_T* allocator = parse_context->info ? parse_context->info->allocator : NULL;
|
|
246
271
|
|
|
247
272
|
tag_helper_info_free(&parse_context->info);
|
|
248
|
-
|
|
249
|
-
|
|
273
|
+
pm_parser_free(parse_context->parser);
|
|
274
|
+
pm_arena_free(parse_context->arena);
|
|
275
|
+
if (parse_context->options) { pm_options_free(parse_context->options); }
|
|
250
276
|
|
|
251
277
|
if (allocator) {
|
|
252
278
|
hb_allocator_dealloc(allocator, parse_context->content_string);
|
|
@@ -254,7 +280,7 @@ static void free_tag_helper_parse_context(tag_helper_parse_context_T* parse_cont
|
|
|
254
280
|
}
|
|
255
281
|
}
|
|
256
282
|
|
|
257
|
-
|
|
283
|
+
pm_visit_result_t search_tag_helper_node(const pm_node_t* node, void* data) {
|
|
258
284
|
tag_helper_search_data_T* search_data = (tag_helper_search_data_T*) data;
|
|
259
285
|
|
|
260
286
|
if (node->type == PM_CALL_NODE) {
|
|
@@ -280,16 +306,12 @@ bool search_tag_helper_node(const pm_node_t* node, void* data) {
|
|
|
280
306
|
search_data->info->has_block = handlers[i]->supports_block();
|
|
281
307
|
}
|
|
282
308
|
|
|
283
|
-
return
|
|
309
|
+
return PM_VISIT_SKIP;
|
|
284
310
|
}
|
|
285
311
|
}
|
|
286
|
-
|
|
287
|
-
return false;
|
|
288
312
|
}
|
|
289
313
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
return search_data->found;
|
|
314
|
+
return PM_VISIT_SKIP;
|
|
293
315
|
}
|
|
294
316
|
|
|
295
317
|
position_T byte_offset_to_position(const char* source, size_t offset) {
|
|
@@ -321,9 +343,11 @@ position_T prism_location_to_position_with_offset(
|
|
|
321
343
|
) {
|
|
322
344
|
position_T default_position = { .line = 1, .column = 1 };
|
|
323
345
|
|
|
324
|
-
if (!pm_location || !pm_location
|
|
346
|
+
if (!pm_location || !herb_prism_location_assigned(*pm_location) || !original_source || !erb_content_source) {
|
|
347
|
+
return default_position;
|
|
348
|
+
}
|
|
325
349
|
|
|
326
|
-
size_t offset_in_erb =
|
|
350
|
+
size_t offset_in_erb = pm_location->start;
|
|
327
351
|
size_t total_offset = erb_content_offset + offset_in_erb;
|
|
328
352
|
|
|
329
353
|
if (strnlen(original_source, total_offset) < total_offset) {
|
|
@@ -375,7 +399,7 @@ static void prism_node_location_to_positions(
|
|
|
375
399
|
parse_context->prism_source
|
|
376
400
|
);
|
|
377
401
|
|
|
378
|
-
pm_location_t end_location = { .start = location
|
|
402
|
+
pm_location_t end_location = { .start = herb_prism_location_end(*location), .length = 0 };
|
|
379
403
|
*out_end = prism_location_to_position_with_offset(
|
|
380
404
|
&end_location,
|
|
381
405
|
parse_context->original_source,
|
|
@@ -394,7 +418,7 @@ static void calculate_tag_name_positions(
|
|
|
394
418
|
*out_start = default_start;
|
|
395
419
|
*out_end = default_end;
|
|
396
420
|
|
|
397
|
-
if (parse_context->info->call_node && parse_context->info->call_node->message_loc
|
|
421
|
+
if (parse_context->info->call_node && herb_prism_location_assigned(parse_context->info->call_node->message_loc)) {
|
|
398
422
|
prism_node_location_to_positions(&parse_context->info->call_node->message_loc, parse_context, out_start, out_end);
|
|
399
423
|
}
|
|
400
424
|
}
|
|
@@ -405,6 +429,7 @@ static const char* IMAGE_TAG_PATH_OPTIONS[] = { "skip_pipeline", NULL };
|
|
|
405
429
|
|
|
406
430
|
static char* extract_path_options_from_keyword_hash(
|
|
407
431
|
pm_call_node_t* call_node,
|
|
432
|
+
const uint8_t* source,
|
|
408
433
|
const char** option_names,
|
|
409
434
|
hb_allocator_T* allocator
|
|
410
435
|
) {
|
|
@@ -449,12 +474,18 @@ static char* extract_path_options_from_keyword_hash(
|
|
|
449
474
|
if (!first) { hb_buffer_append(&buffer, ", "); }
|
|
450
475
|
first = false;
|
|
451
476
|
|
|
452
|
-
|
|
453
|
-
|
|
477
|
+
hb_buffer_append_with_length(
|
|
478
|
+
&buffer,
|
|
479
|
+
(const char*) (source + assoc->key->location.start),
|
|
480
|
+
assoc->key->location.length
|
|
481
|
+
);
|
|
454
482
|
hb_buffer_append(&buffer, " ");
|
|
455
483
|
|
|
456
|
-
|
|
457
|
-
|
|
484
|
+
hb_buffer_append_with_length(
|
|
485
|
+
&buffer,
|
|
486
|
+
(const char*) (source + assoc->value->location.start),
|
|
487
|
+
assoc->value->location.length
|
|
488
|
+
);
|
|
458
489
|
}
|
|
459
490
|
|
|
460
491
|
if (first) {
|
|
@@ -512,8 +543,11 @@ static hb_array_T* prepend_stylesheet_link_tag_attributes(
|
|
|
512
543
|
size_t length = pm_string_length(&string_node->unescaped);
|
|
513
544
|
source_value = hb_allocator_strndup(allocator, (const char*) pm_string_source(&string_node->unescaped), length);
|
|
514
545
|
} else {
|
|
515
|
-
|
|
516
|
-
|
|
546
|
+
source_value = hb_allocator_strndup(
|
|
547
|
+
allocator,
|
|
548
|
+
(const char*) (parse_context->prism_source + source_argument->location.start),
|
|
549
|
+
source_argument->location.length
|
|
550
|
+
);
|
|
517
551
|
}
|
|
518
552
|
|
|
519
553
|
if (!source_value) { return attributes; }
|
|
@@ -523,7 +557,7 @@ static hb_array_T* prepend_stylesheet_link_tag_attributes(
|
|
|
523
557
|
|
|
524
558
|
size_t source_length = strlen(source_value);
|
|
525
559
|
bool is_url = stylesheet_link_tag_source_is_url(source_value, source_length);
|
|
526
|
-
bool source_is_path_helper = is_route_helper_node(source_argument,
|
|
560
|
+
bool source_is_path_helper = is_route_helper_node(source_argument, parse_context->parser);
|
|
527
561
|
|
|
528
562
|
char* href_value = source_value;
|
|
529
563
|
|
|
@@ -603,6 +637,7 @@ static AST_NODE_T* transform_tag_helper_with_attributes(
|
|
|
603
637
|
if (attributes && handler->name && strcmp(handler->name, "javascript_include_tag") == 0) {
|
|
604
638
|
path_options = extract_path_options_from_keyword_hash(
|
|
605
639
|
parse_context->info->call_node,
|
|
640
|
+
parse_context->prism_source,
|
|
606
641
|
JAVASCRIPT_INCLUDE_TAG_PATH_OPTIONS,
|
|
607
642
|
allocator
|
|
608
643
|
);
|
|
@@ -616,6 +651,7 @@ static AST_NODE_T* transform_tag_helper_with_attributes(
|
|
|
616
651
|
if (attributes && handler->name && strcmp(handler->name, "stylesheet_link_tag") == 0) {
|
|
617
652
|
path_options = extract_path_options_from_keyword_hash(
|
|
618
653
|
parse_context->info->call_node,
|
|
654
|
+
parse_context->prism_source,
|
|
619
655
|
STYLESHEET_LINK_TAG_PATH_OPTIONS,
|
|
620
656
|
allocator
|
|
621
657
|
);
|
|
@@ -627,8 +663,12 @@ static AST_NODE_T* transform_tag_helper_with_attributes(
|
|
|
627
663
|
}
|
|
628
664
|
|
|
629
665
|
if (attributes && handler->name && strcmp(handler->name, "image_tag") == 0) {
|
|
630
|
-
path_options =
|
|
631
|
-
|
|
666
|
+
path_options = extract_path_options_from_keyword_hash(
|
|
667
|
+
parse_context->info->call_node,
|
|
668
|
+
parse_context->prism_source,
|
|
669
|
+
IMAGE_TAG_PATH_OPTIONS,
|
|
670
|
+
allocator
|
|
671
|
+
);
|
|
632
672
|
discard_attribute_by_name(attributes, "skip-pipeline", allocator);
|
|
633
673
|
|
|
634
674
|
AST_NODE_T* size_node = remove_attribute_by_name(attributes, "size");
|
|
@@ -722,7 +762,7 @@ static AST_NODE_T* transform_tag_helper_with_attributes(
|
|
|
722
762
|
bool content_is_ruby_expression = false;
|
|
723
763
|
|
|
724
764
|
if (parse_context->info->call_node && handler->extract_content) {
|
|
725
|
-
helper_content = handler->extract_content(parse_context->info->call_node,
|
|
765
|
+
helper_content = handler->extract_content(parse_context->info->call_node, parse_context->parser, allocator);
|
|
726
766
|
|
|
727
767
|
if (helper_content) {
|
|
728
768
|
pm_call_node_t* call = parse_context->info->call_node;
|
|
@@ -751,8 +791,8 @@ static AST_NODE_T* transform_tag_helper_with_attributes(
|
|
|
751
791
|
}
|
|
752
792
|
}
|
|
753
793
|
|
|
754
|
-
if (detect_turbo_frame_tag(parse_context->info->call_node,
|
|
755
|
-
char* id_value = extract_turbo_frame_tag_id(parse_context->info->call_node,
|
|
794
|
+
if (detect_turbo_frame_tag(parse_context->info->call_node, parse_context->parser)) {
|
|
795
|
+
char* id_value = extract_turbo_frame_tag_id(parse_context->info->call_node, parse_context->parser, allocator);
|
|
756
796
|
|
|
757
797
|
if (id_value) {
|
|
758
798
|
if (!attributes) { attributes = hb_array_init(4, allocator); }
|
|
@@ -780,10 +820,10 @@ static AST_NODE_T* transform_tag_helper_with_attributes(
|
|
|
780
820
|
}
|
|
781
821
|
}
|
|
782
822
|
|
|
783
|
-
if (detect_javascript_include_tag(parse_context->info->call_node,
|
|
823
|
+
if (detect_javascript_include_tag(parse_context->info->call_node, parse_context->parser)
|
|
784
824
|
&& parse_context->info->call_node->arguments && parse_context->info->call_node->arguments->arguments.size >= 1) {
|
|
785
825
|
char* source_value =
|
|
786
|
-
extract_javascript_include_tag_src(parse_context->info->call_node,
|
|
826
|
+
extract_javascript_include_tag_src(parse_context->info->call_node, parse_context->parser, allocator);
|
|
787
827
|
|
|
788
828
|
if (source_value) {
|
|
789
829
|
if (!attributes) { attributes = hb_array_init(4, allocator); }
|
|
@@ -821,9 +861,9 @@ static AST_NODE_T* transform_tag_helper_with_attributes(
|
|
|
821
861
|
}
|
|
822
862
|
}
|
|
823
863
|
|
|
824
|
-
if (detect_image_tag(parse_context->info->call_node,
|
|
864
|
+
if (detect_image_tag(parse_context->info->call_node, parse_context->parser)
|
|
825
865
|
&& parse_context->info->call_node->arguments && parse_context->info->call_node->arguments->arguments.size >= 1) {
|
|
826
|
-
char* source_value = extract_image_tag_src(parse_context->info->call_node,
|
|
866
|
+
char* source_value = extract_image_tag_src(parse_context->info->call_node, parse_context->parser, allocator);
|
|
827
867
|
|
|
828
868
|
if (source_value) {
|
|
829
869
|
if (!attributes) { attributes = hb_array_init(4, allocator); }
|
|
@@ -832,7 +872,7 @@ static AST_NODE_T* transform_tag_helper_with_attributes(
|
|
|
832
872
|
position_T source_start, source_end;
|
|
833
873
|
prism_node_location_to_positions(&first_argument->location, parse_context, &source_start, &source_end);
|
|
834
874
|
bool source_is_string = (first_argument->type == PM_STRING_NODE);
|
|
835
|
-
bool source_is_path_helper = is_route_helper_node(first_argument,
|
|
875
|
+
bool source_is_path_helper = is_route_helper_node(first_argument, parse_context->parser);
|
|
836
876
|
|
|
837
877
|
size_t source_length = strlen(source_value);
|
|
838
878
|
bool is_url = image_tag_source_is_url(source_value, source_length);
|
|
@@ -865,7 +905,7 @@ static AST_NODE_T* transform_tag_helper_with_attributes(
|
|
|
865
905
|
}
|
|
866
906
|
}
|
|
867
907
|
|
|
868
|
-
if (detect_stylesheet_link_tag(parse_context->info->call_node,
|
|
908
|
+
if (detect_stylesheet_link_tag(parse_context->info->call_node, parse_context->parser)
|
|
869
909
|
&& parse_context->info->call_node->arguments && parse_context->info->call_node->arguments->arguments.size >= 1) {
|
|
870
910
|
pm_node_t* first_argument = parse_context->info->call_node->arguments->arguments.nodes[0];
|
|
871
911
|
|
|
@@ -1056,8 +1096,11 @@ static AST_NODE_T* create_javascript_include_tag_element(
|
|
|
1056
1096
|
size_t length = pm_string_length(&string_node->unescaped);
|
|
1057
1097
|
source_value = hb_allocator_strndup(allocator, (const char*) pm_string_source(&string_node->unescaped), length);
|
|
1058
1098
|
} else {
|
|
1059
|
-
|
|
1060
|
-
|
|
1099
|
+
source_value = hb_allocator_strndup(
|
|
1100
|
+
allocator,
|
|
1101
|
+
(const char*) (parse_context->prism_source + source_argument->location.start),
|
|
1102
|
+
source_argument->location.length
|
|
1103
|
+
);
|
|
1061
1104
|
}
|
|
1062
1105
|
|
|
1063
1106
|
position_T source_start, source_end;
|
|
@@ -1164,8 +1207,12 @@ static hb_array_T* transform_javascript_include_tag_multi_source(
|
|
|
1164
1207
|
|
|
1165
1208
|
if (source_count == 0) { return NULL; }
|
|
1166
1209
|
|
|
1167
|
-
char* path_options =
|
|
1168
|
-
|
|
1210
|
+
char* path_options = extract_path_options_from_keyword_hash(
|
|
1211
|
+
call_node,
|
|
1212
|
+
parse_context->prism_source,
|
|
1213
|
+
JAVASCRIPT_INCLUDE_TAG_PATH_OPTIONS,
|
|
1214
|
+
allocator
|
|
1215
|
+
);
|
|
1169
1216
|
hb_array_T* elements = hb_array_init(source_count * 2, allocator);
|
|
1170
1217
|
|
|
1171
1218
|
for (size_t i = 0; i < source_count; i++) {
|
|
@@ -1264,7 +1311,12 @@ static hb_array_T* transform_stylesheet_link_tag_multi_source(
|
|
|
1264
1311
|
|
|
1265
1312
|
if (source_count == 0) { return NULL; }
|
|
1266
1313
|
|
|
1267
|
-
char* path_options = extract_path_options_from_keyword_hash(
|
|
1314
|
+
char* path_options = extract_path_options_from_keyword_hash(
|
|
1315
|
+
call_node,
|
|
1316
|
+
parse_context->prism_source,
|
|
1317
|
+
STYLESHEET_LINK_TAG_PATH_OPTIONS,
|
|
1318
|
+
allocator
|
|
1319
|
+
);
|
|
1268
1320
|
hb_array_T* elements = hb_array_init(source_count * 2, allocator);
|
|
1269
1321
|
|
|
1270
1322
|
for (size_t i = 0; i < source_count; i++) {
|
|
@@ -1340,6 +1392,7 @@ static AST_NODE_T* transform_erb_block_to_tag_helper(
|
|
|
1340
1392
|
tag_helper_parse_context_T* parse_context
|
|
1341
1393
|
) {
|
|
1342
1394
|
if (!block_node || !context || !parse_context) { return NULL; }
|
|
1395
|
+
if (!block_node->tag_opening || !block_node->tag_closing) { return NULL; }
|
|
1343
1396
|
hb_allocator_T* allocator = context->allocator;
|
|
1344
1397
|
|
|
1345
1398
|
char* tag_name = parse_context->info->tag_name ? hb_allocator_strdup(allocator, parse_context->info->tag_name) : NULL;
|
|
@@ -1371,16 +1424,17 @@ static AST_NODE_T* transform_erb_block_to_tag_helper(
|
|
|
1371
1424
|
resolve_nonce_attribute(attributes, allocator);
|
|
1372
1425
|
}
|
|
1373
1426
|
|
|
1374
|
-
if (detect_link_to(parse_context->info->call_node,
|
|
1375
|
-
&& parse_context->info->call_node->arguments
|
|
1427
|
+
if (detect_link_to(parse_context->info->call_node, parse_context->parser) && parse_context->info->call_node->arguments
|
|
1428
|
+
&& parse_context->info->call_node->arguments->arguments.size >= 1) {
|
|
1376
1429
|
pm_node_t* first_argument = parse_context->info->call_node->arguments->arguments.nodes[0];
|
|
1377
|
-
size_t source_length = first_argument->location.
|
|
1430
|
+
size_t source_length = first_argument->location.length;
|
|
1431
|
+
const char* first_argument_source = (const char*) (parse_context->prism_source + first_argument->location.start);
|
|
1378
1432
|
char* href = NULL;
|
|
1379
1433
|
|
|
1380
|
-
if (first_argument->type != PM_STRING_NODE && !is_route_helper_node(first_argument,
|
|
1381
|
-
href = wrap_in_url_for(
|
|
1434
|
+
if (first_argument->type != PM_STRING_NODE && !is_route_helper_node(first_argument, parse_context->parser)) {
|
|
1435
|
+
href = wrap_in_url_for(first_argument_source, source_length, allocator);
|
|
1382
1436
|
} else {
|
|
1383
|
-
href = hb_allocator_strndup(allocator,
|
|
1437
|
+
href = hb_allocator_strndup(allocator, first_argument_source, source_length);
|
|
1384
1438
|
}
|
|
1385
1439
|
|
|
1386
1440
|
if (href) {
|
|
@@ -1406,8 +1460,8 @@ static AST_NODE_T* transform_erb_block_to_tag_helper(
|
|
|
1406
1460
|
}
|
|
1407
1461
|
}
|
|
1408
1462
|
|
|
1409
|
-
if (detect_turbo_frame_tag(parse_context->info->call_node,
|
|
1410
|
-
char* id_value = extract_turbo_frame_tag_id(parse_context->info->call_node,
|
|
1463
|
+
if (detect_turbo_frame_tag(parse_context->info->call_node, parse_context->parser)) {
|
|
1464
|
+
char* id_value = extract_turbo_frame_tag_id(parse_context->info->call_node, parse_context->parser, allocator);
|
|
1411
1465
|
|
|
1412
1466
|
if (id_value) {
|
|
1413
1467
|
if (!attributes) { attributes = hb_array_init(4, allocator); }
|
|
@@ -1488,6 +1542,8 @@ static AST_NODE_T* transform_erb_block_to_tag_helper(
|
|
|
1488
1542
|
&element_errors,
|
|
1489
1543
|
context->options
|
|
1490
1544
|
);
|
|
1545
|
+
|
|
1546
|
+
hb_buffer_free(&helper_name_buffer);
|
|
1491
1547
|
}
|
|
1492
1548
|
|
|
1493
1549
|
if (tag_name && parser_is_foreign_content_tag(hb_string_from_c_string(tag_name)) && context->source
|
|
@@ -1575,7 +1631,7 @@ static AST_NODE_T* transform_link_to_helper(
|
|
|
1575
1631
|
hb_allocator_T* allocator = context->allocator;
|
|
1576
1632
|
tag_helper_info_T* info = parse_context->info;
|
|
1577
1633
|
|
|
1578
|
-
char* href = extract_link_to_href(info->call_node,
|
|
1634
|
+
char* href = extract_link_to_href(info->call_node, parse_context->parser, allocator);
|
|
1579
1635
|
|
|
1580
1636
|
hb_array_T* attributes = NULL;
|
|
1581
1637
|
pm_arguments_node_t* link_arguments = info->call_node->arguments;
|
|
@@ -1603,8 +1659,12 @@ static AST_NODE_T* transform_link_to_helper(
|
|
|
1603
1659
|
|
|
1604
1660
|
if (second_arg->type != PM_KEYWORD_HASH_NODE && second_arg->type != PM_HASH_NODE
|
|
1605
1661
|
&& second_arg->type != PM_STRING_NODE && second_arg->type != PM_SYMBOL_NODE) {
|
|
1606
|
-
size_t source_length = second_arg->location.
|
|
1607
|
-
char* content = hb_allocator_strndup(
|
|
1662
|
+
size_t source_length = second_arg->location.length;
|
|
1663
|
+
char* content = hb_allocator_strndup(
|
|
1664
|
+
allocator,
|
|
1665
|
+
(const char*) (parse_context->prism_source + second_arg->location.start),
|
|
1666
|
+
source_length
|
|
1667
|
+
);
|
|
1608
1668
|
|
|
1609
1669
|
if (content) {
|
|
1610
1670
|
hb_buffer_T wrapped;
|
|
@@ -1884,11 +1944,12 @@ void transform_tag_helper_array(hb_array_T* array, analyze_ruby_context_T* conte
|
|
|
1884
1944
|
}
|
|
1885
1945
|
|
|
1886
1946
|
hb_array_replace_contents(array, &new_array);
|
|
1887
|
-
hb_array_free(&multi);
|
|
1888
1947
|
ast_node_free(child, context->allocator);
|
|
1889
1948
|
|
|
1890
1949
|
i += multi_size - 1;
|
|
1891
1950
|
}
|
|
1951
|
+
|
|
1952
|
+
hb_array_free(&multi);
|
|
1892
1953
|
} else if (strcmp(parse_context->matched_handler->name, "link_to") == 0) {
|
|
1893
1954
|
replacement = transform_link_to_helper(erb_node, context, parse_context);
|
|
1894
1955
|
} else if (string_equals(parse_context->matched_handler->name, "tag") && parse_context->info->tag_name
|
|
@@ -1921,11 +1982,12 @@ void transform_tag_helper_array(hb_array_T* array, analyze_ruby_context_T* conte
|
|
|
1921
1982
|
}
|
|
1922
1983
|
|
|
1923
1984
|
hb_array_replace_contents(array, &new_array);
|
|
1924
|
-
hb_array_free(&attributes);
|
|
1925
1985
|
ast_node_free(child, context->allocator);
|
|
1926
1986
|
|
|
1927
1987
|
i += attributes_size - 1;
|
|
1928
1988
|
}
|
|
1989
|
+
|
|
1990
|
+
hb_array_free(&attributes);
|
|
1929
1991
|
} else {
|
|
1930
1992
|
replacement = transform_tag_helper_with_attributes(erb_node, context, parse_context);
|
|
1931
1993
|
}
|
|
@@ -1987,12 +2049,13 @@ void transform_tag_helper_array(hb_array_T* array, analyze_ruby_context_T* conte
|
|
|
1987
2049
|
}
|
|
1988
2050
|
|
|
1989
2051
|
hb_array_replace_contents(array, &new_array);
|
|
1990
|
-
hb_array_free(&attributes);
|
|
1991
2052
|
ast_node_free(child, context->allocator);
|
|
1992
2053
|
|
|
1993
2054
|
i += attributes_size - 1;
|
|
1994
2055
|
}
|
|
1995
2056
|
|
|
2057
|
+
hb_array_free(&attributes);
|
|
2058
|
+
|
|
1996
2059
|
free_tag_helper_parse_context(parse_context);
|
|
1997
2060
|
} else if (parse_context) {
|
|
1998
2061
|
free_tag_helper_parse_context(parse_context);
|
|
@@ -24,14 +24,15 @@ char* extract_turbo_frame_tag_id(pm_call_node_t* call_node, pm_parser_t* parser,
|
|
|
24
24
|
return hb_allocator_strndup(allocator, (const char*) pm_string_source(&symbol_node->unescaped), length);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
size_t source_length = first_argument->location.
|
|
28
|
-
const char* source = (const char*) first_argument->location.start;
|
|
27
|
+
size_t source_length = first_argument->location.length;
|
|
28
|
+
const char* source = (const char*) (pm_parser_start(parser) + first_argument->location.start);
|
|
29
29
|
|
|
30
30
|
if (first_argument->type == PM_CALL_NODE) {
|
|
31
31
|
pm_call_node_t* call = (pm_call_node_t*) first_argument;
|
|
32
|
-
pm_constant_t* call_constant =
|
|
32
|
+
const pm_constant_t* call_constant = pm_parser_constant(parser, call->name);
|
|
33
33
|
|
|
34
|
-
if (call_constant &&
|
|
34
|
+
if (call_constant && pm_constant_length(call_constant) == 6
|
|
35
|
+
&& strncmp((const char*) pm_constant_start(call_constant), "dom_id", 6) == 0) {
|
|
35
36
|
return hb_allocator_strndup(allocator, source, source_length);
|
|
36
37
|
}
|
|
37
38
|
}
|