util.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.getTypes = getTypes;
  6. exports.isReference = isReference;
  7. exports.replaceWithOrRemove = replaceWithOrRemove;
  8. exports.runtimeProperty = runtimeProperty;
  9. exports.wrapWithTypes = wrapWithTypes;
  10. let currentTypes = null;
  11. function wrapWithTypes(types, fn) {
  12. return function (...args) {
  13. const oldTypes = currentTypes;
  14. currentTypes = types;
  15. try {
  16. return fn.apply(this, args);
  17. } finally {
  18. currentTypes = oldTypes;
  19. }
  20. };
  21. }
  22. function getTypes() {
  23. return currentTypes;
  24. }
  25. function runtimeProperty(name) {
  26. const t = getTypes();
  27. return t.memberExpression(t.identifier("regeneratorRuntime"), t.identifier(name), false);
  28. }
  29. function isReference(path) {
  30. return path.isReferenced() || path.parentPath.isAssignmentExpression({
  31. left: path.node
  32. });
  33. }
  34. function replaceWithOrRemove(path, replacement) {
  35. if (replacement) {
  36. path.replaceWith(replacement);
  37. } else {
  38. path.remove();
  39. }
  40. }
  41. //# sourceMappingURL=util.js.map