Urara-Blog/node_modules/.pnpm-store/v3/files/33/5f4ae9d74c71cf1c76d35c8c5a3a58a2361e0da884b01dbc471239fc3b2ba54a55970894f24dbfd01eb92240cb21de92063192ed6edc82bdd760ef69350254
2022-08-14 01:14:53 +08:00

45 lines
No EOL
1.1 KiB
Text

"use strict";
exports.__esModule = true;
exports.default = void 0;
/**
* Safari 10.3 had an issue where async arrow function expressions within any class method would throw.
* After an initial fix, any references to the instance via `this` within those methods would also throw.
* This is fixed by converting arrow functions in class methods into equivalent function expressions.
* @see https://bugs.webkit.org/show_bug.cgi?id=166879
*
* @example
* class X{ a(){ async () => {}; } } // throws
* class X{ a(){ async function() {}; } } // works
*
* @example
* class X{ a(){
* async () => this.a; // throws
* } }
* class X{ a(){
* var _this=this;
* async function() { return _this.a }; // works
* } }
*/
const OPTS = {
allowInsertArrow: false,
specCompliant: false
};
var _default = ({
types: t
}) => ({
name: "transform-async-arrows-in-class",
visitor: {
ArrowFunctionExpression(path) {
if (path.node.async && path.findParent(t.isClassMethod)) {
path.arrowFunctionToExpression(OPTS);
}
}
}
});
exports.default = _default;
module.exports = exports.default;