@@ -10,7 +10,7 @@ import {
1010import { isPromise } from 'ramda-adjunct' ;
1111
1212import { Path } from './Path.ts' ;
13- import type { VisitorFn } from './Path.ts' ;
13+ import type { VisitorFn , VisitorResult } from './Path.ts' ;
1414
1515/**
1616 * Enter/leave visitor structure for a specific node type.
@@ -21,23 +21,6 @@ export interface NodeVisitor<TNode, TVisitor = unknown> {
2121 leave ?: VisitorFn < TNode , TVisitor > ;
2222}
2323
24- /**
25- * Visitor object structure.
26- * Visitors can have:
27- * - `enter`/`leave` for generic callbacks
28- * - Type-specific methods like `StringElement(path) {}`
29- * - Type-specific enter/leave like `StringElement: { enter, leave }`
30- * - Any other properties (for class-based visitors)
31- *
32- * Note: Class-based visitors must add `[key: string]: unknown;` index signature.
33- * @public
34- */
35- export type Visitor < TNode > = {
36- enter ?: VisitorFn < TNode > | Record < string , VisitorFn < TNode > > ;
37- leave ?: VisitorFn < TNode > | Record < string , VisitorFn < TNode > > ;
38- [ key : string ] : unknown ;
39- } ;
40-
4124// =============================================================================
4225// Default implementations for ApiDOM
4326// =============================================================================
@@ -154,7 +137,7 @@ const lookup = (record: Record<string, unknown>, type: string): unknown => {
154137 * @public
155138 */
156139export const getVisitFn = < TNode > (
157- visitor : Visitor < TNode > ,
140+ visitor : object ,
158141 type : string | undefined ,
159142 isLeaving : boolean ,
160143) : VisitorFn < TNode > | null => {
@@ -237,7 +220,7 @@ export interface MergedVisitorAsync<TNode> {
237220 * @public
238221 */
239222export const mergeVisitors = < TNode > (
240- visitors : Visitor < TNode > [ ] ,
223+ visitors : object [ ] ,
241224 options : MergeVisitorsOptions < TNode > = { } ,
242225) : MergedVisitor < TNode > => {
243226 const {
@@ -253,13 +236,13 @@ export const mergeVisitors = <TNode>(
253236 const skipping : ( symbol | TNode ) [ ] = new Array ( visitors . length ) . fill ( internalSkipSymbol ) ;
254237
255238 return {
256- enter ( path : Path < TNode > ) {
239+ enter ( path : Path < TNode > ) : VisitorResult < TNode > {
257240 let currentNode = path . node ;
258241 let hasChanged = false ;
259242
260243 for ( let i = 0 ; i < visitors . length ; i += 1 ) {
261244 if ( skipping [ i ] === internalSkipSymbol ) {
262- const visitFn = visitFnGetter ( visitors [ i ] , nodeTypeGetter ( currentNode ) , false ) ;
245+ const visitFn = visitFnGetter < TNode > ( visitors [ i ] , nodeTypeGetter ( currentNode ) , false ) ;
263246
264247 if ( typeof visitFn === 'function' ) {
265248 // Create a proxy path that tracks changes per-visitor
@@ -320,12 +303,12 @@ export const mergeVisitors = <TNode>(
320303 return undefined ;
321304 } ,
322305
323- leave ( path : Path < TNode > ) {
306+ leave ( path : Path < TNode > ) : VisitorResult < TNode > {
324307 const currentNode = path . node ;
325308
326309 for ( let i = 0 ; i < visitors . length ; i += 1 ) {
327310 if ( skipping [ i ] === internalSkipSymbol ) {
328- const visitFn = visitFnGetter ( visitors [ i ] , nodeTypeGetter ( currentNode ) , true ) ;
311+ const visitFn = visitFnGetter < TNode > ( visitors [ i ] , nodeTypeGetter ( currentNode ) , true ) ;
329312
330313 if ( typeof visitFn === 'function' ) {
331314 // Create a proxy path for leave phase
@@ -376,7 +359,7 @@ export const mergeVisitors = <TNode>(
376359 * @public
377360 */
378361export const mergeVisitorsAsync = < TNode > (
379- visitors : Visitor < TNode > [ ] ,
362+ visitors : object [ ] ,
380363 options : MergeVisitorsOptions < TNode > = { } ,
381364) : MergedVisitorAsync < TNode > => {
382365 const {
@@ -390,13 +373,13 @@ export const mergeVisitorsAsync = <TNode>(
390373 const skipping : ( symbol | TNode ) [ ] = new Array ( visitors . length ) . fill ( internalSkipSymbol ) ;
391374
392375 return {
393- async enter ( path : Path < TNode > ) {
376+ async enter ( path : Path < TNode > ) : Promise < void | TNode | undefined > {
394377 let currentNode = path . node ;
395378 let hasChanged = false ;
396379
397380 for ( let i = 0 ; i < visitors . length ; i += 1 ) {
398381 if ( skipping [ i ] === internalSkipSymbol ) {
399- const visitFn = visitFnGetter ( visitors [ i ] , nodeTypeGetter ( currentNode ) , false ) ;
382+ const visitFn = visitFnGetter < TNode > ( visitors [ i ] , nodeTypeGetter ( currentNode ) , false ) ;
400383
401384 if ( typeof visitFn === 'function' ) {
402385 const proxyPath = createPathProxy ( path , currentNode ) ;
@@ -446,12 +429,12 @@ export const mergeVisitorsAsync = <TNode>(
446429 return undefined ;
447430 } ,
448431
449- async leave ( path : Path < TNode > ) {
432+ async leave ( path : Path < TNode > ) : Promise < void | TNode | undefined > {
450433 const currentNode = path . node ;
451434
452435 for ( let i = 0 ; i < visitors . length ; i += 1 ) {
453436 if ( skipping [ i ] === internalSkipSymbol ) {
454- const visitFn = visitFnGetter ( visitors [ i ] , nodeTypeGetter ( currentNode ) , true ) ;
437+ const visitFn = visitFnGetter < TNode > ( visitors [ i ] , nodeTypeGetter ( currentNode ) , true ) ;
455438
456439 if ( typeof visitFn === 'function' ) {
457440 const proxyPath = createPathProxy ( path , currentNode ) ;
0 commit comments