hooks.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.defineCommonJSHook = defineCommonJSHook;
  6. exports.makeInvokers = makeInvokers;
  7. const commonJSHooksKey = "@babel/plugin-transform-modules-commonjs/customWrapperPlugin";
  8. function defineCommonJSHook(file, hook) {
  9. let hooks = file.get(commonJSHooksKey);
  10. if (!hooks) file.set(commonJSHooksKey, hooks = []);
  11. hooks.push(hook);
  12. }
  13. function findMap(arr, cb) {
  14. if (arr) {
  15. for (const el of arr) {
  16. const res = cb(el);
  17. if (res != null) return res;
  18. }
  19. }
  20. }
  21. function makeInvokers(file) {
  22. const hooks = file.get(commonJSHooksKey);
  23. return {
  24. getWrapperPayload(...args) {
  25. return findMap(hooks, hook => hook.getWrapperPayload == null ? void 0 : hook.getWrapperPayload(...args));
  26. },
  27. wrapReference(...args) {
  28. return findMap(hooks, hook => hook.wrapReference == null ? void 0 : hook.wrapReference(...args));
  29. },
  30. buildRequireWrapper(...args) {
  31. return findMap(hooks, hook => hook.buildRequireWrapper == null ? void 0 : hook.buildRequireWrapper(...args));
  32. }
  33. };
  34. }
  35. //# sourceMappingURL=hooks.js.map