transform-ast.js 1.4 KB

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