@herb-tools/core 0.8.1 → 0.8.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.
@@ -1,4 +1,4 @@
1
- import { Node, ERBNode, ERBContentNode, HTMLElementNode, HTMLOpenTagNode, HTMLCloseTagNode, HTMLAttributeNameNode } from "./nodes.js";
1
+ import { Node, ERBNode, ERBContentNode, HTMLElementNode, HTMLOpenTagNode, HTMLCloseTagNode, HTMLAttributeNameNode, HTMLCommentNode } from "./nodes.js";
2
2
  import type { Location } from "./location.js";
3
3
  import type { Position } from "./position.js";
4
4
  export type ERBOutputNode = ERBNode & {
@@ -6,10 +6,19 @@ export type ERBOutputNode = ERBNode & {
6
6
  value: "<%=" | "<%==";
7
7
  };
8
8
  };
9
+ export type ERBCommentNode = ERBNode & {
10
+ tag_opening: {
11
+ value: "<%#";
12
+ };
13
+ };
9
14
  /**
10
15
  * Checks if a node is an ERB output node (generates content: <%= %> or <%== %>)
11
16
  */
12
17
  export declare function isERBOutputNode(node: Node): node is ERBOutputNode;
18
+ /**
19
+ * Checks if a node is a ERB comment node (control flow: <%# %>)
20
+ */
21
+ export declare function isERBCommentNode(node: Node): node is ERBCommentNode;
13
22
  /**
14
23
  * Checks if a node is a non-output ERB node (control flow: <% %>)
15
24
  */
@@ -77,7 +86,7 @@ export declare function getTagName(node: HTMLElementNode | HTMLOpenTagNode | HTM
77
86
  /**
78
87
  * Check if a node is a comment (HTML comment or ERB comment)
79
88
  */
80
- export declare function isCommentNode(node: Node): boolean;
89
+ export declare function isCommentNode(node: Node): node is HTMLCommentNode | ERBCommentNode;
81
90
  /**
82
91
  * Compares two positions to determine if they are equal
83
92
  * Returns true if pos1 and pos2 are at the same location
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@herb-tools/core",
3
- "version": "0.8.1",
3
+ "version": "0.8.3",
4
4
  "description": "Core module exporting shared interfaces, AST node definitions, and common utilities for Herb",
5
5
  "license": "MIT",
6
6
  "homepage": "https://herb-tools.dev",
package/src/ast-utils.ts CHANGED
@@ -19,11 +19,11 @@ import {
19
19
  } from "./nodes.js"
20
20
 
21
21
  import {
22
- isNode,
23
22
  isAnyOf,
24
23
  isLiteralNode,
25
24
  isERBNode,
26
25
  isERBContentNode,
26
+ isHTMLCommentNode,
27
27
  areAllOfType,
28
28
  filterLiteralNodes
29
29
  } from "./node-type-guards.js"
@@ -37,6 +37,12 @@ export type ERBOutputNode = ERBNode & {
37
37
  }
38
38
  }
39
39
 
40
+ export type ERBCommentNode = ERBNode & {
41
+ tag_opening: {
42
+ value: "<%#"
43
+ }
44
+ }
45
+
40
46
  /**
41
47
  * Checks if a node is an ERB output node (generates content: <%= %> or <%== %>)
42
48
  */
@@ -47,6 +53,17 @@ export function isERBOutputNode(node: Node): node is ERBOutputNode {
47
53
  return ["<%=", "<%=="].includes(node.tag_opening?.value)
48
54
  }
49
55
 
56
+ /**
57
+ * Checks if a node is a ERB comment node (control flow: <%# %>)
58
+ */
59
+ export function isERBCommentNode(node: Node): node is ERBCommentNode {
60
+ if (!isERBNode(node)) return false
61
+ if (!node.tag_opening?.value) return false
62
+
63
+ return node.tag_opening?.value === "<%#" || (node.tag_opening?.value !== "<%#" && (node.content?.value || "").trimStart().startsWith("#"))
64
+ }
65
+
66
+
50
67
  /**
51
68
  * Checks if a node is a non-output ERB node (control flow: <% %>)
52
69
  */
@@ -200,8 +217,8 @@ export function getTagName(node: HTMLElementNode | HTMLOpenTagNode | HTMLCloseTa
200
217
  /**
201
218
  * Check if a node is a comment (HTML comment or ERB comment)
202
219
  */
203
- export function isCommentNode(node: Node): boolean {
204
- return isNode(node, HTMLCommentNode) || (isERBNode(node) && !isERBControlFlowNode(node))
220
+ export function isCommentNode(node: Node): node is HTMLCommentNode | ERBCommentNode {
221
+ return isHTMLCommentNode(node) || isERBCommentNode(node)
205
222
  }
206
223
 
207
224
  /**
package/src/errors.ts 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.8.1/templates/javascript/packages/core/src/errors.ts.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.3/templates/javascript/packages/core/src/errors.ts.erb
3
3
 
4
4
  import { Location, SerializedLocation } from "./location.js"
5
5
  import { Token, SerializedToken } from "./token.js"
@@ -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.1/templates/javascript/packages/core/src/node-type-guards.ts.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.3/templates/javascript/packages/core/src/node-type-guards.ts.erb
3
3
 
4
4
  import type { Node, NodeType, ERBNode } from "./nodes.js"
5
5
 
package/src/nodes.ts 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.8.1/templates/javascript/packages/core/src/nodes.ts.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.3/templates/javascript/packages/core/src/nodes.ts.erb
3
3
 
4
4
  import { Location } from "./location.js"
5
5
  import { Token, SerializedToken } from "./token.js"
package/src/visitor.ts 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.8.1/templates/javascript/packages/core/src/visitor.ts.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.3/templates/javascript/packages/core/src/visitor.ts.erb
3
3
 
4
4
  import {
5
5
  Node,