Sha256: ddc701954b56958e07a46ec3ea66fb52c70b053828e0b32cb9e4bd26a7a2b0cb

Contents?: true

Size: 1018 Bytes

Versions: 35

Compression:

Stored size: 1018 Bytes

Contents

/**
 * 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,
};

export default ({ types: t }) => ({
  name: "transform-async-arrows-in-class",
  visitor: {
    ArrowFunctionExpression(path) {
      if (path.node.async && path.findParent(t.isClassMethod)) {
        path.arrowFunctionToExpression(OPTS);
      }
    },
  },
});

Version data entries

35 entries across 34 versions & 7 rubygems

Version Path
immosquare-cleaner-0.1.62 node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
immosquare-cleaner-0.1.61 node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
immosquare-cleaner-0.1.60 node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
immosquare-cleaner-0.1.59 node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
immosquare-cleaner-0.1.58 node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
immosquare-cleaner-0.1.57 node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
immosquare-cleaner-0.1.56 node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
immosquare-cleaner-0.1.55 node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
immosquare-cleaner-0.1.54 node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
immosquare-cleaner-0.1.53 node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
immosquare-cleaner-0.1.52 node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
immosquare-cleaner-0.1.51 node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
immosquare-cleaner-0.1.50 node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
immosquare-cleaner-0.1.49 node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
immosquare-cleaner-0.1.48 node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
immosquare-cleaner-0.1.47 node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
immosquare-cleaner-0.1.46 node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
immosquare-cleaner-0.1.45 node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
optimacms-0.1.61 spec/dummy/node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
disco_app-0.16.1 test/dummy/node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js