@@ -16,7 +16,8 @@ export function generateJSDoc(filePath: string): void {
16
16
17
17
const printer = ts . createPrinter ( { newLine : ts . NewLineKind . LineFeed } ) ;
18
18
19
- function visit ( node : ts . Node ) : ts . Node {
19
+ // Visit function that processes each node
20
+ function visit ( node : ts . Node , context : ts . TransformationContext ) : ts . Node {
20
21
if ( ts . isFunctionDeclaration ( node ) && node . name ) {
21
22
const jsDoc = createJSDoc ( node . name . text , node . parameters , node . type ) ;
22
23
ts . addSyntheticLeadingComment (
@@ -56,32 +57,20 @@ export function generateJSDoc(filePath: string): void {
56
57
return node ;
57
58
}
58
59
59
- return ts . visitEachChild ( node , visit , context ) ;
60
+ return ts . visitEachChild ( node , ( child ) => visit ( child , context ) , context ) ; // Pass context to visit
60
61
}
61
62
62
- // Create a transformation context
63
- const context : ts . TransformationContext = {
64
- factory : ts . factory ,
65
- startLexicalEnvironment : ( ) => { } ,
66
- endLexicalEnvironment : ( ) => [ ] ,
67
- suspendLexicalEnvironment : ( ) => { } ,
68
- resumeLexicalEnvironment : ( ) => { } ,
69
- requestEmitHelper : ( ) => { } ,
70
- readEmitHelpers : ( ) => undefined ,
71
- enableSubstitution : ( ) => { } ,
72
- isSubstitutionEnabled : ( ) => false ,
73
- onSubstituteNode : ( hint , node ) => node ,
74
- enableEmitNotification : ( ) => { } ,
75
- isEmitNotificationEnabled : ( ) => false ,
76
- onEmitNode : ( hint , node , emitCallback ) => emitCallback ( hint , node ) ,
77
- getCompilerOptions : ( ) => ( { } as ts . CompilerOptions ) ,
78
- hoistFunctionDeclaration : ( ) => { } ,
79
- hoistVariableDeclaration : ( ) => { } ,
63
+ // Create the transformer
64
+ const transformer : ts . TransformerFactory < ts . SourceFile > = ( context ) => {
65
+ return ( sourceFile ) => {
66
+ return ts . visitNode ( sourceFile , ( node ) =>
67
+ visit ( node , context )
68
+ ) as ts . SourceFile ; // Pass context to visit
69
+ } ;
80
70
} ;
81
71
82
- const result = ts . transform ( sourceFile , [
83
- ( context ) => ( rootNode ) => ts . visitNode ( rootNode , visit ) ,
84
- ] ) ;
72
+ // Apply the transformer
73
+ const result = ts . transform ( sourceFile , [ transformer ] ) ;
85
74
const transformedSourceFile = result . transformed [ 0 ] as ts . SourceFile ;
86
75
const updatedCode = printer . printFile ( transformedSourceFile ) ;
87
76
0 commit comments