removal-hooks.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.hooks = void 0;
  6. const hooks = [function (self, parent) {
  7. const removeParent =
  8. self.key === "test" && (parent.isWhile() || parent.isSwitchCase()) ||
  9. self.key === "declaration" && parent.isExportDeclaration() ||
  10. self.key === "body" && parent.isLabeledStatement() ||
  11. self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 1 ||
  12. self.key === "expression" && parent.isExpressionStatement();
  13. if (removeParent) {
  14. parent.remove();
  15. return true;
  16. }
  17. }, function (self, parent) {
  18. if (parent.isSequenceExpression() && parent.node.expressions.length === 1) {
  19. parent.replaceWith(parent.node.expressions[0]);
  20. return true;
  21. }
  22. }, function (self, parent) {
  23. if (parent.isBinary()) {
  24. if (self.key === "left") {
  25. parent.replaceWith(parent.node.right);
  26. } else {
  27. parent.replaceWith(parent.node.left);
  28. }
  29. return true;
  30. }
  31. }, function (self, parent) {
  32. if (parent.isIfStatement() && self.key === "consequent" || self.key === "body" && (parent.isLoop() || parent.isArrowFunctionExpression())) {
  33. self.replaceWith({
  34. type: "BlockStatement",
  35. body: []
  36. });
  37. return true;
  38. }
  39. }];
  40. exports.hooks = hooks;
  41. //# sourceMappingURL=removal-hooks.js.map