UNPKG

@sentry/utils

Version:
29 lines (26 loc) 988 B
/** * Polyfill for the nullish coalescing operator (`??`). * * Note that the RHS is wrapped in a function so that if it's a computed value, that evaluation won't happen unless the * LHS evaluates to a nullish value, to mimic the operator's short-circuiting behavior. * * Adapted from Sucrase (https://github.com/alangpierce/sucrase) * * @param lhs The value of the expression to the left of the `??` * @param rhsFn A function returning the value of the expression to the right of the `??` * @returns The LHS value, unless it's `null` or `undefined`, in which case, the RHS value */ function _nullishCoalesce(lhs, rhsFn) { // by checking for loose equality to `null`, we catch both `null` and `undefined` return lhs != null ? lhs : rhsFn(); } // Sucrase version: // function _nullishCoalesce(lhs, rhsFn) { // if (lhs != null) { // return lhs; // } else { // return rhsFn(); // } // } export { _nullishCoalesce }; //# sourceMappingURL=_nullishCoalesce.js.map