@herb-tools/node 0.8.5 → 0.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/binding.gyp +1 -0
  2. package/dist/herb-node.esm.js +1 -1
  3. package/extension/error_helpers.cpp +2 -2
  4. package/extension/error_helpers.h +1 -1
  5. package/extension/extension_helpers.cpp +1 -1
  6. package/extension/libherb/analyze.c +40 -30
  7. package/extension/libherb/analyze_missing_end.c +1 -1
  8. package/extension/libherb/analyze_transform.c +1 -1
  9. package/extension/libherb/ast_node.c +1 -1
  10. package/extension/libherb/ast_nodes.c +54 -158
  11. package/extension/libherb/ast_nodes.h +1 -1
  12. package/extension/libherb/ast_pretty_print.c +1 -1
  13. package/extension/libherb/ast_pretty_print.h +1 -1
  14. package/extension/libherb/errors.c +6 -6
  15. package/extension/libherb/errors.h +1 -1
  16. package/extension/libherb/extract.c +2 -2
  17. package/extension/libherb/herb.c +2 -2
  18. package/extension/libherb/include/ast_nodes.h +1 -1
  19. package/extension/libherb/include/ast_pretty_print.h +1 -1
  20. package/extension/libherb/include/errors.h +1 -1
  21. package/extension/libherb/include/util/hb_narray.h +30 -0
  22. package/extension/libherb/include/version.h +1 -1
  23. package/extension/libherb/parser.c +9 -9
  24. package/extension/libherb/parser_helpers.c +4 -4
  25. package/extension/libherb/parser_match_tags.c +1 -1
  26. package/extension/libherb/pretty_print.c +6 -6
  27. package/extension/libherb/util/hb_array.c +1 -0
  28. package/extension/libherb/util/hb_narray.c +81 -0
  29. package/extension/libherb/util/hb_narray.h +30 -0
  30. package/extension/libherb/version.h +1 -1
  31. package/extension/libherb/visitor.c +27 -27
  32. package/extension/nodes.cpp +2 -2
  33. package/extension/nodes.h +1 -1
  34. package/extension/prism/include/prism/ast.h +54 -20
  35. package/extension/prism/include/prism/diagnostic.h +2 -0
  36. package/extension/prism/include/prism/options.h +8 -2
  37. package/extension/prism/include/prism/parser.h +3 -0
  38. package/extension/prism/include/prism/version.h +2 -2
  39. package/extension/prism/include/prism.h +1 -1
  40. package/extension/prism/src/diagnostic.c +5 -1
  41. package/extension/prism/src/encoding.c +172 -67
  42. package/extension/prism/src/node.c +9 -0
  43. package/extension/prism/src/options.c +17 -7
  44. package/extension/prism/src/prettyprint.c +16 -0
  45. package/extension/prism/src/prism.c +1192 -1895
  46. package/extension/prism/src/serialize.c +7 -1
  47. package/extension/prism/src/token_type.c +2 -2
  48. package/extension/prism/src/util/pm_constant_pool.c +1 -1
  49. package/package.json +4 -4
package/binding.gyp CHANGED
@@ -40,6 +40,7 @@
40
40
  "./extension/libherb/util.c",
41
41
  "./extension/libherb/util/hb_arena.c",
42
42
  "./extension/libherb/util/hb_array.c",
43
+ "./extension/libherb/util/hb_narray.c",
43
44
  "./extension/libherb/util/hb_buffer.c",
44
45
  "./extension/libherb/util/hb_string.c",
45
46
  "./extension/libherb/util/hb_system.c",
@@ -6,7 +6,7 @@ import { createRequire } from 'module';
6
6
  import { fileURLToPath } from 'url';
7
7
 
8
8
  var name = "@herb-tools/node";
9
- var version = "0.8.5";
9
+ var version = "0.8.7";
10
10
  var packageJSON = {
11
11
  name: name,
12
12
  version: version};
@@ -1,5 +1,5 @@
1
1
  // NOTE: This file is generated by the templates/template.rb script and should not
2
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.5/templates/javascript/packages/node/extension/error_helpers.cpp.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.7/templates/javascript/packages/node/extension/error_helpers.cpp.erb
3
3
 
