transform-ast.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.transformFromAstSync = exports.transformFromAstAsync = exports.transformFromAst = void 0;
  6. function _gensync() {
  7. const data = require("gensync");
  8. _gensync = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. var _config = require("./config");
  14. var _transformation = require("./transformation");
  15. const transformFromAstRunner = _gensync()(function* (ast, code, opts) {
  16. const config = yield* (0, _config.default)(opts);
  17. if (config === null) return null;
  18. if (!ast) throw new Error("No AST given");
  19. return yield* (0, _transformation.run)(config, code, ast);
  20. });
  21. const transformFromAst = function transformFromAst(ast, code, optsOrCallback, maybeCallback) {
  22. let opts;
  23. let callback;
  24. if (typeof optsOrCallback === "function") {
  25. callback = optsOrCallback;
  26. opts = undefined;
  27. } else {
  28. opts = optsOrCallback;
  29. callback = maybeCallback;
  30. }
  31. if (callback === undefined) {
  32. {
  33. return transformFromAstRunner.sync(ast, code, opts);
  34. }
  35. }
  36. transformFromAstRunner.errback(ast, code, opts, callback);
  37. };
  38. exports.transformFromAst = transformFromAst;
  39. const transformFromAstSync = transformFromAstRunner.sync;
  40. exports.transformFromAstSync = transformFromAstSync;
  41. const transformFromAstAsync = transformFromAstRunner.async;
  42. exports.transformFromAstAsync = transformFromAstAsync;
  43. 0 && 0;