@herb-tools/formatter 0.6.1 → 0.7.1

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.
package/dist/index.cjs CHANGED
@@ -198,7 +198,7 @@ class Token {
198
198
  }
199
199
 
200
200
  // NOTE: This file is generated by the templates/template.rb script and should not
201
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.1/templates/javascript/packages/core/src/errors.ts.erb
201
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.1/templates/javascript/packages/core/src/errors.ts.erb
202
202
  class HerbError {
203
203
  type;
204
204
  message;
@@ -648,7 +648,7 @@ function convertToUTF8(string) {
648
648
  }
649
649
 
650
650
  // NOTE: This file is generated by the templates/template.rb script and should not
651
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.1/templates/javascript/packages/core/src/nodes.ts.erb
651
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.1/templates/javascript/packages/core/src/nodes.ts.erb
652
652
  class Node {
653
653
  type;
654
654
  location;
@@ -688,7 +688,7 @@ class Node {
688
688
  return "∅\n";
689
689
  if (array.length === 0)
690
690
  return "[]\n";
691
- let output = `(${array.length} item${array.length == 1 ? "" : "s"})\n`;
691
+ let output = `(${array.length} item${array.length === 1 ? "" : "s"})\n`;
692
692
  array.forEach((item, index) => {
693
693
  const isLast = index === array.length - 1;
694
694
  if (item instanceof Node || item instanceof HerbError) {
@@ -712,7 +712,7 @@ class Node {
712
712
  .treeInspect()
713
713
  .trimStart()
714
714
  .split("\n")
715
- .map((line, index) => index == 0 ? line.trimStart() : `${prefix}${prefix2}${line}`)
715
+ .map((line, index) => index === 0 ? line.trimStart() : `${prefix}${prefix2}${line}`)
716
716
  .join("\n")
717
717
  .trimStart();
718
718
  output += `\n`;
@@ -953,6 +953,7 @@ class HTMLElementNode extends Node {
953
953
  body;
954
954
  close_tag;
955
955
  is_void;
956
+ source;
956
957
  static get type() {
957
958
  return "AST_HTML_ELEMENT_NODE";
958
959
  }
@@ -966,6 +967,7 @@ class HTMLElementNode extends Node {
966
967
  body: (data.body || []).map(node => fromSerializedNode(node)),
967
968
  close_tag: data.close_tag ? fromSerializedNode((data.close_tag)) : null,
968
969
  is_void: data.is_void,
970
+ source: data.source,
969
971
  });
970
972
  }
971
973
  constructor(props) {
@@ -975,6 +977,7 @@ class HTMLElementNode extends Node {
975
977
  this.body = props.body;
976
978
  this.close_tag = props.close_tag;
977
979
  this.is_void = props.is_void;
980
+ this.source = props.source;
978
981
  }
979
982
  accept(visitor) {
980
983
  visitor.visitHTMLElementNode(this);
@@ -1006,6 +1009,7 @@ class HTMLElementNode extends Node {
1006
1009
  body: this.body.map(node => node.toJSON()),
1007
1010
  close_tag: this.close_tag ? this.close_tag.toJSON() : null,
1008
1011
  is_void: this.is_void,
1012
+ source: this.source,
1009
1013
  };
1010
1014
  }
1011
1015
  treeInspect() {
@@ -1016,7 +1020,8 @@ class HTMLElementNode extends Node {
1016
1020
  output += `├── tag_name: ${this.tag_name ? this.tag_name.treeInspect() : "∅"}\n`;
1017
1021
  output += `├── body: ${this.inspectArray(this.body, "│ ")}`;
1018
1022
  output += `├── close_tag: ${this.inspectNode(this.close_tag, "│ ")}`;
1019
- output += `└── is_void: ${typeof this.is_void === 'boolean' ? String(this.is_void) : "∅"}\n`;
1023
+ output += `├── is_void: ${typeof this.is_void === 'boolean' ? String(this.is_void) : "∅"}\n`;
1024
+ output += `└── source: ${this.source ? JSON.stringify(this.source) : "∅"}\n`;
1020
1025
  return output;
1021
1026
  }
1022
1027
  }
@@ -2877,7 +2882,7 @@ class ParseResult extends Result {
2877
2882
  }
2878
2883
 
2879
2884
  // NOTE: This file is generated by the templates/template.rb script and should not
2880
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.1/templates/javascript/packages/core/src/node-type-guards.ts.erb
2885
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.1/templates/javascript/packages/core/src/node-type-guards.ts.erb
2881
2886
  /**
2882
2887
  * Type guard functions for AST nodes.
2883
2888
  * These functions provide type checking by combining both instanceof
@@ -3262,7 +3267,11 @@ function isParseResult(object) {
3262
3267
  * Checks if a node is an ERB output node (generates content: <%= %> or <%== %>)
3263
3268
  */
3264
3269
  function isERBOutputNode(node) {
3265
- return isNode(node, ERBContentNode) && ["<%=", "<%=="].includes(node.tag_opening?.value);
3270
+ if (!isNode(node, ERBContentNode))
3271
+ return false;
3272
+ if (!node.tag_opening?.value)
3273
+ return false;
3274
+ return ["<%=", "<%=="].includes(node.tag_opening?.value);
3266
3275
  }
3267
3276
  /**
3268
3277
  * Checks if a node is a non-output ERB node (control flow: <% %>)
@@ -3360,7 +3369,7 @@ function getNodesAfterPosition(nodes, position, inclusive = true) {
3360
3369
  }
3361
3370
 
3362
3371
  // NOTE: This file is generated by the templates/template.rb script and should not
3363
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.1/templates/javascript/packages/core/src/visitor.ts.erb
3372
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.1/templates/javascript/packages/core/src/visitor.ts.erb
3364
3373
  class Visitor {
3365
3374
  visit(node) {
3366
3375
  if (!node)
@@ -3589,6 +3598,8 @@ class Printer extends Visitor {
3589
3598
  * @throws {Error} When node has parse errors and ignoreErrors is false
3590
3599
  */
3591
3600
  print(input, options = DEFAULT_PRINT_OPTIONS) {
3601
+ if (!input)
3602
+ return "";
3592
3603
  if (isToken(input)) {
3593
3604
  return input.value;
3594
3605
  }