@herb-tools/node 0.7.1 → 0.7.3

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.
@@ -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.7.1";
9
+ var version = "0.7.3";
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.7.1/templates/javascript/packages/node/extension/error_helpers.cpp.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.3/templates/javascript/packages/node/extension/error_helpers.cpp.erb
3
3
 
4
4
  #include <node_api.h>
5
5
  #include "error_helpers.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.7.1/templates/javascript/packages/node/extension/error_helpers.h.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.3/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
@@ -54,7 +54,7 @@ static bool analyze_erb_content(const AST_NODE_T* node, void* data) {
54
54
  if (strcmp(opening, "<%%") != 0 && strcmp(opening, "<%%=") != 0 && strcmp(opening, "<%#") != 0) {
55
55
  analyzed_ruby_T* analyzed = herb_analyze_ruby(erb_content_node->content->value);
56
56
 
57
- if (false) { pretty_print_analyed_ruby(analyzed, erb_content_node->content->value); }
57
+ if (false) { pretty_print_analyzed_ruby(analyzed, erb_content_node->content->value); }
58
58
 
59
59
  erb_content_node->parsed = true;
60
60
  erb_content_node->valid = analyzed->valid;
@@ -1107,7 +1107,8 @@ void herb_analyze_parse_errors(AST_DOCUMENT_NODE_T* document, const char* source
1107
1107
  char* extracted_ruby = herb_extract_ruby_with_semicolons(source);
1108
1108
 
1109
1109
  pm_parser_t parser;
1110
- pm_parser_init(&parser, (const uint8_t*) extracted_ruby, strlen(extracted_ruby), NULL);
1110
+ pm_options_t options = { 0, .partial_script = true };
1111
+ pm_parser_init(&parser, (const uint8_t*) extracted_ruby, strlen(extracted_ruby), &options);
1111
1112
 
1112
1113
  pm_node_t* root = pm_parse(&parser);
1113
1114
 
@@ -1115,16 +1116,11 @@ void herb_analyze_parse_errors(AST_DOCUMENT_NODE_T* document, const char* source
1115
1116
  error = (const pm_diagnostic_t*) error->node.next) {
1116
1117
 
1117
1118
  RUBY_PARSE_ERROR_T* parse_error = ruby_parse_error_from_prism_error(error, (AST_NODE_T*) document, source, &parser);
1118
-
1119
- // TODO: ideally this shouldn't be hard-coded
1120
- if (strcmp(parse_error->diagnostic_id, "invalid_yield") == 0) {
1121
- error_free((ERROR_T*) parse_error);
1122
- } else {
1123
- array_append(document->base.errors, parse_error);
1124
- }
1119
+ array_append(document->base.errors, parse_error);
1125
1120
  }
1126
1121
 
1127
1122
  pm_node_destroy(&parser, root);
1128
1123
  pm_parser_free(&parser);
1124
+ pm_options_free(&options);
1129
1125
  free(extracted_ruby);
1130
1126
  }
@@ -91,9 +91,12 @@ bool search_if_nodes(const pm_node_t* node, void* data) {
91
91
  if (node->type == PM_IF_NODE) {
92
92
  const pm_if_node_t* if_node = (const pm_if_node_t*) node;
93
93
 
94
- // Handle ternary
95
- if (if_node->if_keyword_loc.start != NULL && if_node->if_keyword_loc.end != NULL) {
94
+ bool has_if_keyword = if_node->if_keyword_loc.start != NULL && if_node->if_keyword_loc.end != NULL;
95
+ bool has_end_keyword = if_node->end_keyword_loc.start != NULL && if_node->end_keyword_loc.end != NULL;
96
+
97
+ if (has_if_keyword && has_end_keyword) {
96
98
  analyzed->has_if_node = true;
99
+
97
100
  return true;
98
101
  }
99
102
  }
@@ -198,12 +201,20 @@ bool search_unless_nodes(const pm_node_t* node, void* data) {
198
201
  analyzed_ruby_T* analyzed = (analyzed_ruby_T*) data;
199
202
 
200
203
  if (node->type == PM_UNLESS_NODE) {
201
- analyzed->has_unless_node = true;
202
- return true;
203
- } else {
204
- pm_visit_child_nodes(node, search_unless_nodes, analyzed);
204
+ const pm_unless_node_t* unless_node = (const pm_unless_node_t*) node;
205
+
206
+ bool has_if_keyword = unless_node->keyword_loc.start != NULL && unless_node->keyword_loc.end != NULL;
207
+ bool has_end_keyword = unless_node->end_keyword_loc.start != NULL && unless_node->end_keyword_loc.end != NULL;
208
+
209
+ if (has_if_keyword && has_end_keyword) {
210
+ analyzed->has_unless_node = true;
211
+
212
+ return true;
213
+ }
205
214
  }
206
215
 
216
+ pm_visit_child_nodes(node, search_unless_nodes, analyzed);
217
+
207
218
  return false;
208
219
  }
209
220
 
@@ -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.7.1/templates/src/ast_nodes.c.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.3/templates/src/ast_nodes.c.erb
3
3
 
4
4
  #include <stdio.h>
5
5
  #include <stdbool.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.7.1/templates/src/include/ast_nodes.h.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.3/templates/src/include/ast_nodes.h.erb
3
3
 
4
4
  #ifndef HERB_AST_NODES_H
5
5
  #define HERB_AST_NODES_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.7.1/templates/src/ast_pretty_print.c.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.3/templates/src/ast_pretty_print.c.erb
3
3
 
4
4
  #include "include/ast_node.h"
5
5
  #include "include/ast_nodes.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.7.1/templates/src/include/ast_pretty_print.h.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.3/templates/src/include/ast_pretty_print.h.erb
3
3
 
4
4
  #ifndef HERB_AST_PRETTY_PRINT_H
5
5
  #define HERB_AST_PRETTY_PRINT_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.7.1/templates/src/errors.c.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.3/templates/src/errors.c.erb
3
3
 
4
4
  #include "include/array.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.7.1/templates/src/include/errors.h.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.3/templates/src/include/errors.h.erb
3
3
 
4
4
  #ifndef HERB_ERRORS_H
5
5
  #define HERB_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.7.1/templates/src/include/ast_nodes.h.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.3/templates/src/include/ast_nodes.h.erb
3
3
 
4
4
  #ifndef HERB_AST_NODES_H
5
5
  #define HERB_AST_NODES_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.7.1/templates/src/include/ast_pretty_print.h.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.3/templates/src/include/ast_pretty_print.h.erb
3
3
 
4
4
  #ifndef HERB_AST_PRETTY_PRINT_H
5
5
  #define HERB_AST_PRETTY_PRINT_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.7.1/templates/src/include/errors.h.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.3/templates/src/include/errors.h.erb
3
3
 
4
4
  #ifndef HERB_ERRORS_H
5
5
  #define HERB_ERRORS_H
@@ -88,6 +88,6 @@ void pretty_print_array(
88
88
 
89
89
  void pretty_print_errors(AST_NODE_T* node, size_t indent, size_t relative_indent, bool last_property, buffer_T* buffer);
90
90
 
91
- void pretty_print_analyed_ruby(analyzed_ruby_T* analyzed, const char* source);
91
+ void pretty_print_analyzed_ruby(analyzed_ruby_T* analyzed, const char* source);
92
92
 
93
93
  #endif
@@ -1,6 +1,6 @@
1
1
  #ifndef HERB_VERSION_H
2
2
  #define HERB_VERSION_H
3
3
 
4
- #define HERB_VERSION "0.7.1"
4
+ #define HERB_VERSION "0.7.3"
5
5
 
6
6
  #endif
@@ -555,14 +555,12 @@ static AST_HTML_ATTRIBUTE_VALUE_NODE_T* parser_parse_html_attribute_value(parser
555
555
  return value;
556
556
  }
557
557
 
558
- token_T* token = parser_advance(parser);
559
-
560
558
  append_unexpected_error(
561
559
  "Unexpected Token",
562
560
  "TOKEN_IDENTIFIER, TOKEN_QUOTE, TOKEN_ERB_START",
563
- token_type_to_string(token->type),
564
- token->location->start,
565
- token->location->end,
561
+ token_type_to_string(parser->current_token->type),
562
+ parser->current_token->location->start,
563
+ parser->current_token->location->end,
566
564
  errors
567
565
  );
568
566
 
@@ -571,13 +569,11 @@ static AST_HTML_ATTRIBUTE_VALUE_NODE_T* parser_parse_html_attribute_value(parser
571
569
  children,
572
570
  NULL,
573
571
  false,
574
- token->location->start,
575
- token->location->end,
572
+ parser->current_token->location->start,
573
+ parser->current_token->location->end,
576
574
  errors
577
575
  );
578
576
 
579
- token_free(token);
580
-
581
577
  return value;
582
578
  }
583
579
 
@@ -1135,6 +1131,7 @@ static void parser_parse_in_data_state(parser_T* parser, array_T* children, arra
1135
1131
  parser,
1136
1132
  TOKEN_AMPERSAND,
1137
1133
  TOKEN_AT,
1134
+ TOKEN_BACKTICK,
1138
1135
  TOKEN_CHARACTER,
1139
1136
  TOKEN_COLON,
1140
1137
  TOKEN_DASH,
@@ -254,7 +254,7 @@ void pretty_print_string_property(
254
254
  }
255
255
  }
256
256
 
257
- void pretty_print_analyed_ruby(analyzed_ruby_T* analyzed, const char* source) {
257
+ void pretty_print_analyzed_ruby(analyzed_ruby_T* analyzed, const char* source) {
258
258
  printf(
259
259
  "------------------------\nanalyzed (%p)\n------------------------\n%s\n------------------------\n if: %i\n "
260
260
  " elsif: %i\n else: %i\n end: %i\n block: %i\n block_closing: %i\n case: %i\n when: %i\n for: "
@@ -88,6 +88,6 @@ void pretty_print_array(
88
88
 
89
89
  void pretty_print_errors(AST_NODE_T* node, size_t indent, size_t relative_indent, bool last_property, buffer_T* buffer);
90
90
 
91
- void pretty_print_analyed_ruby(analyzed_ruby_T* analyzed, const char* source);
91
+ void pretty_print_analyzed_ruby(analyzed_ruby_T* analyzed, const char* source);
92
92
 
93
93
  #endif
@@ -1,6 +1,6 @@
1
1
  #ifndef HERB_VERSION_H
2
2
  #define HERB_VERSION_H
3
3
 
4
- #define HERB_VERSION "0.7.1"
4
+ #define HERB_VERSION "0.7.3"
5
5
 
6
6
  #endif
@@ -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.7.1/templates/src/visitor.c.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.3/templates/src/visitor.c.erb
3
3
 
4
4
  #include <stdio.h>
5
5
 
@@ -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.7.1/templates/javascript/packages/node/extension/nodes.cpp.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.3/templates/javascript/packages/node/extension/nodes.cpp.erb
3
3
 
4
4
  #include <node_api.h>
5
5
  #include "error_helpers.h"
package/extension/nodes.h CHANGED
@@ -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.7.1/templates/javascript/packages/node/extension/nodes.h.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.3/templates/javascript/packages/node/extension/nodes.h.erb
3
3
 
4
4
  #ifndef HERB_EXTENSION_NODES_H
5
5
  #define HERB_EXTENSION_NODES_H
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@herb-tools/node",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "Native Node.js addon for HTML-aware ERB parsing using Herb.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -48,7 +48,7 @@
48
48
  "host": "https://github.com/marcoroth/herb/releases/download/"
49
49
  },
50
50
  "dependencies": {
51
- "@herb-tools/core": "0.7.1",
51
+ "@herb-tools/core": "0.7.3",
52
52
  "@mapbox/node-pre-gyp": "^2.0.0",
53
53
  "node-addon-api": "^5.1.0",
54
54
  "node-pre-gyp-github": "^2.0.0"