util.js 949 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.willPathCastToBoolean = willPathCastToBoolean;
  6. function willPathCastToBoolean(path) {
  7. const maybeWrapped = path;
  8. const {
  9. node,
  10. parentPath
  11. } = maybeWrapped;
  12. if (parentPath.isLogicalExpression()) {
  13. const {
  14. operator,
  15. right
  16. } = parentPath.node;
  17. if (operator === "&&" || operator === "||" || operator === "??" && node === right) {
  18. return willPathCastToBoolean(parentPath);
  19. }
  20. }
  21. if (parentPath.isSequenceExpression()) {
  22. const {
  23. expressions
  24. } = parentPath.node;
  25. if (expressions[expressions.length - 1] === node) {
  26. return willPathCastToBoolean(parentPath);
  27. } else {
  28. return true;
  29. }
  30. }
  31. return parentPath.isConditional({
  32. test: node
  33. }) || parentPath.isUnaryExpression({
  34. operator: "!"
  35. }) || parentPath.isLoop({
  36. test: node
  37. });
  38. }
  39. //# sourceMappingURL=util.js.map