removal-hooks.js 1.3 KB

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