index.d.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { types, ConfigAPI, NodePath } from '@babel/core';
  2. import { TemplateBuilder } from '@babel/template';
  3. interface TemplateVariables {
  4. componentName: string;
  5. interfaces: types.TSInterfaceDeclaration[];
  6. props: (types.ObjectPattern | types.Identifier)[];
  7. imports: types.ImportDeclaration[];
  8. exports: (types.VariableDeclaration | types.ExportDeclaration | types.Statement)[];
  9. jsx: types.JSXElement;
  10. }
  11. interface TemplateContext {
  12. options: Options;
  13. tpl: TemplateBuilder<types.Statement | types.Statement[]>['ast'];
  14. }
  15. interface Template {
  16. (variables: TemplateVariables, context: TemplateContext): types.Statement | types.Statement[];
  17. }
  18. interface State {
  19. componentName: string;
  20. caller?: {
  21. previousExport?: string | null;
  22. };
  23. }
  24. interface JSXRuntimeImport {
  25. source: string;
  26. namespace?: string;
  27. specifiers?: string[];
  28. }
  29. interface Options {
  30. typescript?: boolean;
  31. titleProp?: boolean;
  32. descProp?: 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. declare const plugin: (_: ConfigAPI, opts: Options) => {
  46. visitor: {
  47. Program(path: NodePath<types.Program>): void;
  48. };
  49. };
  50. export { Options, Template, plugin as default };