convert.js 916 B

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = void 0;
  4. var _state = require("./state");
  5. var _config = require("./config");
  6. var _plugins = require("./plugins");
  7. function run(code, config, state) {
  8. const expandedState = (0, _state.expandState)(state);
  9. const plugins = (0, _plugins.getPlugins)(config, state).map(_plugins.resolvePlugin);
  10. let nextCode = String(code).replace('\0', ''); // eslint-disable-next-line no-restricted-syntax
  11. for (const plugin of plugins) {
  12. nextCode = plugin(nextCode, config, expandedState);
  13. }
  14. return nextCode;
  15. }
  16. async function convert(code, config = {}, state = {}) {
  17. config = await (0, _config.loadConfig)(config, state);
  18. return run(code, config, state);
  19. }
  20. convert.sync = (code, config = {}, state = {}) => {
  21. config = _config.loadConfig.sync(config, state);
  22. return run(code, config, state);
  23. };
  24. var _default = convert;
  25. exports.default = _default;