From f61875f8ccc4ea1ad51808314acbffab6863254e Mon Sep 17 00:00:00 2001 From: Jake Son Date: Sun, 22 Oct 2023 10:21:48 +0900 Subject: [PATCH] refactor: change type signature of cli plugin --- lib/plugin/compiler-plugin.ts | 12 ++++++------ lib/plugin/visitors/http-interface.visitor.ts | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/plugin/compiler-plugin.ts b/lib/plugin/compiler-plugin.ts index f825c10..bec2460 100644 --- a/lib/plugin/compiler-plugin.ts +++ b/lib/plugin/compiler-plugin.ts @@ -11,24 +11,24 @@ function isFilenameMatched(patterns: string[], filename: string): boolean { export const before: ( options: Record | undefined, program: ts.Program, -) => (ctx: ts.TransformationContext) => ts.Transformer = ( +) => ts.TransformerFactory | ts.CustomTransformerFactory = ( options, program, ) => { const mergedOption = mergePluginOptions(options); - return (ctx: ts.TransformationContext): ts.Transformer => { - return (sf: ts.SourceFile) => { + return (ctx) => { + return (sourceFile) => { if ( isFilenameMatched( mergedOption.interfaceFilenameSuffix as string[], - sf.fileName, + sourceFile.fileName, ) ) { - return httpInterfaceVisitor.visit(sf, ctx, program); + return httpInterfaceVisitor.visit(sourceFile, ctx, program); } - return sf; + return sourceFile; }; }; }; diff --git a/lib/plugin/visitors/http-interface.visitor.ts b/lib/plugin/visitors/http-interface.visitor.ts index 17d7c5d..da2dd9a 100644 --- a/lib/plugin/visitors/http-interface.visitor.ts +++ b/lib/plugin/visitors/http-interface.visitor.ts @@ -40,7 +40,7 @@ export class HttpInterfaceVisitor { sourceFile: ts.SourceFile, ctx: ts.TransformationContext, program: ts.Program, - ): ts.Node { + ): ts.SourceFile { this.importSet.clear(); const factory = ctx.factory; const typeChecker = program.getTypeChecker(); @@ -61,7 +61,7 @@ export class HttpInterfaceVisitor { return ts.visitEachChild(node, visitNode, ctx); }; - return ts.visitNode(sourceFile, visitNode); + return ts.visitNode(sourceFile, visitNode) as ts.SourceFile; } private updateSourceFile(