@herb-tools/core 0.6.1 → 0.7.0

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.
@@ -143,6 +143,7 @@ export interface SerializedHTMLElementNode extends SerializedNode {
143
143
  body: SerializedNode[];
144
144
  close_tag: SerializedHTMLCloseTagNode | null;
145
145
  is_void: boolean;
146
+ source: string;
146
147
  }
147
148
  export interface HTMLElementNodeProps extends BaseNodeProps {
148
149
  open_tag: HTMLOpenTagNode | null;
@@ -150,6 +151,7 @@ export interface HTMLElementNodeProps extends BaseNodeProps {
150
151
  body: Node[];
151
152
  close_tag: HTMLCloseTagNode | null;
152
153
  is_void: boolean;
154
+ source: string;
153
155
  }
154
156
  export declare class HTMLElementNode extends Node {
155
157
  readonly open_tag: HTMLOpenTagNode | null;
@@ -157,6 +159,7 @@ export declare class HTMLElementNode extends Node {
157
159
  readonly body: Node[];
158
160
  readonly close_tag: HTMLCloseTagNode | null;
159
161
  readonly is_void: boolean;
162
+ readonly source: string;
160
163
  static get type(): NodeType;
161
164
  static from(data: SerializedHTMLElementNode): HTMLElementNode;
162
165
  constructor(props: HTMLElementNodeProps);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@herb-tools/core",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Core module exporting shared interfaces, AST node definitions, and common utilities for Herb",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/ast-utils.ts CHANGED
@@ -34,7 +34,10 @@ import type { Position } from "./position.js"
34
34
  * Checks if a node is an ERB output node (generates content: <%= %> or <%== %>)
35
35
  */
36
36
  export function isERBOutputNode(node: Node): node is ERBContentNode {
37
- return isNode(node, ERBContentNode) && ["<%=", "<%=="].includes((node as ERBContentNode).tag_opening?.value!)
37
+ if (!isNode(node, ERBContentNode)) return false
38
+ if (!node.tag_opening?.value) return false
39
+
40
+ return ["<%=", "<%=="].includes(node.tag_opening?.value)
38
41
  }
39
42
 
40
43
  /**
@@ -183,7 +186,7 @@ export function getCombinedAttributeName(attributeNameNode: HTMLAttributeNameNod
183
186
  /**
184
187
  * Gets the tag name of an HTML element node
185
188
  */
186
- export function getTagName(node: HTMLElementNode | HTMLOpenTagNode | HTMLCloseTagNode): string {
189
+ export function getTagName(node: HTMLElementNode | HTMLOpenTagNode | HTMLCloseTagNode): string {
187
190
  return node.tag_name?.value ?? ""
188
191
  }
189
192
 
@@ -281,7 +284,7 @@ export function getNodesBeforePosition<T extends Node>(nodes: T[], position: Pos
281
284
  }
282
285
 
283
286
  /**
284
- * Gets nodes that start after the specified position
287
+ * Gets nodes that start after the specified position
285
288
  * @param inclusive - If true, includes nodes that start exactly at the position (default: true, matching typical boundary behavior)
286
289
  */
287
290
  export function getNodesAfterPosition<T extends Node>(nodes: T[], position: Position, inclusive = true): T[] {
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.6.1/templates/javascript/packages/core/src/errors.ts.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.0/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,9 +1,9 @@
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.6.1/templates/javascript/packages/core/src/node-type-guards.ts.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.0/templates/javascript/packages/core/src/node-type-guards.ts.erb
3
3
 
4
4
  import type { Node, NodeType, ERBNode } from "./nodes.js"
5
5
 
6
- import { Token } from "./token.js"
6
+ import { Token } from "./token.js"
7
7
  import { ParseResult } from "./parse-result.js"
8
8
 
9
9
  import {
@@ -552,22 +552,22 @@ export function areAllOfType(
552
552
  */
553
553
 
554
554
  export function filterNodes<T extends NodeType[]>(
555
- nodes: Node[] | undefined | null,
555
+ nodes: Node[] | undefined | null,
556
556
  ...types: T
557
557
  ): NodeTypeToClass[T[number]][]
558
558
 
559
559
  export function filterNodes<T extends (new (...args: any[]) => Node)[]>(
560
- nodes: Node[] | undefined | null,
560
+ nodes: Node[] | undefined | null,
561
561
  ...types: T
562
562
  ): ClassToInstance<T[number]>[]
563
563
 
564
564
  export function filterNodes(
565
- nodes: Node[] | undefined | null,
565
+ nodes: Node[] | undefined | null,
566
566
  ...types: Array<(node: Node) => boolean>
567
567
  ): Node[]
568
568
 
569
569
  export function filterNodes(
570
- nodes: Node[] | undefined | null,
570
+ nodes: Node[] | undefined | null,
571
571
  ...types: Array<NodeType | (new (...args: any[]) => Node) | ((node: Node) => boolean)>
572
572
  ): Node[] {
573
573
  if (!nodes) return []
@@ -620,7 +620,7 @@ export function isNode(
620
620
  }
621
621
 
622
622
  export function isToken(object: any): object is Token {
623
- return (object instanceof Token) || (object?.constructor?.name === "Token" && "value" in object) || (object as any).type?.startsWith('TOKEN_')
623
+ return (object instanceof Token) || (object?.constructor?.name === "Token" && "value" in object) || (object as any).type?.startsWith('TOKEN_')
624
624
  }
625
625
 
626
626
  export function isParseResult(object: any): object is ParseResult {
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.6.1/templates/javascript/packages/core/src/nodes.ts.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.0/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"
@@ -80,7 +80,7 @@ export abstract class Node implements BaseNodeProps {
80
80
  if (!array) return "∅\n"
81
81
  if (array.length === 0) return "[]\n"
82
82
 
83
- let output = `(${array.length} item${array.length == 1 ? "" : "s"})\n`
83
+ let output = `(${array.length} item${array.length === 1 ? "" : "s"})\n`
84
84
 
85
85
  array.forEach((item, index) => {
86
86
  const isLast = index === array.length - 1
@@ -122,7 +122,7 @@ export abstract class Node implements BaseNodeProps {
122
122
  .trimStart()
123
123
  .split("\n")
124
124
  .map((line, index) =>
125
- index == 0 ? line.trimStart() : `${prefix}${prefix2}${line}`,
125
+ index === 0 ? line.trimStart() : `${prefix}${prefix2}${line}`,
126
126
  )
127
127
  .join("\n")
128
128
  .trimStart()
@@ -467,6 +467,7 @@ export interface SerializedHTMLElementNode extends SerializedNode {
467
467
  body: SerializedNode[];
468
468
  close_tag: SerializedHTMLCloseTagNode | null;
469
469
  is_void: boolean;
470
+ source: string;
470
471
  }
471
472
 
472
473
  export interface HTMLElementNodeProps extends BaseNodeProps {
@@ -475,6 +476,7 @@ export interface HTMLElementNodeProps extends BaseNodeProps {
475
476
  body: Node[];
476
477
  close_tag: HTMLCloseTagNode | null;
477
478
  is_void: boolean;
479
+ source: string;
478
480
  }
479
481
 
480
482
  export class HTMLElementNode extends Node {
@@ -483,6 +485,7 @@ export class HTMLElementNode extends Node {
483
485
  readonly body: Node[];
484
486
  readonly close_tag: HTMLCloseTagNode | null;
485
487
  readonly is_void: boolean;
488
+ readonly source: string;
486
489
 
487
490
  static get type(): NodeType {
488
491
  return "AST_HTML_ELEMENT_NODE"
@@ -498,6 +501,7 @@ export class HTMLElementNode extends Node {
498
501
  body: (data.body || []).map(node => fromSerializedNode(node)),
499
502
  close_tag: data.close_tag ? fromSerializedNode((data.close_tag)) : null,
500
503
  is_void: data.is_void,
504
+ source: data.source,
501
505
  })
502
506
  }
503
507
 
@@ -508,6 +512,7 @@ export class HTMLElementNode extends Node {
508
512
  this.body = props.body;
509
513
  this.close_tag = props.close_tag;
510
514
  this.is_void = props.is_void;
515
+ this.source = props.source;
511
516
  }
512
517
 
513
518
  accept(visitor: Visitor): void {
@@ -544,6 +549,7 @@ export class HTMLElementNode extends Node {
544
549
  body: this.body.map(node => node.toJSON()),
545
550
  close_tag: this.close_tag ? this.close_tag.toJSON() : null,
546
551
  is_void: this.is_void,
552
+ source: this.source,
547
553
  };
548
554
  }
549
555
 
@@ -556,7 +562,8 @@ export class HTMLElementNode extends Node {
556
562
  output += `├── tag_name: ${this.tag_name ? this.tag_name.treeInspect() : "∅"}\n`;
557
563
  output += `├── body: ${this.inspectArray(this.body, "│ ")}`;
558
564
  output += `├── close_tag: ${this.inspectNode(this.close_tag, "│ ")}`;
559
- output += `└── is_void: ${typeof this.is_void === 'boolean' ? String(this.is_void) : "∅"}\n`;
565
+ output += `├── is_void: ${typeof this.is_void === 'boolean' ? String(this.is_void) : "∅"}\n`;
566
+ output += `└── source: ${this.source ? JSON.stringify(this.source) : "∅"}\n`;
560
567
 
561
568
  return output
562
569
  }
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.6.1/templates/javascript/packages/core/src/visitor.ts.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.0/templates/javascript/packages/core/src/visitor.ts.erb
3
3
 
4
4
  import {
5
5
  Node,