FileState.d.ts 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. import type { HubInterface, Scope, Visitor } from '@babel/traverse';
  2. import { NodePath } from '@babel/traverse';
  3. import type { File, Program } from '@babel/types';
  4. import type { Importer, ImportPath } from './importer/index.js';
  5. import type { TransformOptions } from '@babel/core';
  6. export default class FileState {
  7. #private;
  8. opts: TransformOptions;
  9. path: NodePath<Program>;
  10. ast: File;
  11. scope: Scope;
  12. code: string;
  13. hub: HubInterface;
  14. constructor(options: TransformOptions, { code, ast, importer }: {
  15. code: string;
  16. ast: File;
  17. importer: Importer;
  18. });
  19. /**
  20. * Try to resolve and import the ImportPath with the `name`
  21. */
  22. import(path: ImportPath, name: string): NodePath | null;
  23. /**
  24. * Parse the content of a new file
  25. * The `filename` is required so that potential imports inside the content can be correctly resolved and
  26. * the correct babel config file could be loaded. `filename` needs to be an absolute path.
  27. */
  28. parse(code: string, filename: string): FileState;
  29. traverse<S>(visitors: Visitor<S>, state?: S): void;
  30. traverse(visitors: Visitor): void;
  31. }