transform.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.transformAsync = exports.transformSync = exports.transform = 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 transformRunner = (0, _gensync().default)(function* transform(code, opts) {
  17. const config = yield* (0, _config.default)(opts);
  18. if (config === null) return null;
  19. return yield* (0, _transformation.run)(config, code);
  20. });
  21. const transform = function transform(code, opts, callback) {
  22. if (typeof opts === "function") {
  23. callback = opts;
  24. opts = undefined;
  25. }
  26. if (callback === undefined) return transformRunner.sync(code, opts);
  27. transformRunner.errback(code, opts, callback);
  28. };
  29. exports.transform = transform;
  30. const transformSync = transformRunner.sync;
  31. exports.transformSync = transformSync;
  32. const transformAsync = transformRunner.async;
  33. exports.transformAsync = transformAsync;