_asyncNullishCoalesce.js 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. import { _nullishCoalesce } from './_nullishCoalesce.js';
  2. // https://github.com/alangpierce/sucrase/tree/265887868966917f3b924ce38dfad01fbab1329f
  3. /**
  4. * Polyfill for the nullish coalescing operator (`??`), when used in situations where at least one of the values is the
  5. * result of an async operation.
  6. *
  7. * Note that the RHS is wrapped in a function so that if it's a computed value, that evaluation won't happen unless the
  8. * LHS evaluates to a nullish value, to mimic the operator's short-circuiting behavior.
  9. *
  10. * Adapted from Sucrase (https://github.com/alangpierce/sucrase)
  11. *
  12. * @param lhs The value of the expression to the left of the `??`
  13. * @param rhsFn A function returning the value of the expression to the right of the `??`
  14. * @returns The LHS value, unless it's `null` or `undefined`, in which case, the RHS value
  15. */
  16. async function _asyncNullishCoalesce(lhs, rhsFn) {
  17. return _nullishCoalesce(lhs, rhsFn);
  18. }
  19. // Sucrase version:
  20. // async function _asyncNullishCoalesce(lhs, rhsFn) {
  21. // if (lhs != null) {
  22. // return lhs;
  23. // } else {
  24. // return await rhsFn();
  25. // }
  26. // }
  27. export { _asyncNullishCoalesce };
  28. //# sourceMappingURL=_asyncNullishCoalesce.js.map