Skip to content

Commit

Permalink
refactor: change type signature of cli plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jbl428 committed Oct 22, 2023
1 parent b5951bf commit f61875f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions lib/plugin/compiler-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ function isFilenameMatched(patterns: string[], filename: string): boolean {
export const before: (
options: Record<string, any> | undefined,
program: ts.Program,
) => (ctx: ts.TransformationContext) => ts.Transformer<any> = (
) => ts.TransformerFactory<ts.SourceFile> | ts.CustomTransformerFactory = (
options,
program,
) => {
const mergedOption = mergePluginOptions(options);

return (ctx: ts.TransformationContext): ts.Transformer<any> => {
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;
};
};
};
4 changes: 2 additions & 2 deletions lib/plugin/visitors/http-interface.visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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(
Expand Down

0 comments on commit f61875f

Please sign in to comment.