|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 2 weeks ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1018 bytes
|
| Line | |
|---|
| 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 | });
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.