transform-BfdLLNnY.mjs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { n as __toESM, t as require_binding } from "./binding-C5G6_6ql.mjs";
  2. import { a as bindingifySourcemap, n as normalizeBindingError } from "./error-CP8smW_P.mjs";
  3. //#region src/utils/minify.ts
  4. var import_binding = /* @__PURE__ */ __toESM(require_binding(), 1);
  5. /**
  6. * Minify asynchronously.
  7. *
  8. * Note: This function can be slower than {@linkcode minifySync} due to the overhead of spawning a thread.
  9. *
  10. * @category Utilities
  11. * @experimental
  12. */
  13. async function minify(filename, sourceText, options) {
  14. const inputMap = bindingifySourcemap(options?.inputMap);
  15. const result = await (0, import_binding.minify)(filename, sourceText, options);
  16. if (result.map && inputMap) result.map = {
  17. version: 3,
  18. ...(0, import_binding.collapseSourcemaps)([inputMap, bindingifySourcemap(result.map)])
  19. };
  20. return result;
  21. }
  22. /**
  23. * Minify synchronously.
  24. *
  25. * @category Utilities
  26. * @experimental
  27. */
  28. function minifySync(filename, sourceText, options) {
  29. const inputMap = bindingifySourcemap(options?.inputMap);
  30. const result = (0, import_binding.minifySync)(filename, sourceText, options);
  31. if (result.map && inputMap) result.map = {
  32. version: 3,
  33. ...(0, import_binding.collapseSourcemaps)([inputMap, bindingifySourcemap(result.map)])
  34. };
  35. return result;
  36. }
  37. //#endregion
  38. //#region src/utils/transform.ts
  39. /**
  40. * Transpile a JavaScript or TypeScript into a target ECMAScript version, asynchronously.
  41. *
  42. * Note: This function can be slower than `transformSync` due to the overhead of spawning a thread.
  43. *
  44. * @param filename The name of the file being transformed. If this is a
  45. * relative path, consider setting the {@linkcode TransformOptions#cwd} option.
  46. * @param sourceText The source code to transform.
  47. * @param options The transform options including tsconfig and inputMap. See {@linkcode TransformOptions} for more information.
  48. * @param cache Optional tsconfig cache for reusing resolved tsconfig across multiple transforms.
  49. * Only used when `options.tsconfig` is `true`.
  50. *
  51. * @returns a promise that resolves to an object containing the transformed code,
  52. * source maps, and any errors that occurred during parsing or transformation.
  53. *
  54. * @category Utilities
  55. * @experimental
  56. */
  57. async function transform(filename, sourceText, options, cache) {
  58. const result = await (0, import_binding.enhancedTransform)(filename, sourceText, options, cache);
  59. return {
  60. ...result,
  61. errors: result.errors.map(normalizeBindingError),
  62. warnings: result.warnings.map((w) => w.field0)
  63. };
  64. }
  65. /**
  66. * Transpile a JavaScript or TypeScript into a target ECMAScript version.
  67. *
  68. * @param filename The name of the file being transformed. If this is a
  69. * relative path, consider setting the {@linkcode TransformOptions#cwd} option.
  70. * @param sourceText The source code to transform.
  71. * @param options The transform options including tsconfig and inputMap. See {@linkcode TransformOptions} for more information.
  72. * @param cache Optional tsconfig cache for reusing resolved tsconfig across multiple transforms.
  73. * Only used when `options.tsconfig` is `true`.
  74. *
  75. * @returns an object containing the transformed code, source maps, and any errors
  76. * that occurred during parsing or transformation.
  77. *
  78. * @category Utilities
  79. * @experimental
  80. */
  81. function transformSync(filename, sourceText, options, cache) {
  82. const result = (0, import_binding.enhancedTransformSync)(filename, sourceText, options, cache);
  83. return {
  84. ...result,
  85. errors: result.errors.map(normalizeBindingError),
  86. warnings: result.warnings.map((w) => w.field0)
  87. };
  88. }
  89. //#endregion
  90. export { minifySync as a, minify as i, transform as n, transformSync as r, import_binding as t };