index.js 917 B

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = function (_ref) {
  4. var t = _ref.types;
  5. return {
  6. visitor: {
  7. ArrowFunctionExpression: function ArrowFunctionExpression(path, state) {
  8. if (state.opts.spec) {
  9. var node = path.node;
  10. if (node.shadow) return;
  11. node.shadow = { this: false };
  12. node.type = "FunctionExpression";
  13. var boundThis = t.thisExpression();
  14. boundThis._forceShadow = path;
  15. path.ensureBlock();
  16. path.get("body").unshiftContainer("body", t.expressionStatement(t.callExpression(state.addHelper("newArrowCheck"), [t.thisExpression(), boundThis])));
  17. path.replaceWith(t.callExpression(t.memberExpression(node, t.identifier("bind")), [t.thisExpression()]));
  18. } else {
  19. path.arrowFunctionToShadowed();
  20. }
  21. }
  22. }
  23. };
  24. };
  25. module.exports = exports["default"];