transpile.d.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132
  1. import type { TranspileOptions, TranspileResults } from '../internal/index';
  2. /**
  3. * The `transpile()` function inputs source code as a string, with various options
  4. * within the second argument. The function is stateless and returns a `Promise` of the
  5. * results, including diagnostics and the transpiled code. The `transpile()` function
  6. * does not handle any bundling, minifying, or precompiling any CSS preprocessing like
  7. * Sass or Less. The `transpileSync()` equivalent is available so the same function
  8. * it can be called synchronously. However, TypeScript must be already loaded within
  9. * the global for it to work, where as the async `transpile()` function will load
  10. * TypeScript automatically.
  11. *
  12. * Since TypeScript is used, the source code will transpile from TypeScript to JavaScript,
  13. * and does not require Babel presets. Additionally, the results includes an `imports`
  14. * array of all the import paths found in the source file. The transpile options can be
  15. * used to set the `module` format, such as `cjs`, and JavaScript `target` version, such
  16. * as `es2017`.
  17. *
  18. * @param code the code to transpile
  19. * @param opts options for the transpilation process
  20. * @returns a Promise wrapping the results of the transpilation
  21. */
  22. export declare const transpile: (code: string, opts?: TranspileOptions) => Promise<TranspileResults>;
  23. /**
  24. * Synchronous equivalent of the `transpile()` function. When used in a browser
  25. * environment, TypeScript must already be available globally, where as the async
  26. * `transpile()` function will load TypeScript automatically.
  27. *
  28. * @param code the code to transpile
  29. * @param opts options for the transpilation process
  30. * @returns the results of the transpilation
  31. */
  32. export declare const transpileSync: (code: string, opts?: TranspileOptions) => TranspileResults;