index.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. "use strict";
  2. exports.__esModule = true;
  3. var _symbol = require("babel-runtime/core-js/symbol");
  4. var _symbol2 = _interopRequireDefault(_symbol);
  5. exports.default = function (_ref) {
  6. var t = _ref.types;
  7. var VISITED = (0, _symbol2.default)();
  8. return {
  9. visitor: {
  10. ExportDefaultDeclaration: function ExportDefaultDeclaration(path) {
  11. if (!path.get("declaration").isClassDeclaration()) return;
  12. var node = path.node;
  13. var ref = node.declaration.id || path.scope.generateUidIdentifier("class");
  14. node.declaration.id = ref;
  15. path.replaceWith(node.declaration);
  16. path.insertAfter(t.exportDefaultDeclaration(ref));
  17. },
  18. ClassDeclaration: function ClassDeclaration(path) {
  19. var node = path.node;
  20. var ref = node.id || path.scope.generateUidIdentifier("class");
  21. path.replaceWith(t.variableDeclaration("let", [t.variableDeclarator(ref, t.toExpression(node))]));
  22. },
  23. ClassExpression: function ClassExpression(path, state) {
  24. var node = path.node;
  25. if (node[VISITED]) return;
  26. var inferred = (0, _babelHelperFunctionName2.default)(path);
  27. if (inferred && inferred !== node) return path.replaceWith(inferred);
  28. node[VISITED] = true;
  29. var Constructor = _vanilla2.default;
  30. if (state.opts.loose) Constructor = _loose2.default;
  31. path.replaceWith(new Constructor(path, state.file).run());
  32. }
  33. }
  34. };
  35. };
  36. var _loose = require("./loose");
  37. var _loose2 = _interopRequireDefault(_loose);
  38. var _vanilla = require("./vanilla");
  39. var _vanilla2 = _interopRequireDefault(_vanilla);
  40. var _babelHelperFunctionName = require("babel-helper-function-name");
  41. var _babelHelperFunctionName2 = _interopRequireDefault(_babelHelperFunctionName);
  42. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  43. module.exports = exports["default"];