4
4
  #include <node_api.h>
5
5
  #include "error_helpers.h"
@@ -360,7 +360,7 @@ napi_value ErrorsArrayFromCArray(napi_env env, hb_array_T* array) {
360
360
  napi_create_array(env, &result);
361
361
 
362
362
  if (array) {
363
- for (size_t i = 0; i < array->size; i++) {
363
+ for (size_t i = 0; i < hb_array_size(array); i++) {
364
364
  ERROR_T* error = (ERROR_T*) hb_array_get(array, i);
365
365
  if (error) {
366
366
  napi_value js_error = ErrorFromCStruct(env, error);
@@ -1,5 +1,5 @@
1
1
  // NOTE: This file is generated by the templates/template.rb script and should not
2
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.5/templates/javascript/packages/node/extension/error_helpers.h.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.7/templates/javascript/packages/node/extension/error_helpers.h.erb
3
3
 
4
4
  #ifndef HERB_EXTENSION_ERRORS_H
5
5
  #define HERB_EXTENSION_ERRORS_H
@@ -153,7 +153,7 @@ napi_value CreateLexResult(napi_env env, hb_array_T* tokens, napi_value source)
153
153
 
154
154
  // Add tokens to array
155
155
  if (tokens) {
156
- for (size_t i = 0; i < tokens->size; i++) {
156
+ for (size_t i = 0; i < hb_array_size(tokens); i++) {
157
157
  token_T* token = (token_T*)hb_array_get(tokens, i);
158
158
  if (token) {
159
159
  napi_value token_obj = CreateToken(env, token);
@@ -192,9 +192,19 @@ static bool find_earliest_control_keyword_walker(const pm_node_t* node, void* da
192
192
  case PM_CALL_NODE: {
193
193
  pm_call_node_t* call = (pm_call_node_t*) node;
194
194
 
195
- if (call->block != NULL) {
196
- current_type = CONTROL_TYPE_BLOCK;
197
- keyword_offset = (uint32_t) (node->location.start - context->source_start);
195
+ if (call->block != NULL && call->block->type == PM_BLOCK_NODE) {
196
+ pm_block_node_t* block_node = (pm_block_node_t*) call->block;
197
+ size_t opening_length = block_node->opening_loc.end - block_node->opening_loc.start;
198
+ bool has_do_opening =
199
+ opening_length == 2 && block_node->opening_loc.start[0] == 'd' && block_node->opening_loc.start[1] == 'o';
200
+ bool has_brace_opening = opening_length == 1 && block_node->opening_loc.start[0] == '{';
201
+ bool has_closing_location = block_node->closing_loc.start != NULL && block_node->closing_loc.end != NULL
202
+ && (block_node->closing_loc.end - block_node->closing_loc.start) > 0;
203
+
204
+ if (has_do_opening || (has_brace_opening && !has_closing_location)) {
205
+ current_type = CONTROL_TYPE_BLOCK;
206
+ keyword_offset = (uint32_t) (node->location.start - context->source_start);
207
+ }
198
208
  }
199
209
  break;
200
210
  }
@@ -298,7 +308,7 @@ static AST_NODE_T* create_control_node(
298
308
 
299
309
  if (end_node) {
300
310
  end_position = end_node->base.location.end;
301
- } else if (children && children->size > 0) {
311
+ } else if (hb_array_size(children) > 0) {
302
312
  AST_NODE_T* last_child = hb_array_last(children);
303
313
  end_position = last_child->location.end;
304
314
  } else if (subsequent) {
@@ -340,7 +350,7 @@ static AST_NODE_T* create_control_node(
340
350
  hb_array_T* in_conditions = hb_array_init(8);
341
351
  hb_array_T* non_when_non_in_children = hb_array_init(8);
342
352
 
343
- for (size_t i = 0; i < children->size; i++) {
353
+ for (size_t i = 0; i < hb_array_size(children); i++) {
344
354
  AST_NODE_T* child = hb_array_get(children, i);
345
355
 
346
356
  if (child && child->type == AST_ERB_WHEN_NODE) {
@@ -354,7 +364,7 @@ static AST_NODE_T* create_control_node(
354
364
 
355
365
  hb_array_free(&children);
356
366
 
357
- if (in_conditions->size > 0) {
367
+ if (hb_array_size(in_conditions) > 0) {
358
368
  hb_array_free(&when_conditions);
359
369
 
360
370
  return (AST_NODE_T*) ast_erb_case_match_node_init(
@@ -550,7 +560,7 @@ static size_t process_control_structure(
550
560
  hb_array_T* in_conditions = hb_array_init(8);
551
561
  hb_array_T* non_when_non_in_children = hb_array_init(8);
552
562
 
553
- while (index < array->size) {
563
+ while (index < hb_array_size(array)) {
554
564
  AST_NODE_T* next_node = hb_array_get(array, index);
555
565
 
556
566
  if (!next_node) { break; }
@@ -566,7 +576,7 @@ static size_t process_control_structure(
566
576
  index++;
567
577
  }
568
578
 
569
- while (index < array->size) {
579
+ while (index < hb_array_size(array)) {
570
580
  AST_NODE_T* next_node = hb_array_get(array, index);
571
581
 
572
582
  if (!next_node) { break; }
@@ -638,7 +648,7 @@ static size_t process_control_structure(
638
648
 
639
649
  AST_ERB_ELSE_NODE_T* else_clause = NULL;
640
650
 
641
- if (index < array->size) {
651
+ if (index < hb_array_size(array)) {
642
652
  AST_NODE_T* next_node = hb_array_get(array, index);
643
653
 
644
654
  if (next_node && next_node->type == AST_ERB_CONTENT_NODE) {
@@ -672,7 +682,7 @@ static size_t process_control_structure(
672
682
 
673
683
  AST_ERB_END_NODE_T* end_node = NULL;
674
684
 
675
- if (index < array->size) {
685
+ if (index < hb_array_size(array)) {
676
686
  AST_NODE_T* potential_end = hb_array_get(array, index);
677
687
 
678
688
  if (potential_end && potential_end->type == AST_ERB_CONTENT_NODE) {
@@ -705,15 +715,15 @@ static size_t process_control_structure(
705
715
  end_position = end_node->base.location.end;
706
716
  } else if (else_clause) {
707
717
  end_position = else_clause->base.location.end;
708
- } else if (when_conditions->size > 0) {
718
+ } else if (hb_array_size(when_conditions) > 0) {
709
719
  AST_NODE_T* last_when = hb_array_last(when_conditions);
710
720
  end_position = last_when->location.end;
711
- } else if (in_conditions->size > 0) {
721
+ } else if (hb_array_size(in_conditions) > 0) {
712
722
  AST_NODE_T* last_in = hb_array_last(in_conditions);
713
723
  end_position = last_in->location.end;
714
724
  }
715
725
 
716
- if (in_conditions->size > 0) {
726
+ if (hb_array_size(in_conditions) > 0) {
717
727
  hb_array_T* case_match_errors = erb_node->base.errors;
718
728
  erb_node->base.errors = NULL;
719
729
 
@@ -771,7 +781,7 @@ static size_t process_control_structure(
771
781
  AST_ERB_ELSE_NODE_T* else_clause = NULL;
772
782
  AST_ERB_ENSURE_NODE_T* ensure_clause = NULL;
773
783
 
774
- if (index < array->size) {
784
+ if (index < hb_array_size(array)) {
775
785
  AST_NODE_T* next_node = hb_array_get(array, index);
776
786
 
777
787
  if (next_node && next_node->type == AST_ERB_CONTENT_NODE) {
@@ -786,7 +796,7 @@ static size_t process_control_structure(
786
796
  }
787
797
  }
788
798
 
789
- if (index < array->size) {
799
+ if (index < hb_array_size(array)) {
790
800
  AST_NODE_T* next_node = hb_array_get(array, index);
791
801
 
792
802
  if (next_node && next_node->type == AST_ERB_CONTENT_NODE) {
@@ -818,7 +828,7 @@ static size_t process_control_structure(
818
828
  }
819
829
  }
820
830
 
821
- if (index < array->size) {
831
+ if (index < hb_array_size(array)) {
822
832
  AST_NODE_T* next_node = hb_array_get(array, index);
823
833
 
824
834
  if (next_node && next_node->type == AST_ERB_CONTENT_NODE) {
@@ -830,7 +840,7 @@ static size_t process_control_structure(
830
840
 
831
841
  index++;
832
842
 
833
- while (index < array->size) {
843
+ while (index < hb_array_size(array)) {
834
844
  AST_NODE_T* child = hb_array_get(array, index);
835
845
 
836
846
  if (!child) { break; }
@@ -866,7 +876,7 @@ static size_t process_control_structure(
866
876
 
867
877
  AST_ERB_END_NODE_T* end_node = NULL;
868
878
 
869
- if (index < array->size) {
879
+ if (index < hb_array_size(array)) {
870
880
  AST_NODE_T* potential_end = hb_array_get(array, index);
871
881
 
872
882
  if (potential_end && potential_end->type == AST_ERB_CONTENT_NODE) {
@@ -933,7 +943,7 @@ static size_t process_control_structure(
933
943
 
934
944
  AST_ERB_END_NODE_T* end_node = NULL;
935
945
 
936
- if (index < array->size) {
946
+ if (index < hb_array_size(array)) {
937
947
  AST_NODE_T* potential_close = hb_array_get(array, index);
938
948
 
939
949
  if (potential_close && potential_close->type == AST_ERB_CONTENT_NODE) {
@@ -965,7 +975,7 @@ static size_t process_control_structure(
965
975
 
966
976
  if (end_node) {
967
977
  end_position = end_node->base.location.end;
968
- } else if (children && children->size > 0) {
978
+ } else if (hb_array_size(children) > 0) {
969
979
  AST_NODE_T* last_child = hb_array_last(children);
970
980
  end_position = last_child->location.end;
971
981
  }
@@ -995,7 +1005,7 @@ static size_t process_control_structure(
995
1005
  AST_NODE_T* subsequent = NULL;
996
1006
  AST_ERB_END_NODE_T* end_node = NULL;
997
1007
 
998
- if (index < array->size) {
1008
+ if (index < hb_array_size(array)) {
999
1009
  AST_NODE_T* next_node = hb_array_get(array, index);
1000
1010
 
1001
1011
  if (next_node && next_node->type == AST_ERB_CONTENT_NODE) {
@@ -1008,7 +1018,7 @@ static size_t process_control_structure(
1008
1018
  }
1009
1019
  }
1010
1020
 
1011
- if (index < array->size) {
1021
+ if (index < hb_array_size(array)) {
1012
1022
  AST_NODE_T* potential_end = hb_array_get(array, index);
1013
1023
 
1014
1024
  if (potential_end && potential_end->type == AST_ERB_CONTENT_NODE) {
@@ -1070,7 +1080,7 @@ static size_t process_subsequent_block(
1070
1080
  hb_array_free(&children);
1071
1081
  }
1072
1082
 
1073
- if (index < array->size) {
1083
+ if (index < hb_array_size(array)) {
1074
1084
  AST_NODE_T* next_node = hb_array_get(array, index);
1075
1085
 
1076
1086
  if (next_node && next_node->type == AST_ERB_CONTENT_NODE) {
@@ -1128,7 +1138,7 @@ static size_t process_block_children(
1128
1138
  analyze_ruby_context_T* context,
1129
1139
  control_type_t parent_type
1130
1140
  ) {
1131
- while (index < array->size) {
1141
+ while (index < hb_array_size(array)) {
1132
1142
  AST_NODE_T* child = hb_array_get(array, index);
1133
1143
 
1134
1144
  if (!child) { break; }
@@ -1150,7 +1160,7 @@ static size_t process_block_children(
1150
1160
  hb_array_T* temp_array = hb_array_init(1);
1151
1161
  size_t new_index = process_control_structure(node, array, index, temp_array, context, child_type);
1152
1162
 
1153
- if (temp_array->size > 0) { hb_array_append(children_array, hb_array_first(temp_array)); }
1163
+ if (hb_array_size(temp_array) > 0) { hb_array_append(children_array, hb_array_first(temp_array)); }
1154
1164
 
1155
1165
  hb_array_free(&temp_array);
1156
1166
 
@@ -1166,10 +1176,10 @@ static size_t process_block_children(
1166
1176
  }
1167
1177
 
1168
1178
  hb_array_T* rewrite_node_array(AST_NODE_T* node, hb_array_T* array, analyze_ruby_context_T* context) {
1169
- hb_array_T* new_array = hb_array_init(array->size);
1179
+ hb_array_T* new_array = hb_array_init(hb_array_size(array));
1170
1180
  size_t index = 0;
1171
1181
 
1172
- while (index < array->size) {
1182
+ while (index < hb_array_size(array)) {
1173
1183
  AST_NODE_T* item = hb_array_get(array, index);
1174
1184
 
1175
1185
  if (!item) { break; }
@@ -1304,7 +1314,7 @@ static bool detect_invalid_erb_structures(const AST_NODE_T* node, void* data) {
1304
1314
  if (if_node->end_node == NULL) { check_erb_node_for_missing_end(node); }
1305
1315
 
1306
1316
  if (if_node->statements != NULL) {
1307
- for (size_t i = 0; i < if_node->statements->size; i++) {
1317
+ for (size_t i = 0; i < hb_array_size(if_node->statements); i++) {
1308
1318
  AST_NODE_T* statement = (AST_NODE_T*) hb_array_get(if_node->statements, i);
1309
1319
 
1310
1320
  if (statement != NULL) { herb_visit_node(statement, detect_invalid_erb_structures, context); }
@@ -1336,7 +1346,7 @@ static bool detect_invalid_erb_structures(const AST_NODE_T* node, void* data) {
1336
1346
  const AST_ERB_IF_NODE_T* elsif_node = (const AST_ERB_IF_NODE_T*) subsequent;
1337
1347
 
1338
1348
  if (elsif_node->statements != NULL) {
1339
- for (size_t i = 0; i < elsif_node->statements->size; i++) {
1349
+ for (size_t i = 0; i < hb_array_size(elsif_node->statements); i++) {
1340
1350
  AST_NODE_T* statement = (AST_NODE_T*) hb_array_get(elsif_node->statements, i);
1341
1351
 
1342
1352
  if (statement != NULL) { herb_visit_node(statement, detect_invalid_erb_structures, context); }
@@ -1348,7 +1358,7 @@ static bool detect_invalid_erb_structures(const AST_NODE_T* node, void* data) {
1348
1358
  const AST_ERB_ELSE_NODE_T* else_node = (const AST_ERB_ELSE_NODE_T*) subsequent;
1349
1359
 
1350
1360
  if (else_node->statements != NULL) {
1351
- for (size_t i = 0; i < else_node->statements->size; i++) {
1361
+ for (size_t i = 0; i < hb_array_size(else_node->statements); i++) {
1352
1362
  AST_NODE_T* statement = (AST_NODE_T*) hb_array_get(else_node->statements, i);
1353
1363
 
1354
1364
  if (statement != NULL) { herb_visit_node(statement, detect_invalid_erb_structures, context); }
@@ -1,5 +1,5 @@
1
1
  // NOTE: This file is generated by the templates/template.rb script and should not
2
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.5/templates/src/analyze_missing_end.c.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.7/templates/src/analyze_missing_end.c.erb
3
3
 
4
4
  #include "include/analyze_helpers.h"
5
5
  #include "include/errors.h"
@@ -1,5 +1,5 @@
1
1
  // NOTE: This file is generated by the templates/template.rb script and should not
2
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.5/templates/src/analyze_transform.c.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.7/templates/src/analyze_transform.c.erb
3
3
 
4
4
  #include "include/analyze.h"
5
5
  #include "include/visitor.h"
@@ -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 node->errors->size;
46
+ return hb_array_size(node->errors);
47
47
  }
48
48
 
49
49
  hb_array_T* ast_node_errors(const AST_NODE_T* node) {