parse.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.parseAsync = exports.parseSync = exports.parse = 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 _parser = _interopRequireDefault(require("./parser"));
  15. var _normalizeOpts = _interopRequireDefault(require("./transformation/normalize-opts"));
  16. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  17. const parseRunner = (0, _gensync().default)(function* parse(code, opts) {
  18. const config = yield* (0, _config.default)(opts);
  19. if (config === null) {
  20. return null;
  21. }
  22. return yield* (0, _parser.default)(config.passes, (0, _normalizeOpts.default)(config), code);
  23. });
  24. const parse = function parse(code, opts, callback) {
  25. if (typeof opts === "function") {
  26. callback = opts;
  27. opts = undefined;
  28. }
  29. if (callback === undefined) return parseRunner.sync(code, opts);
  30. parseRunner.errback(code, opts, callback);
  31. };
  32. exports.parse = parse;
  33. const parseSync = parseRunner.sync;
  34. exports.parseSync = parseSync;
  35. const parseAsync = parseRunner.async;
  36. exports.parseAsync = parseAsync;