herb 0.8.3 → 0.8.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3908d930c973519ff35367b6e870825d296b040fc7b24d063cac2063bc3f444
4
- data.tar.gz: 8088699f58e77d1bce02721b1808840bac6b9799e8e8ea1c978abf967c4e371a
3
+ metadata.gz: b0fa9bb876ad3b41c74d1e21950d4a3482acd44626b20299ed57d7bc4e7e70d3
4
+ data.tar.gz: 8f414d5c9be5c2187e26d5b5a1f32c59c3026384f002be0034b55f14eb52bd24
5
5
  SHA512:
6
- metadata.gz: 0a5702c77e7e99b6c8d9d27af6d970d0fda38e8391e14b778f6a25e2f76b17099ccbec7370263fd78ab1f6dd8446fd4820eaa625013650b1530222847672b4f8
7
- data.tar.gz: fae00c8ed586d665d32f4133a1e12f4a44535e276f3924dd60524d549aa7904a65d3093994d07bae2e59b9a146bcc9638a14d8f6dcd7cb4620fa821b394b487f
6
+ metadata.gz: 83a1bd88f84e725f66395c1faebde394a4b052b5bfe335d75f4cfb1a8c33c2850773e102c8ea10fd0b5511d8cd0d0984176fea7a09a229c3ed51885eab5a840e
7
+ data.tar.gz: b85b14411e24b0f4a3c7dd7b384a8f741f107007ed114a32358675a2e46a59990e365bd277a6fc35c36762a1e4b1d87578c73c4c290be6fdf5593643aead3a05
@@ -342,7 +342,7 @@ VALUE rb_errors_array_from_c_array(hb_array_T* array) {
342
342
  VALUE rb_array = rb_ary_new();
343
343
 
344
344
  if (array) {
345
- for (size_t i = 0; i < hb_array_size(array); i++) {
345
+ for (size_t i = 0; i < array->size; i++) {
346
346
  ERROR_T* child_node = (ERROR_T*) hb_array_get(array, i);
347
347
 
348
348
  if (child_node) {
@@ -63,7 +63,7 @@ VALUE create_lex_result(hb_array_T* tokens, VALUE source) {
63
63
  VALUE warnings = rb_ary_new();
64
64
  VALUE errors = rb_ary_new();
65
65
 
66
- for (size_t i = 0; i < hb_array_size(tokens); i++) {
66
+ for (size_t i = 0; i < tokens->size; i++) {
67
67
  token_T* token = hb_array_get(tokens, i);
68
68
  if (token != NULL) { rb_ary_push(value, rb_token_from_c_struct(token)); }
69
69
  }
data/ext/herb/nodes.c CHANGED
@@ -464,7 +464,7 @@ static VALUE rb_erb_content_node_from_c_struct(AST_ERB_CONTENT_NODE_T* erb_conte
464
464
  VALUE erb_content_node_tag_opening = rb_token_from_c_struct(erb_content_node->tag_opening);
465
465
  VALUE erb_content_node_content = rb_token_from_c_struct(erb_content_node->content);
466
466
  VALUE erb_content_node_tag_closing = rb_token_from_c_struct(erb_content_node->tag_closing);
467
- /* #<Herb::Template::AnalyzedRubyField:0x00007f1c2e6c7a68 @name="analyzed_ruby", @options={kind: nil}> */
467
+ /* #<Herb::Template::AnalyzedRubyField:0x00007f696ec27868 @name="analyzed_ruby", @options={kind: nil}> */
468
468
  VALUE erb_content_node_analyzed_ruby = Qnil;
469
469
  VALUE erb_content_node_parsed = (erb_content_node->parsed) ? Qtrue : Qfalse;
470
470
  VALUE erb_content_node_valid = (erb_content_node->valid) ? Qtrue : Qfalse;
@@ -1091,7 +1091,7 @@ static VALUE rb_nodes_array_from_c_array(hb_array_T* array) {
1091
1091
  VALUE rb_array = rb_ary_new();
1092
1092
 
1093
1093
  if (array) {
1094
- for (size_t i = 0; i < hb_array_size(array); i++) {
1094
+ for (size_t i = 0; i < array->size; i++) {
1095
1095
  AST_NODE_T* child_node = (AST_NODE_T*) hb_array_get(array, i);
1096
1096
 
1097
1097
  if (child_node) {
@@ -25,6 +25,7 @@ module Herb
25
25
  @relative_file_path = calculate_relative_path
26
26
  @top_level_elements = [] #: Array[Herb::AST::HTMLElementNode]
27
27
  @element_stack = [] #: Array[String]
28
+ @erb_block_stack = [] #: Array[Herb::AST::ERBBlockNode]
28
29
  @debug_attributes_applied = false
29
30
  @in_attribute = false
30
31
  @in_html_comment = false
@@ -83,6 +84,12 @@ module Herb
83
84
  nil
84
85
  end
85
86
 
87
+ def visit_erb_block_node(node)
88
+ @erb_block_stack.push(node)
89
+ super
90
+ @erb_block_stack.pop
91
+ end
92
+
86
93
  private
87
94
 
88
95
  def calculate_relative_path
@@ -295,7 +302,11 @@ module Herb
295
302
 
296
303
  def in_excluded_context?
297
304
  excluded_tags = ["script", "style", "head", "textarea", "pre"]
298
- excluded_tags.any? { |tag| @element_stack.include?(tag) }
305
+ return true if excluded_tags.any? { |tag| @element_stack.include?(tag) }
306
+
307
+ return true if @erb_block_stack.any? { |node| javascript_tag?(node.content.value.strip) }
308
+
309
+ false
299
310
  end
300
311
 
301
312
  def erb_output?(opening)
@@ -332,6 +343,18 @@ module Herb
332
343
 
333
344
  false
334
345
  end
346
+
347
+ # TODO: Rewrite using Prism Nodes once available
348
+ def javascript_tag?(code)
349
+ cleaned_code = code.strip.gsub(/\s+/, " ")
350
+
351
+ return true if cleaned_code.match?(/\bjavascript_tag\s.*do\s*$/) ||
352
+ cleaned_code.match?(/\bjavascript_tag\s.*\{\s*$/) ||
353
+ cleaned_code.match?(/\bjavascript_tag\(.*do\s*$/) ||
354
+ cleaned_code.match?(/\bjavascript_tag\(.*\{\s*$/)
355
+
356
+ false
357
+ end
335
358
  end
336
359
  end
337
360
  end
data/lib/herb/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # typed: true
3
3
 
4
4
  module Herb
5
- VERSION = "0.8.3"
5
+ VERSION = "0.8.4"
6
6
  end
@@ -19,6 +19,8 @@ module Herb
19
19
 
20
20
  def visit_erb_yield_node: (untyped _node) -> untyped
21
21
 
22
+ def visit_erb_block_node: (untyped node) -> untyped
23
+
22
24
  private
23
25
 
24
26
  def calculate_relative_path: () -> untyped
@@ -65,6 +67,9 @@ module Herb
65
67
 
66
68
  # TODO: Rewrite using Prism Nodes once available
67
69
  def complex_rails_helper?: (untyped code) -> untyped
70
+
71
+ # TODO: Rewrite using Prism Nodes once available
72
+ def javascript_tag?: (untyped code) -> untyped
68
73
  end
69
74
  end
70
75
  end
data/src/analyze.c CHANGED
@@ -287,7 +287,7 @@ static AST_NODE_T* create_control_node(
287
287
 
288
288
  if (end_node) {
289
289
  end_position = end_node->base.location.end;
290
- } else if (children && hb_array_size(children) > 0) {
290
+ } else if (children && children->size > 0) {
291
291
  AST_NODE_T* last_child = hb_array_last(children);
292
292
  end_position = last_child->location.end;
293
293
  } else if (subsequent) {
@@ -329,7 +329,7 @@ static AST_NODE_T* create_control_node(
329
329
  hb_array_T* in_conditions = hb_array_init(8);
330
330
  hb_array_T* non_when_non_in_children = hb_array_init(8);
331
331
 
332
- for (size_t i = 0; i < hb_array_size(children); i++) {
332
+ for (size_t i = 0; i < children->size; i++) {
333
333
  AST_NODE_T* child = hb_array_get(children, i);
334
334
 
335
335
  if (child && child->type == AST_ERB_WHEN_NODE) {
@@ -343,7 +343,7 @@ static AST_NODE_T* create_control_node(
343
343
 
344
344
  hb_array_free(&children);
345
345
 
346
- if (hb_array_size(in_conditions) > 0) {
346
+ if (in_conditions->size > 0) {
347
347
  hb_array_free(&when_conditions);
348
348
 
349
349
  return (AST_NODE_T*) ast_erb_case_match_node_init(
@@ -539,7 +539,7 @@ static size_t process_control_structure(
539
539
  hb_array_T* in_conditions = hb_array_init(8);
540
540
  hb_array_T* non_when_non_in_children = hb_array_init(8);
541
541
 
542
- while (index < hb_array_size(array)) {
542
+ while (index < array->size) {
543
543
  AST_NODE_T* next_node = hb_array_get(array, index);
544
544
 
545
545
  if (!next_node) { break; }
@@ -555,7 +555,7 @@ static size_t process_control_structure(
555
555
  index++;
556
556
  }
557
557
 
558
- while (index < hb_array_size(array)) {
558
+ while (index < array->size) {
559
559
  AST_NODE_T* next_node = hb_array_get(array, index);
560
560
 
561
561
  if (!next_node) { break; }
@@ -627,7 +627,7 @@ static size_t process_control_structure(
627
627
 
628
628
  AST_ERB_ELSE_NODE_T* else_clause = NULL;
629
629
 
630
- if (index < hb_array_size(array)) {
630
+ if (index < array->size) {
631
631
  AST_NODE_T* next_node = hb_array_get(array, index);
632
632
 
633
633
  if (next_node && next_node->type == AST_ERB_CONTENT_NODE) {
@@ -661,7 +661,7 @@ static size_t process_control_structure(
661
661
 
662
662
  AST_ERB_END_NODE_T* end_node = NULL;
663
663
 
664
- if (index < hb_array_size(array)) {
664
+ if (index < array->size) {
665
665
  AST_NODE_T* potential_end = hb_array_get(array, index);
666
666
 
667
667
  if (potential_end && potential_end->type == AST_ERB_CONTENT_NODE) {
@@ -694,15 +694,15 @@ static size_t process_control_structure(
694
694
  end_position = end_node->base.location.end;
695
695
  } else if (else_clause) {
696
696
  end_position = else_clause->base.location.end;
697
- } else if (hb_array_size(when_conditions) > 0) {
697
+ } else if (when_conditions->size > 0) {
698
698
  AST_NODE_T* last_when = hb_array_last(when_conditions);
699
699
  end_position = last_when->location.end;
700
- } else if (hb_array_size(in_conditions) > 0) {
700
+ } else if (in_conditions->size > 0) {
701
701
  AST_NODE_T* last_in = hb_array_last(in_conditions);
702
702
  end_position = last_in->location.end;
703
703
  }
704
704
 
705
- if (hb_array_size(in_conditions) > 0) {
705
+ if (in_conditions->size > 0) {
706
706
  hb_array_T* case_match_errors = erb_node->base.errors;
707
707
  erb_node->base.errors = NULL;
708
708
 
@@ -760,7 +760,7 @@ static size_t process_control_structure(
760
760
  AST_ERB_ELSE_NODE_T* else_clause = NULL;
761
761
  AST_ERB_ENSURE_NODE_T* ensure_clause = NULL;
762
762
 
763
- if (index < hb_array_size(array)) {
763
+ if (index < array->size) {
764
764
  AST_NODE_T* next_node = hb_array_get(array, index);
765
765
 
766
766
  if (next_node && next_node->type == AST_ERB_CONTENT_NODE) {
@@ -775,7 +775,7 @@ static size_t process_control_structure(
775
775
  }
776
776
  }
777
777
 
778
- if (index < hb_array_size(array)) {
778
+ if (index < array->size) {
779
779
  AST_NODE_T* next_node = hb_array_get(array, index);
780
780
 
781
781
  if (next_node && next_node->type == AST_ERB_CONTENT_NODE) {
@@ -807,7 +807,7 @@ static size_t process_control_structure(
807
807
  }
808
808
  }
809
809
 
810
- if (index < hb_array_size(array)) {
810
+ if (index < array->size) {
811
811
  AST_NODE_T* next_node = hb_array_get(array, index);
812
812
 
813
813
  if (next_node && next_node->type == AST_ERB_CONTENT_NODE) {
@@ -819,7 +819,7 @@ static size_t process_control_structure(
819
819
 
820
820
  index++;
821
821
 
822
- while (index < hb_array_size(array)) {
822
+ while (index < array->size) {
823
823
  AST_NODE_T* child = hb_array_get(array, index);
824
824
 
825
825
  if (!child) { break; }
@@ -855,7 +855,7 @@ static size_t process_control_structure(
855
855
 
856
856
  AST_ERB_END_NODE_T* end_node = NULL;
857
857
 
858
- if (index < hb_array_size(array)) {
858
+ if (index < array->size) {
859
859
  AST_NODE_T* potential_end = hb_array_get(array, index);
860
860
 
861
861
  if (potential_end && potential_end->type == AST_ERB_CONTENT_NODE) {
@@ -922,7 +922,7 @@ static size_t process_control_structure(
922
922
 
923
923
  AST_ERB_END_NODE_T* end_node = NULL;
924
924
 
925
- if (index < hb_array_size(array)) {
925
+ if (index < array->size) {
926
926
  AST_NODE_T* potential_close = hb_array_get(array, index);
927
927
 
928
928
  if (potential_close && potential_close->type == AST_ERB_CONTENT_NODE) {
@@ -954,7 +954,7 @@ static size_t process_control_structure(
954
954
 
955
955
  if (end_node) {
956
956
  end_position = end_node->base.location.end;
957
- } else if (children && hb_array_size(children) > 0) {
957
+ } else if (children && children->size > 0) {
958
958
  AST_NODE_T* last_child = hb_array_last(children);
959
959
  end_position = last_child->location.end;
960
960
  }
@@ -984,7 +984,7 @@ static size_t process_control_structure(
984
984
  AST_NODE_T* subsequent = NULL;
985
985
  AST_ERB_END_NODE_T* end_node = NULL;
986
986
 
987
- if (index < hb_array_size(array)) {
987
+ if (index < array->size) {
988
988
  AST_NODE_T* next_node = hb_array_get(array, index);
989
989
 
990
990
  if (next_node && next_node->type == AST_ERB_CONTENT_NODE) {
@@ -997,7 +997,7 @@ static size_t process_control_structure(
997
997
  }
998
998
  }
999
999
 
1000
- if (index < hb_array_size(array)) {
1000
+ if (index < array->size) {
1001
1001
  AST_NODE_T* potential_end = hb_array_get(array, index);
1002
1002
 
1003
1003
  if (potential_end && potential_end->type == AST_ERB_CONTENT_NODE) {
@@ -1059,7 +1059,7 @@ static size_t process_subsequent_block(
1059
1059
  hb_array_free(&children);
1060
1060
  }
1061
1061
 
1062
- if (index < hb_array_size(array)) {
1062
+ if (index < array->size) {
1063
1063
  AST_NODE_T* next_node = hb_array_get(array, index);
1064
1064
 
1065
1065
  if (next_node && next_node->type == AST_ERB_CONTENT_NODE) {
@@ -1117,7 +1117,7 @@ static size_t process_block_children(
1117
1117
  analyze_ruby_context_T* context,
1118
1118
  control_type_t parent_type
1119
1119
  ) {
1120
- while (index < hb_array_size(array)) {
1120
+ while (index < array->size) {
1121
1121
  AST_NODE_T* child = hb_array_get(array, index);
1122
1122
 
1123
1123
  if (!child) { break; }
@@ -1139,7 +1139,7 @@ static size_t process_block_children(
1139
1139
  hb_array_T* temp_array = hb_array_init(1);
1140
1140
  size_t new_index = process_control_structure(node, array, index, temp_array, context, child_type);
1141
1141
 
1142
- if (hb_array_size(temp_array) > 0) { hb_array_append(children_array, hb_array_first(temp_array)); }
1142
+ if (temp_array->size > 0) { hb_array_append(children_array, hb_array_first(temp_array)); }
1143
1143
 
1144
1144
  hb_array_free(&temp_array);
1145
1145
 
@@ -1155,10 +1155,10 @@ static size_t process_block_children(
1155
1155
  }
1156
1156
 
1157
1157
  hb_array_T* rewrite_node_array(AST_NODE_T* node, hb_array_T* array, analyze_ruby_context_T* context) {
1158
- hb_array_T* new_array = hb_array_init(hb_array_size(array));
1158
+ hb_array_T* new_array = hb_array_init(array->size);
1159
1159
  size_t index = 0;
1160
1160
 
1161
- while (index < hb_array_size(array)) {
1161
+ while (index < array->size) {
1162
1162
  AST_NODE_T* item = hb_array_get(array, index);
1163
1163
 
1164
1164
  if (!item) { break; }
@@ -1293,7 +1293,7 @@ static bool detect_invalid_erb_structures(const AST_NODE_T* node, void* data) {
1293
1293
  if (if_node->end_node == NULL) { check_erb_node_for_missing_end(node); }
1294
1294
 
1295
1295
  if (if_node->statements != NULL) {
1296
- for (size_t i = 0; i < hb_array_size(if_node->statements); i++) {
1296
+ for (size_t i = 0; i < if_node->statements->size; i++) {
1297
1297
  AST_NODE_T* statement = (AST_NODE_T*) hb_array_get(if_node->statements, i);
1298
1298
 
1299
1299
  if (statement != NULL) { herb_visit_node(statement, detect_invalid_erb_structures, context); }
@@ -1325,7 +1325,7 @@ static bool detect_invalid_erb_structures(const AST_NODE_T* node, void* data) {
1325
1325
  const AST_ERB_IF_NODE_T* elsif_node = (const AST_ERB_IF_NODE_T*) subsequent;
1326
1326
 
1327
1327
  if (elsif_node->statements != NULL) {
1328
- for (size_t i = 0; i < hb_array_size(elsif_node->statements); i++) {
1328
+ for (size_t i = 0; i < elsif_node->statements->size; i++) {
1329
1329
  AST_NODE_T* statement = (AST_NODE_T*) hb_array_get(elsif_node->statements, i);
1330
1330
 
1331
1331
  if (statement != NULL) { herb_visit_node(statement, detect_invalid_erb_structures, context); }
@@ -1337,7 +1337,7 @@ static bool detect_invalid_erb_structures(const AST_NODE_T* node, void* data) {
1337
1337
  const AST_ERB_ELSE_NODE_T* else_node = (const AST_ERB_ELSE_NODE_T*) subsequent;
1338
1338
 
1339
1339
  if (else_node->statements != NULL) {
1340
- for (size_t i = 0; i < hb_array_size(else_node->statements); i++) {
1340
+ for (size_t i = 0; i < else_node->statements->size; i++) {
1341
1341
  AST_NODE_T* statement = (AST_NODE_T*) hb_array_get(else_node->statements, i);
1342
1342
 
1343
1343
  if (statement != NULL) { herb_visit_node(statement, detect_invalid_erb_structures, context); }
data/src/ast_node.c CHANGED
@@ -43,7 +43,7 @@ ast_node_type_T ast_node_type(const AST_NODE_T* node) {
43
43
  }
44
44
 
45
45
  size_t ast_node_errors_count(const AST_NODE_T* node) {
46
- return hb_array_size(node->errors);
46
+ return node->errors->size;
47
47
  }
48
48
 
49
49
  hb_array_T* ast_node_errors(const AST_NODE_T* node) {