directive-to-hof
Version:
Transform directives into a higher order function
29 lines (28 loc) • 891 B
TypeScript
export interface DirectiveTransformerOptions {
/**
* The directive to look for in the code.
*/
directive: string;
/**
* The path to the module to import from.
*/
importPath: string;
/**
* The name of the import to use.
*/
importName: string;
/**
* Whether to only allow async functions.
*/
asyncOnly?: boolean;
}
/**
* Creates a transformer that looks for a specific directive in the code and rewrites it accordingly by
* wrapping the function in a call to the imported higher-order function.
* @param options The options for the transformer.
* @returns A function that takes the source code and arguments and returns the transformed code.
*/
export declare function createDirectiveTransformer(options: DirectiveTransformerOptions): (source: string, args: any) => Promise<{
contents: any;
loader: any;
}>;