Urara-Blog/node_modules/.pnpm-store/v3/files/04/89456fca176d7b9a0803d83ba51e8030667768f8e0e85c63ecb1efa86c324240f1b0f20a42ea3f081fe476fd5c5daafd452efb977bf47010f7286322bef820
2022-08-14 01:14:53 +08:00

28 lines
No EOL
1.1 KiB
Text

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NullThrowsReasons = exports.nullThrows = void 0;
/**
* A set of common reasons for calling nullThrows
*/
const NullThrowsReasons = {
MissingParent: 'Expected node to have a parent.',
MissingToken: (token, thing) => `Expected to find a ${token} for the ${thing}.`,
};
exports.NullThrowsReasons = NullThrowsReasons;
/**
* Assert that a value must not be null or undefined.
* This is a nice explicit alternative to the non-null assertion operator.
*/
function nullThrows(value, message) {
// this function is primarily used to keep types happy in a safe way
// i.e. is used when we expect that a value is never nullish
// this means that it's pretty much impossible to test the below if...
// so ignore it in coverage metrics.
/* istanbul ignore if */
if (value === null || value === undefined) {
throw new Error(`Non-null Assertion Failed: ${message}`);
}
return value;
}
exports.nullThrows = nullThrows;
//# sourceMappingURL=nullThrows.js.map