index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _helperPluginUtils = require("@babel/helper-plugin-utils");
  7. var _helperReplaceSupers = require("@babel/helper-replace-supers");
  8. var _core = require("@babel/core");
  9. function replacePropertySuper(path, getObjectRef, file) {
  10. const replaceSupers = new _helperReplaceSupers.default({
  11. getObjectRef: getObjectRef,
  12. methodPath: path,
  13. file: file
  14. });
  15. replaceSupers.replace();
  16. }
  17. var _default = (0, _helperPluginUtils.declare)(api => {
  18. api.assertVersion(7);
  19. return {
  20. name: "transform-object-super",
  21. visitor: {
  22. ObjectExpression(path, state) {
  23. let objectRef;
  24. const getObjectRef = () => objectRef = objectRef || path.scope.generateUidIdentifier("obj");
  25. path.get("properties").forEach(propPath => {
  26. if (!propPath.isMethod()) return;
  27. replacePropertySuper(propPath, getObjectRef, state.file);
  28. });
  29. if (objectRef) {
  30. path.scope.push({
  31. id: _core.types.cloneNode(objectRef)
  32. });
  33. path.replaceWith(_core.types.assignmentExpression("=", _core.types.cloneNode(objectRef), path.node));
  34. }
  35. }
  36. }
  37. };
  38. });
  39. exports.default = _default;