index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = void 0;
  4. /**
  5. * Safari 10.3 had an issue where async arrow function expressions within any class method would throw.
  6. * After an initial fix, any references to the instance via `this` within those methods would also throw.
  7. * This is fixed by converting arrow functions in class methods into equivalent function expressions.
  8. * @see https://bugs.webkit.org/show_bug.cgi?id=166879
  9. *
  10. * @example
  11. * class X{ a(){ async () => {}; } } // throws
  12. * class X{ a(){ async function() {}; } } // works
  13. *
  14. * @example
  15. * class X{ a(){
  16. * async () => this.a; // throws
  17. * } }
  18. * class X{ a(){
  19. * var _this=this;
  20. * async function() { return _this.a }; // works
  21. * } }
  22. */
  23. const OPTS = {
  24. allowInsertArrow: false,
  25. specCompliant: false
  26. };
  27. var _default = ({
  28. types: t
  29. }) => ({
  30. name: "transform-async-arrows-in-class",
  31. visitor: {
  32. ArrowFunctionExpression(path) {
  33. if (path.node.async && path.findParent(t.isClassMethod)) {
  34. path.arrowFunctionToExpression(OPTS);
  35. }
  36. }
  37. }
  38. });
  39. exports.default = _default;
  40. module.exports = exports.default;