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