herb 0.11.2-x86_64-linux-gnu → 0.11.3-x86_64-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/config.yml +7 -8
- data/ext/herb/error_helpers.c +3 -3
- 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/ast/erb_render_node.rb +6 -2
- data/lib/herb/cli.rb +7 -3
- data/lib/herb/dev/runner.rb +5 -2
- data/lib/herb/engine/compiler.rb +39 -4
- data/lib/herb/engine/slots/dynamics_compiler.rb +1 -1
- 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/visitor.rb +37 -7
- data/lib/herb/engine.rb +11 -1
- data/lib/herb/errors.rb +7 -7
- data/lib/herb/version.rb +1 -1
- data/sig/herb/ast/erb_render_node.rbs +2 -0
- data/sig/herb/dev/runner.rbs +2 -2
- data/sig/herb/engine/compiler.rbs +9 -0
- 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 +7 -0
- data/sig/herb/engine.rbs +2 -0
- data/sig/herb/errors.rbs +2 -2
- data/sig/serialized_ast_errors.rbs +1 -1
- data/src/analyze/action_view/tag_helpers.c +23 -9
- data/src/analyze/analyze.c +17 -10
- data/src/analyze/render_nodes.c +189 -38
- 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/include/errors.h +3 -3
- 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.c +3 -1
- 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
- metadata +1 -1
|
@@ -183,6 +183,15 @@ static bool asset_tag_resolves_at_render_time(pm_call_node_t* call_node, const c
|
|
|
183
183
|
return false;
|
|
184
184
|
}
|
|
185
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
|
+
|
|
186
195
|
static tag_helper_parse_context_T* parse_tag_helper_content(
|
|
187
196
|
const char* content_string,
|
|
188
197
|
const char* original_source,
|
|
@@ -235,7 +244,10 @@ static tag_helper_parse_context_T* parse_tag_helper_content(
|
|
|
235
244
|
.parser = parse_context->parser,
|
|
236
245
|
.info = parse_context->info,
|
|
237
246
|
.found = false };
|
|
238
|
-
|
|
247
|
+
|
|
248
|
+
const pm_node_t* expression = sole_top_level_expression(parse_context->root);
|
|
249
|
+
|
|
250
|
+
if (expression) { search_tag_helper_node(expression, &search); }
|
|
239
251
|
|
|
240
252
|
if (!search.found
|
|
241
253
|
|| asset_tag_resolves_at_render_time(parse_context->info->call_node, search.matched_handler->name)) {
|
|
@@ -297,13 +309,9 @@ pm_visit_result_t search_tag_helper_node(const pm_node_t* node, void* data) {
|
|
|
297
309
|
return PM_VISIT_SKIP;
|
|
298
310
|
}
|
|
299
311
|
}
|
|
300
|
-
|
|
301
|
-
return PM_VISIT_SKIP;
|
|
302
312
|
}
|
|
303
313
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
return search_data->found ? PM_VISIT_DESCEND : PM_VISIT_SKIP;
|
|
314
|
+
return PM_VISIT_SKIP;
|
|
307
315
|
}
|
|
308
316
|
|
|
309
317
|
position_T byte_offset_to_position(const char* source, size_t offset) {
|
|
@@ -1384,6 +1392,7 @@ static AST_NODE_T* transform_erb_block_to_tag_helper(
|
|
|
1384
1392
|
tag_helper_parse_context_T* parse_context
|
|
1385
1393
|
) {
|
|
1386
1394
|
if (!block_node || !context || !parse_context) { return NULL; }
|
|
1395
|
+
if (!block_node->tag_opening || !block_node->tag_closing) { return NULL; }
|
|
1387
1396
|
hb_allocator_T* allocator = context->allocator;
|
|
1388
1397
|
|
|
1389
1398
|
char* tag_name = parse_context->info->tag_name ? hb_allocator_strdup(allocator, parse_context->info->tag_name) : NULL;
|
|
@@ -1533,6 +1542,8 @@ static AST_NODE_T* transform_erb_block_to_tag_helper(
|
|
|
1533
1542
|
&element_errors,
|
|
1534
1543
|
context->options
|
|
1535
1544
|
);
|
|
1545
|
+
|
|
1546
|
+
hb_buffer_free(&helper_name_buffer);
|
|
1536
1547
|
}
|
|
1537
1548
|
|
|
1538
1549
|
if (tag_name && parser_is_foreign_content_tag(hb_string_from_c_string(tag_name)) && context->source
|
|
@@ -1933,11 +1944,12 @@ void transform_tag_helper_array(hb_array_T* array, analyze_ruby_context_T* conte
|
|
|
1933
1944
|
}
|
|
1934
1945
|
|
|
1935
1946
|
hb_array_replace_contents(array, &new_array);
|
|
1936
|
-
hb_array_free(&multi);
|
|
1937
1947
|
ast_node_free(child, context->allocator);
|
|
1938
1948
|
|
|
1939
1949
|
i += multi_size - 1;
|
|
1940
1950
|
}
|
|
1951
|
+
|
|
1952
|
+
hb_array_free(&multi);
|
|
1941
1953
|
} else if (strcmp(parse_context->matched_handler->name, "link_to") == 0) {
|
|
1942
1954
|
replacement = transform_link_to_helper(erb_node, context, parse_context);
|
|
1943
1955
|
} else if (string_equals(parse_context->matched_handler->name, "tag") && parse_context->info->tag_name
|
|
@@ -1970,11 +1982,12 @@ void transform_tag_helper_array(hb_array_T* array, analyze_ruby_context_T* conte
|
|
|
1970
1982
|
}
|
|
1971
1983
|
|
|
1972
1984
|
hb_array_replace_contents(array, &new_array);
|
|
1973
|
-
hb_array_free(&attributes);
|
|
1974
1985
|
ast_node_free(child, context->allocator);
|
|
1975
1986
|
|
|
1976
1987
|
i += attributes_size - 1;
|
|
1977
1988
|
}
|
|
1989
|
+
|
|
1990
|
+
hb_array_free(&attributes);
|
|
1978
1991
|
} else {
|
|
1979
1992
|
replacement = transform_tag_helper_with_attributes(erb_node, context, parse_context);
|
|
1980
1993
|
}
|
|
@@ -2036,12 +2049,13 @@ void transform_tag_helper_array(hb_array_T* array, analyze_ruby_context_T* conte
|
|
|
2036
2049
|
}
|
|
2037
2050
|
|
|
2038
2051
|
hb_array_replace_contents(array, &new_array);
|
|
2039
|
-
hb_array_free(&attributes);
|
|
2040
2052
|
ast_node_free(child, context->allocator);
|
|
2041
2053
|
|
|
2042
2054
|
i += attributes_size - 1;
|
|
2043
2055
|
}
|
|
2044
2056
|
|
|
2057
|
+
hb_array_free(&attributes);
|
|
2058
|
+
|
|
2045
2059
|
free_tag_helper_parse_context(parse_context);
|
|
2046
2060
|
} else if (parse_context) {
|
|
2047
2061
|
free_tag_helper_parse_context(parse_context);
|
data/src/analyze/analyze.c
CHANGED
|
@@ -327,19 +327,26 @@ static size_t process_case_structure(
|
|
|
327
327
|
|
|
328
328
|
index++;
|
|
329
329
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
330
|
+
hb_array_T* inline_statements = NULL;
|
|
331
|
+
|
|
332
|
+
if (has_inline_when || has_inline_in) {
|
|
333
|
+
inline_statements = hb_array_init(8, allocator);
|
|
334
|
+
control_type_t inline_type = has_inline_when ? CONTROL_TYPE_WHEN : CONTROL_TYPE_IN;
|
|
335
|
+
index = process_block_children(node, array, index, inline_statements, context, inline_type);
|
|
336
|
+
} else {
|
|
337
|
+
const control_type_t prelude_stop[] = { CONTROL_TYPE_WHEN, CONTROL_TYPE_IN, CONTROL_TYPE_END };
|
|
338
|
+
collect_children_until(
|
|
339
|
+
array,
|
|
340
|
+
&index,
|
|
341
|
+
non_when_non_in_children,
|
|
342
|
+
prelude_stop,
|
|
343
|
+
sizeof(prelude_stop) / sizeof(prelude_stop[0])
|
|
344
|
+
);
|
|
345
|
+
}
|
|
338
346
|
|
|
339
347
|
// Create a synthetic when/in node for inline when/in (e.g., <% case variable when "a" %>),
|
|
340
348
|
if (has_inline_when || has_inline_in) {
|
|
341
|
-
hb_array_T* statements =
|
|
342
|
-
non_when_non_in_children = hb_array_init(8, allocator);
|
|
349
|
+
hb_array_T* statements = inline_statements;
|
|
343
350
|
|
|
344
351
|
position_T start_position = condition_content ? condition_content->location.start
|
|
345
352
|
: (erb_node->tag_closing ? erb_node->tag_closing->location.end
|
data/src/analyze/render_nodes.c
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
#include "../include/lexer/token.h"
|
|
10
10
|
#include "../include/lib/hb_allocator.h"
|
|
11
11
|
#include "../include/lib/hb_array.h"
|
|
12
|
+
#include "../include/lib/hb_buffer.h"
|
|
12
13
|
#include "../include/lib/hb_string.h"
|
|
13
14
|
#include "../include/lib/string.h"
|
|
14
15
|
#include "../include/visitor.h"
|
|
@@ -102,9 +103,57 @@ static pm_block_node_t* find_block_on_render_call(pm_call_node_t* render_call) {
|
|
|
102
103
|
return NULL;
|
|
103
104
|
}
|
|
104
105
|
|
|
106
|
+
static bool literal_string_length(pm_node_t* node, size_t* length) {
|
|
107
|
+
if (node->type == PM_STRING_NODE) {
|
|
108
|
+
*length += pm_string_length(&((pm_string_node_t*) node)->unescaped);
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (node->type != PM_INTERPOLATED_STRING_NODE) { return false; }
|
|
113
|
+
|
|
114
|
+
pm_node_list_t* parts = &((pm_interpolated_string_node_t*) node)->parts;
|
|
115
|
+
|
|
116
|
+
for (size_t index = 0; index < parts->size; index++) {
|
|
117
|
+
if (!literal_string_length(parts->nodes[index], length)) { return false; }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
static char* append_literal_string(pm_node_t* node, char* cursor) {
|
|
124
|
+
if (node->type == PM_STRING_NODE) {
|
|
125
|
+
pm_string_t* unescaped = &((pm_string_node_t*) node)->unescaped;
|
|
126
|
+
size_t length = pm_string_length(unescaped);
|
|
127
|
+
|
|
128
|
+
memcpy(cursor, pm_string_source(unescaped), length);
|
|
129
|
+
return cursor + length;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
pm_node_list_t* parts = &((pm_interpolated_string_node_t*) node)->parts;
|
|
133
|
+
|
|
134
|
+
for (size_t index = 0; index < parts->size; index++) {
|
|
135
|
+
cursor = append_literal_string(parts->nodes[index], cursor);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return cursor;
|
|
139
|
+
}
|
|
140
|
+
|
|
105
141
|
static char* extract_string_value(pm_node_t* node, hb_allocator_T* allocator) {
|
|
106
142
|
if (!node) { return NULL; }
|
|
107
143
|
|
|
144
|
+
if (node->type == PM_INTERPOLATED_STRING_NODE) {
|
|
145
|
+
size_t length = 0;
|
|
146
|
+
if (!literal_string_length(node, &length)) { return NULL; }
|
|
147
|
+
|
|
148
|
+
char* value = hb_allocator_alloc(allocator, length + 1);
|
|
149
|
+
if (!value) { return NULL; }
|
|
150
|
+
|
|
151
|
+
char* end = append_literal_string(node, value);
|
|
152
|
+
*end = '\0';
|
|
153
|
+
|
|
154
|
+
return value;
|
|
155
|
+
}
|
|
156
|
+
|
|
108
157
|
if (node->type == PM_STRING_NODE) {
|
|
109
158
|
pm_string_node_t* string_node = (pm_string_node_t*) node;
|
|
110
159
|
size_t length = pm_string_length(&string_node->unescaped);
|
|
@@ -130,6 +179,40 @@ static char* extract_source_expression(const uint8_t* erb_content_source, pm_nod
|
|
|
130
179
|
);
|
|
131
180
|
}
|
|
132
181
|
|
|
182
|
+
static void append_ruby_string_argument(
|
|
183
|
+
hb_buffer_T* buffer,
|
|
184
|
+
pm_node_t* node,
|
|
185
|
+
const uint8_t* erb_content_source,
|
|
186
|
+
hb_allocator_T* allocator
|
|
187
|
+
) {
|
|
188
|
+
if (!node) { return; }
|
|
189
|
+
|
|
190
|
+
char* value = node->type == PM_SYMBOL_NODE ? NULL : extract_string_value(node, allocator);
|
|
191
|
+
|
|
192
|
+
if (!value) {
|
|
193
|
+
hb_buffer_append_with_length(
|
|
194
|
+
buffer,
|
|
195
|
+
(const char*) (erb_content_source + node->location.start),
|
|
196
|
+
node->location.length
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
hb_buffer_append_char(buffer, '"');
|
|
203
|
+
|
|
204
|
+
for (const char* cursor = value; *cursor; cursor++) {
|
|
205
|
+
bool escape = *cursor == '\\' || *cursor == '"'
|
|
206
|
+
|| (*cursor == '#' && (cursor[1] == '{' || cursor[1] == '@' || cursor[1] == '$'));
|
|
207
|
+
|
|
208
|
+
if (escape) { hb_buffer_append_char(buffer, '\\'); }
|
|
209
|
+
hb_buffer_append_char(buffer, *cursor);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
hb_buffer_append_char(buffer, '"');
|
|
213
|
+
hb_allocator_dealloc(allocator, value);
|
|
214
|
+
}
|
|
215
|
+
|
|
133
216
|
static token_T* create_token_from_prism_node(
|
|
134
217
|
pm_node_t* node,
|
|
135
218
|
const char* value,
|
|
@@ -203,6 +286,18 @@ static keyword_result_T find_keyword_value(
|
|
|
203
286
|
return result;
|
|
204
287
|
}
|
|
205
288
|
|
|
289
|
+
static pm_node_t* find_keyword_value_node(
|
|
290
|
+
const uint8_t* erb_content_source,
|
|
291
|
+
pm_keyword_hash_node_t* keyword_hash,
|
|
292
|
+
const char* key,
|
|
293
|
+
hb_allocator_T* allocator
|
|
294
|
+
) {
|
|
295
|
+
keyword_result_T keyword = find_keyword_value(erb_content_source, keyword_hash, key, allocator);
|
|
296
|
+
if (keyword.value) { hb_allocator_dealloc(allocator, keyword.value); }
|
|
297
|
+
|
|
298
|
+
return keyword.value_node;
|
|
299
|
+
}
|
|
300
|
+
|
|
206
301
|
static pm_hash_node_t* find_locals_hash(pm_keyword_hash_node_t* keyword_hash, hb_allocator_T* allocator) {
|
|
207
302
|
if (!keyword_hash) { return NULL; }
|
|
208
303
|
|
|
@@ -584,9 +679,13 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
|
|
|
584
679
|
if (arguments && arguments->arguments.size >= 1) {
|
|
585
680
|
pm_node_t* first_argument = arguments->arguments.nodes[0];
|
|
586
681
|
|
|
587
|
-
if (first_argument->type == PM_STRING_NODE) {
|
|
682
|
+
if (first_argument->type == PM_STRING_NODE || first_argument->type == PM_INTERPOLATED_STRING_NODE) {
|
|
588
683
|
char* partial_string = extract_string_value(first_argument, allocator);
|
|
589
684
|
|
|
685
|
+
if (!partial_string) {
|
|
686
|
+
partial_string = extract_source_expression(erb_content_source, first_argument, allocator);
|
|
687
|
+
}
|
|
688
|
+
|
|
590
689
|
if (partial_string) {
|
|
591
690
|
has_positional_partial = true;
|
|
592
691
|
|
|
@@ -702,10 +801,12 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
|
|
|
702
801
|
keyword_result_T locals_keyword = find_keyword_value(erb_content_source, keyword_hash, "locals", allocator);
|
|
703
802
|
|
|
704
803
|
if (locals_keyword.value) {
|
|
705
|
-
|
|
804
|
+
hb_buffer_T partial_buffer;
|
|
805
|
+
hb_buffer_init(&partial_buffer, 64, allocator);
|
|
806
|
+
append_ruby_string_argument(&partial_buffer, arguments->arguments.nodes[0], erb_content_source, allocator);
|
|
706
807
|
|
|
707
808
|
append_render_ambiguous_locals_error(
|
|
708
|
-
|
|
809
|
+
hb_string_from_data(hb_buffer_value(&partial_buffer), hb_buffer_length(&partial_buffer)),
|
|
709
810
|
erb_node->base.location.start,
|
|
710
811
|
erb_node->base.location.end,
|
|
711
812
|
allocator,
|
|
@@ -713,19 +814,27 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
|
|
|
713
814
|
options
|
|
714
815
|
);
|
|
715
816
|
|
|
817
|
+
hb_buffer_free(&partial_buffer);
|
|
818
|
+
|
|
716
819
|
hb_allocator_dealloc(allocator, locals_keyword.value);
|
|
717
820
|
}
|
|
718
821
|
}
|
|
719
822
|
|
|
720
823
|
if (has_keyword_partial && partial && keyword_hash && hb_array_size(locals) == 0) {
|
|
721
|
-
|
|
722
|
-
|
|
824
|
+
hb_array_T* stray_assocs = hb_array_init(keyword_hash->elements.size, allocator);
|
|
825
|
+
hb_array_T* kept_elements = hb_array_init(keyword_hash->elements.size, allocator);
|
|
723
826
|
|
|
724
827
|
for (size_t index = 0; index < keyword_hash->elements.size; index++) {
|
|
725
828
|
pm_node_t* element = keyword_hash->elements.nodes[index];
|
|
829
|
+
if (element->type == PM_ASSOC_SPLAT_NODE || element == (pm_node_t*) state_assoc) {
|
|
830
|
+
hb_array_append(kept_elements, element);
|
|
831
|
+
continue;
|
|
832
|
+
}
|
|
833
|
+
|
|
726
834
|
if (element->type != PM_ASSOC_NODE) { continue; }
|
|
727
835
|
|
|
728
836
|
pm_assoc_node_t* assoc = (pm_assoc_node_t*) element;
|
|
837
|
+
|
|
729
838
|
char* key = extract_string_value(assoc->key, allocator);
|
|
730
839
|
if (!key) { continue; }
|
|
731
840
|
|
|
@@ -738,50 +847,65 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
|
|
|
738
847
|
}
|
|
739
848
|
}
|
|
740
849
|
|
|
741
|
-
if (!is_known && assoc == state_assoc) { is_known = true; }
|
|
742
|
-
|
|
743
850
|
if (!is_known) {
|
|
744
|
-
|
|
745
|
-
|
|
851
|
+
hb_array_append(stray_assocs, assoc);
|
|
852
|
+
} else if (!string_equals(key, "partial") && !string_equals(key, "locals")) {
|
|
853
|
+
hb_array_append(kept_elements, element);
|
|
746
854
|
}
|
|
747
855
|
|
|
748
856
|
hb_allocator_dealloc(allocator, key);
|
|
749
857
|
}
|
|
750
858
|
|
|
751
|
-
if (
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
859
|
+
if (hb_array_size(stray_assocs) > 0) {
|
|
860
|
+
hb_buffer_T keywords_buffer;
|
|
861
|
+
hb_buffer_T suggestion_buffer;
|
|
862
|
+
hb_buffer_init(&keywords_buffer, 64, allocator);
|
|
863
|
+
hb_buffer_init(&suggestion_buffer, 128, allocator);
|
|
755
864
|
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
865
|
+
hb_buffer_append(&suggestion_buffer, "partial: ");
|
|
866
|
+
append_ruby_string_argument(
|
|
867
|
+
&suggestion_buffer,
|
|
868
|
+
find_keyword_value_node(erb_content_source, keyword_hash, "partial", allocator),
|
|
869
|
+
erb_content_source,
|
|
870
|
+
allocator
|
|
871
|
+
);
|
|
872
|
+
hb_buffer_append(&suggestion_buffer, ", locals: { ");
|
|
759
873
|
|
|
760
|
-
|
|
874
|
+
for (size_t index = 0; index < hb_array_size(stray_assocs); index++) {
|
|
875
|
+
pm_assoc_node_t* assoc = hb_array_get(stray_assocs, index);
|
|
761
876
|
char* key = extract_string_value(assoc->key, allocator);
|
|
762
|
-
if (!key) { continue; }
|
|
763
|
-
|
|
764
|
-
bool is_known = false;
|
|
765
877
|
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
break;
|
|
770
|
-
}
|
|
878
|
+
if (index > 0) {
|
|
879
|
+
hb_buffer_append(&keywords_buffer, ", ");
|
|
880
|
+
hb_buffer_append(&suggestion_buffer, ", ");
|
|
771
881
|
}
|
|
772
882
|
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
883
|
+
hb_buffer_append(&keywords_buffer, key);
|
|
884
|
+
hb_buffer_append_with_length(
|
|
885
|
+
&suggestion_buffer,
|
|
886
|
+
(const char*) (erb_content_source + assoc->base.location.start),
|
|
887
|
+
assoc->base.location.length
|
|
888
|
+
);
|
|
778
889
|
|
|
779
890
|
hb_allocator_dealloc(allocator, key);
|
|
780
891
|
}
|
|
781
892
|
|
|
893
|
+
hb_buffer_append(&suggestion_buffer, " }");
|
|
894
|
+
|
|
895
|
+
for (size_t index = 0; index < hb_array_size(kept_elements); index++) {
|
|
896
|
+
pm_node_t* element = hb_array_get(kept_elements, index);
|
|
897
|
+
|
|
898
|
+
hb_buffer_append(&suggestion_buffer, ", ");
|
|
899
|
+
hb_buffer_append_with_length(
|
|
900
|
+
&suggestion_buffer,
|
|
901
|
+
(const char*) (erb_content_source + element->location.start),
|
|
902
|
+
element->location.length
|
|
903
|
+
);
|
|
904
|
+
}
|
|
905
|
+
|
|
782
906
|
append_render_missing_locals_error(
|
|
783
|
-
|
|
784
|
-
|
|
907
|
+
hb_string_from_data(hb_buffer_value(&keywords_buffer), hb_buffer_length(&keywords_buffer)),
|
|
908
|
+
hb_string_from_data(hb_buffer_value(&suggestion_buffer), hb_buffer_length(&suggestion_buffer)),
|
|
785
909
|
erb_node->base.location.start,
|
|
786
910
|
erb_node->base.location.end,
|
|
787
911
|
allocator,
|
|
@@ -789,8 +913,12 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
|
|
|
789
913
|
options
|
|
790
914
|
);
|
|
791
915
|
|
|
792
|
-
|
|
916
|
+
hb_buffer_free(&keywords_buffer);
|
|
917
|
+
hb_buffer_free(&suggestion_buffer);
|
|
793
918
|
}
|
|
919
|
+
|
|
920
|
+
hb_array_free(&stray_assocs);
|
|
921
|
+
hb_array_free(&kept_elements);
|
|
794
922
|
}
|
|
795
923
|
|
|
796
924
|
if (!partial && !template_path && !layout && !file && !inline_template && !body && !plain && !html && !renderable
|
|
@@ -805,11 +933,22 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
|
|
|
805
933
|
}
|
|
806
934
|
|
|
807
935
|
if (has_positional_partial && has_keyword_partial && keyword_hash) {
|
|
808
|
-
|
|
936
|
+
hb_buffer_T positional_buffer;
|
|
937
|
+
hb_buffer_T keyword_buffer;
|
|
938
|
+
hb_buffer_init(&positional_buffer, 64, allocator);
|
|
939
|
+
hb_buffer_init(&keyword_buffer, 64, allocator);
|
|
940
|
+
|
|
941
|
+
append_ruby_string_argument(&positional_buffer, arguments->arguments.nodes[0], erb_content_source, allocator);
|
|
942
|
+
append_ruby_string_argument(
|
|
943
|
+
&keyword_buffer,
|
|
944
|
+
find_keyword_value_node(erb_content_source, keyword_hash, "partial", allocator),
|
|
945
|
+
erb_content_source,
|
|
946
|
+
allocator
|
|
947
|
+
);
|
|
809
948
|
|
|
810
949
|
append_render_conflicting_partial_error(
|
|
811
|
-
|
|
812
|
-
|
|
950
|
+
hb_string_from_data(hb_buffer_value(&positional_buffer), hb_buffer_length(&positional_buffer)),
|
|
951
|
+
hb_string_from_data(hb_buffer_value(&keyword_buffer), hb_buffer_length(&keyword_buffer)),
|
|
813
952
|
erb_node->base.location.start,
|
|
814
953
|
erb_node->base.location.end,
|
|
815
954
|
allocator,
|
|
@@ -817,7 +956,8 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
|
|
|
817
956
|
options
|
|
818
957
|
);
|
|
819
958
|
|
|
820
|
-
|
|
959
|
+
hb_buffer_free(&positional_buffer);
|
|
960
|
+
hb_buffer_free(&keyword_buffer);
|
|
821
961
|
}
|
|
822
962
|
|
|
823
963
|
if (as_name) {
|
|
@@ -859,14 +999,25 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
|
|
|
859
999
|
}
|
|
860
1000
|
|
|
861
1001
|
if (layout && !partial && !template_path && !(block_fields && block_fields->end_node)) {
|
|
1002
|
+
hb_buffer_T layout_buffer;
|
|
1003
|
+
hb_buffer_init(&layout_buffer, 64, allocator);
|
|
1004
|
+
append_ruby_string_argument(
|
|
1005
|
+
&layout_buffer,
|
|
1006
|
+
find_keyword_value_node(erb_content_source, keyword_hash, "layout", allocator),
|
|
1007
|
+
erb_content_source,
|
|
1008
|
+
allocator
|
|
1009
|
+
);
|
|
1010
|
+
|
|
862
1011
|
append_render_layout_without_block_error(
|
|
863
|
-
|
|
1012
|
+
hb_string_from_data(hb_buffer_value(&layout_buffer), hb_buffer_length(&layout_buffer)),
|
|
864
1013
|
erb_node->base.location.start,
|
|
865
1014
|
erb_node->base.location.end,
|
|
866
1015
|
allocator,
|
|
867
1016
|
&errors,
|
|
868
1017
|
options
|
|
869
1018
|
);
|
|
1019
|
+
|
|
1020
|
+
hb_buffer_free(&layout_buffer);
|
|
870
1021
|
}
|
|
871
1022
|
|
|
872
1023
|
herb_prism_node_T prism_node = erb_node->prism_node;
|
|
@@ -32,7 +32,7 @@ static size_t element_attribute_count(const AST_NODE_T* node) {
|
|
|
32
32
|
if (node->type == AST_HTML_ELEMENT_NODE) {
|
|
33
33
|
const AST_HTML_ELEMENT_NODE_T* element = (const AST_HTML_ELEMENT_NODE_T*) node;
|
|
34
34
|
|
|
35
|
-
if (element->open_tag != NULL) {
|
|
35
|
+
if (element->open_tag != NULL && element->open_tag->type == AST_HTML_OPEN_TAG_NODE) {
|
|
36
36
|
const AST_HTML_OPEN_TAG_NODE_T* open_tag = (const AST_HTML_OPEN_TAG_NODE_T*) element->open_tag;
|
|
37
37
|
|
|
38
38
|
if (open_tag->children != NULL) { return hb_array_size(open_tag->children); }
|
data/src/diff/herb_diff_nodes.c
CHANGED
|
@@ -37,15 +37,7 @@ static void diff_element_node(
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
if (old_element->open_tag != NULL && new_element->open_tag != NULL) {
|
|
40
|
-
|
|
41
|
-
herb_hash_T new_open_hash = herb_hash_map_get(new_hashes, new_element->open_tag);
|
|
42
|
-
|
|
43
|
-
if (old_open_hash != new_open_hash) {
|
|
44
|
-
const AST_HTML_OPEN_TAG_NODE_T* old_open_tag = (const AST_HTML_OPEN_TAG_NODE_T*) old_element->open_tag;
|
|
45
|
-
const AST_HTML_OPEN_TAG_NODE_T* new_open_tag = (const AST_HTML_OPEN_TAG_NODE_T*) new_element->open_tag;
|
|
46
|
-
|
|
47
|
-
herb_diff_attributes(old_open_tag->children, new_open_tag->children, path, old_hashes, new_hashes, result);
|
|
48
|
-
}
|
|
40
|
+
herb_diff_node(old_element->open_tag, new_element->open_tag, path, old_hashes, new_hashes, preserve_whitespace, result);
|
|
49
41
|
}
|
|
50
42
|
|
|
51
43
|
if (old_element->body != NULL && new_element->body != NULL) {
|
data/src/diff/herb_hash_tree.c
CHANGED
|
@@ -729,7 +729,7 @@ herb_hash_T herb_hash_node_move_identity(const AST_NODE_T* node, const herb_hash
|
|
|
729
729
|
const AST_HTML_ELEMENT_NODE_T* element = (const AST_HTML_ELEMENT_NODE_T*) node;
|
|
730
730
|
hash = hash_token(hash, element->tag_name);
|
|
731
731
|
|
|
732
|
-
if (element->open_tag != NULL) {
|
|
732
|
+
if (element->open_tag != NULL && element->open_tag->type == AST_HTML_OPEN_TAG_NODE) {
|
|
733
733
|
const AST_HTML_OPEN_TAG_NODE_T* open_tag = (const AST_HTML_OPEN_TAG_NODE_T*) element->open_tag;
|
|
734
734
|
hash = herb_hash_combine(hash, identity_hash_attributes(open_tag->children, hash_map));
|
|
735
735
|
}
|
data/src/errors.c
CHANGED
|
@@ -1264,7 +1264,7 @@ RENDER_AMBIGUOUS_LOCALS_ERROR_T* render_ambiguous_locals_error_init(hb_string_T
|
|
|
1264
1264
|
|
|
1265
1265
|
error_init(&render_ambiguous_locals_error->base, RENDER_AMBIGUOUS_LOCALS_ERROR, start, end);
|
|
1266
1266
|
|
|
1267
|
-
const char* message_template = "Did you mean `render partial:
|
|
1267
|
+
const char* message_template = "Did you mean `render partial: %s, locals: { ... }`? Using `render %s, locals: { ... }` passes a local variable named `locals` to the partial instead of setting the `locals:` option.";
|
|
1268
1268
|
|
|
1269
1269
|
hb_string_T truncated_argument_0 = hb_string_truncate(partial, ERROR_MESSAGES_TRUNCATED_LENGTH);
|
|
1270
1270
|
char* truncated_c_string_0 = hb_string_to_c_string_using_malloc(truncated_argument_0);
|
|
@@ -1272,7 +1272,7 @@ RENDER_AMBIGUOUS_LOCALS_ERROR_T* render_ambiguous_locals_error_init(hb_string_T
|
|
|
1272
1272
|
hb_string_T truncated_argument_1 = hb_string_truncate(partial, ERROR_MESSAGES_TRUNCATED_LENGTH);
|
|
1273
1273
|
char* truncated_c_string_1 = hb_string_to_c_string_using_malloc(truncated_argument_1);
|
|
1274
1274
|
|
|
1275
|
-
char message[
|
|
1275
|
+
char message[438];
|
|
1276
1276
|
snprintf(
|
|
1277
1277
|
message,
|
|
1278
1278
|
sizeof(message),
|
|
@@ -1297,48 +1297,43 @@ void append_render_ambiguous_locals_error(hb_string_T partial, position_T start,
|
|
|
1297
1297
|
parser_options_increment_error_count(options);
|
|
1298
1298
|
}
|
|
1299
1299
|
|
|
1300
|
-
RENDER_MISSING_LOCALS_ERROR_T* render_missing_locals_error_init(hb_string_T
|
|
1300
|
+
RENDER_MISSING_LOCALS_ERROR_T* render_missing_locals_error_init(hb_string_T keywords, hb_string_T suggestion, position_T start, position_T end, hb_allocator_T* allocator) {
|
|
1301
1301
|
RENDER_MISSING_LOCALS_ERROR_T* render_missing_locals_error = hb_allocator_alloc(allocator, sizeof(RENDER_MISSING_LOCALS_ERROR_T));
|
|
1302
1302
|
|
|
1303
1303
|
if (!render_missing_locals_error) { return NULL; }
|
|
1304
1304
|
|
|
1305
1305
|
error_init(&render_missing_locals_error->base, RENDER_MISSING_LOCALS_ERROR, start, end);
|
|
1306
1306
|
|
|
1307
|
-
const char* message_template = "Wrap `%s` in `locals: { ... }` when using `partial:`. Use `render
|
|
1307
|
+
const char* message_template = "Wrap `%s` in `locals: { ... }` when using `partial:`. Use `render %s` instead. Without `locals:`, these keyword arguments are ignored.";
|
|
1308
1308
|
|
|
1309
1309
|
hb_string_T truncated_argument_0 = hb_string_truncate(keywords, ERROR_MESSAGES_TRUNCATED_LENGTH);
|
|
1310
1310
|
char* truncated_c_string_0 = hb_string_to_c_string_using_malloc(truncated_argument_0);
|
|
1311
1311
|
|
|
1312
|
-
hb_string_T truncated_argument_1 = hb_string_truncate(
|
|
1312
|
+
hb_string_T truncated_argument_1 = hb_string_truncate(suggestion, ERROR_MESSAGES_TRUNCATED_LENGTH);
|
|
1313
1313
|
char* truncated_c_string_1 = hb_string_to_c_string_using_malloc(truncated_argument_1);
|
|
1314
1314
|
|
|
1315
|
-
|
|
1316
|
-
char* truncated_c_string_2 = hb_string_to_c_string_using_malloc(truncated_argument_2);
|
|
1317
|
-
|
|
1318
|
-
char message[546];
|
|
1315
|
+
char message[391];
|
|
1319
1316
|
snprintf(
|
|
1320
1317
|
message,
|
|
1321
1318
|
sizeof(message),
|
|
1322
1319
|
message_template,
|
|
1323
1320
|
truncated_c_string_0 ? truncated_c_string_0 : "",
|
|
1324
|
-
truncated_c_string_1 ? truncated_c_string_1 : ""
|
|
1325
|
-
truncated_c_string_2 ? truncated_c_string_2 : ""
|
|
1321
|
+
truncated_c_string_1 ? truncated_c_string_1 : ""
|
|
1326
1322
|
);
|
|
1327
1323
|
|
|
1328
1324
|
if (truncated_c_string_0) { free(truncated_c_string_0); }
|
|
1329
1325
|
if (truncated_c_string_1) { free(truncated_c_string_1); }
|
|
1330
|
-
if (truncated_c_string_2) { free(truncated_c_string_2); }
|
|
1331
1326
|
render_missing_locals_error->base.message = hb_string_copy(hb_string(message), allocator);
|
|
1332
1327
|
|
|
1333
|
-
render_missing_locals_error->partial = hb_string_copy(partial, allocator);
|
|
1334
1328
|
render_missing_locals_error->keywords = hb_string_copy(keywords, allocator);
|
|
1329
|
+
render_missing_locals_error->suggestion = hb_string_copy(suggestion, allocator);
|
|
1335
1330
|
return render_missing_locals_error;
|
|
1336
1331
|
}
|
|
1337
1332
|
|
|
1338
|
-
void append_render_missing_locals_error(hb_string_T
|
|
1333
|
+
void append_render_missing_locals_error(hb_string_T keywords, hb_string_T suggestion, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T** errors, const struct PARSER_OPTIONS_STRUCT* options) {
|
|
1339
1334
|
if (parser_options_errors_exceeded(options)) { return; }
|
|
1340
1335
|
|
|
1341
|
-
hb_array_append_lazy(errors, render_missing_locals_error_init(
|
|
1336
|
+
hb_array_append_lazy(errors, render_missing_locals_error_init(keywords, suggestion, start, end, allocator), allocator);
|
|
1342
1337
|
|
|
1343
1338
|
parser_options_increment_error_count(options);
|
|
1344
1339
|
}
|
|
@@ -1370,7 +1365,7 @@ RENDER_CONFLICTING_PARTIAL_ERROR_T* render_conflicting_partial_error_init(hb_str
|
|
|
1370
1365
|
|
|
1371
1366
|
error_init(&render_conflicting_partial_error->base, RENDER_CONFLICTING_PARTIAL_ERROR, start, end);
|
|
1372
1367
|
|
|
1373
|
-
const char* message_template = "Both a positional partial
|
|
1368
|
+
const char* message_template = "Both a positional partial `%s` and a keyword `partial: %s` were passed to `render`. Use one form or the other, not both.";
|
|
1374
1369
|
|
|
1375
1370
|
hb_string_T truncated_argument_0 = hb_string_truncate(positional_partial, ERROR_MESSAGES_TRUNCATED_LENGTH);
|
|
1376
1371
|
char* truncated_c_string_0 = hb_string_to_c_string_using_malloc(truncated_argument_0);
|
|
@@ -1378,7 +1373,7 @@ RENDER_CONFLICTING_PARTIAL_ERROR_T* render_conflicting_partial_error_init(hb_str
|
|
|
1378
1373
|
hb_string_T truncated_argument_1 = hb_string_truncate(keyword_partial, ERROR_MESSAGES_TRUNCATED_LENGTH);
|
|
1379
1374
|
char* truncated_c_string_1 = hb_string_to_c_string_using_malloc(truncated_argument_1);
|
|
1380
1375
|
|
|
1381
|
-
char message[
|
|
1376
|
+
char message[377];
|
|
1382
1377
|
snprintf(
|
|
1383
1378
|
message,
|
|
1384
1379
|
sizeof(message),
|
|
@@ -1466,12 +1461,12 @@ RENDER_LAYOUT_WITHOUT_BLOCK_ERROR_T* render_layout_without_block_error_init(hb_s
|
|
|
1466
1461
|
|
|
1467
1462
|
error_init(&render_layout_without_block_error->base, RENDER_LAYOUT_WITHOUT_BLOCK_ERROR, start, end);
|
|
1468
1463
|
|
|
1469
|
-
const char* message_template = "Layout rendering needs a block. Use `render layout:
|
|
1464
|
+
const char* message_template = "Layout rendering needs a block. Use `render layout: %s do ... end` so the layout has content to wrap.";
|
|
1470
1465
|
|
|
1471
1466
|
hb_string_T truncated_argument_0 = hb_string_truncate(layout, ERROR_MESSAGES_TRUNCATED_LENGTH);
|
|
1472
1467
|
char* truncated_c_string_0 = hb_string_to_c_string_using_malloc(truncated_argument_0);
|
|
1473
1468
|
|
|
1474
|
-
char message[
|
|
1469
|
+
char message[230];
|
|
1475
1470
|
snprintf(
|
|
1476
1471
|
message,
|
|
1477
1472
|
sizeof(message),
|
|
@@ -2254,8 +2249,8 @@ static void error_free_render_ambiguous_locals_error(RENDER_AMBIGUOUS_LOCALS_ERR
|
|
|
2254
2249
|
}
|
|
2255
2250
|
|
|
2256
2251
|
static void error_free_render_missing_locals_error(RENDER_MISSING_LOCALS_ERROR_T* render_missing_locals_error, hb_allocator_T* allocator) {
|
|
2257
|
-
if (!hb_string_is_empty(render_missing_locals_error->partial)) { hb_allocator_dealloc(allocator, render_missing_locals_error->partial.data); }
|
|
2258
2252
|
if (!hb_string_is_empty(render_missing_locals_error->keywords)) { hb_allocator_dealloc(allocator, render_missing_locals_error->keywords.data); }
|
|
2253
|
+
if (!hb_string_is_empty(render_missing_locals_error->suggestion)) { hb_allocator_dealloc(allocator, render_missing_locals_error->suggestion.data); }
|
|
2259
2254
|
|
|
2260
2255
|
error_free_base_error(&render_missing_locals_error->base, allocator);
|
|
2261
2256
|
}
|
|
@@ -2974,8 +2969,8 @@ static void error_pretty_print_render_missing_locals_error(RENDER_MISSING_LOCALS
|
|
|
2974
2969
|
hb_buffer_append(buffer, "\n");
|
|
2975
2970
|
|
|
2976
2971
|
pretty_print_quoted_property(hb_string("message"), error->base.message, indent, relative_indent, false, buffer);
|
|
2977
|
-
pretty_print_quoted_property(hb_string("
|
|
2978
|
-
pretty_print_quoted_property(hb_string("
|
|
2972
|
+
pretty_print_quoted_property(hb_string("keywords"), error->keywords, indent, relative_indent, false, buffer);
|
|
2973
|
+
pretty_print_quoted_property(hb_string("suggestion"), error->suggestion, indent, relative_indent, true, buffer);
|
|
2979
2974
|
}
|
|
2980
2975
|
|
|
2981
2976
|
static void error_pretty_print_render_no_arguments_error(RENDER_NO_ARGUMENTS_ERROR_T* error, const size_t indent, const size_t relative_indent, hb_buffer_T* buffer) {
|