You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB

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