_asyncNullishCoalesce.js 1.3 KB

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