You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.3 KiB

4 years ago
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.wrapWithTypes = wrapWithTypes;
  4. exports.getTypes = getTypes;
  5. exports.runtimeProperty = runtimeProperty;
  6. exports.isReference = isReference;
  7. exports.replaceWithOrRemove = replaceWithOrRemove;
  8. /**
  9. * Copyright (c) 2014-present, Facebook, Inc.
  10. *
  11. * This source code is licensed under the MIT license found in the
  12. * LICENSE file in the root directory of this source tree.
  13. */
  14. var currentTypes = null;
  15. function wrapWithTypes(types, fn) {
  16. return function () {
  17. var oldTypes = currentTypes;
  18. currentTypes = types;
  19. try {
  20. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  21. args[_key] = arguments[_key];
  22. }
  23. return fn.apply(this, args);
  24. } finally {
  25. currentTypes = oldTypes;
  26. }
  27. };
  28. }
  29. function getTypes() {
  30. return currentTypes;
  31. }
  32. function runtimeProperty(name) {
  33. var t = getTypes();
  34. return t.memberExpression(t.identifier("regeneratorRuntime"), t.identifier(name), false);
  35. }
  36. function isReference(path) {
  37. return path.isReferenced() || path.parentPath.isAssignmentExpression({
  38. left: path.node
  39. });
  40. }
  41. function replaceWithOrRemove(path, replacement) {
  42. if (replacement) {
  43. path.replaceWith(replacement);
  44. } else {
  45. path.remove();
  46. }
  47. }