UNPKG

1.47 kBTypeScriptView Raw
1import { types, ConfigAPI, NodePath } from '@babel/core';
2import { TemplateBuilder } from '@babel/template';
3
4interface TemplateVariables {
5 componentName: string;
6 interfaces: types.TSInterfaceDeclaration[];
7 props: (types.ObjectPattern | types.Identifier)[];
8 imports: types.ImportDeclaration[];
9 exports: (types.VariableDeclaration | types.ExportDeclaration | types.Statement)[];
10 jsx: types.JSXElement;
11}
12interface TemplateContext {
13 options: Options;
14 tpl: TemplateBuilder<types.Statement | types.Statement[]>['ast'];
15}
16interface Template {
17 (variables: TemplateVariables, context: TemplateContext): types.Statement | types.Statement[];
18}
19interface State {
20 componentName: string;
21 caller?: {
22 previousExport?: string | null;
23 };
24}
25interface JSXRuntimeImport {
26 source: string;
27 namespace?: string;
28 specifiers?: string[];
29}
30interface Options {
31 typescript?: boolean;
32 titleProp?: boolean;
33 expandProps?: boolean | 'start' | 'end';
34 ref?: boolean;
35 template?: Template;
36 state: State;
37 native?: boolean;
38 memo?: boolean;
39 exportType?: 'named' | 'default';
40 namedExport?: string;
41 jsxRuntime?: 'automatic' | 'classic';
42 jsxRuntimeImport?: JSXRuntimeImport;
43 importSource?: string;
44}
45
46declare const plugin: (_: ConfigAPI, opts: Options) => {
47 visitor: {
48 Program(path: NodePath<types.Program>): void;
49 };
50};
51
52export { Options, Template, plugin as default };