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
disco_app-0.15.2 test/dummy/node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
disco_app-0.18.4 test/dummy/node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
disco_app-0.18.1 test/dummy/node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
disco_app-0.14.0 test/dummy/node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
tang-0.2.1 spec/tang_app/node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
tang-0.2.0 spec/tang_app/node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
tang-0.1.0 spec/tang_app/node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
tang-0.0.9 spec/tang_app/node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js
condenser-0.3 lib/condenser/processors/node_modules/@babel/preset-modules/src/plugins/transform-async-arrows-in-class/index.js