UNPKG

rc-js-util

Version:

A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.

58 lines 1.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports._Production = void 0; const _debug_js_1 = require("../debug/_debug.js"); /** * @public * Utilities for production builds. */ class _Production { /** * @deprecated * Throws an `Error` with the given message. If `_BUILD.DEBUG` is true and `_BUILD.DISABLE_BREAKPOINT_FLAG` is false or unset then a breakpoint will be hit first. * Should not be used for "expected" errors (bad input etc). */ static error(message) { if (_BUILD.DEBUG) { if (!_debug_js_1._Debug.isFlagSet("DISABLE_BREAKPOINT")) { _debug_js_1._Debug.breakpoint(); } } throw new Error(message); } /** * Creates an `Error` with the given message. If `_BUILD.DEBUG` is true and `_BUILD.DISABLE_BREAKPOINT_FLAG` is false or unset then a breakpoint will be hit first. * Should not be used for "expected" errors (bad input etc). */ static createError(message) { if (_BUILD.DEBUG) { if (!_debug_js_1._Debug.isFlagSet("DISABLE_BREAKPOINT")) { _debug_js_1._Debug.breakpoint(); } } return new Error(message); } /** * A function that will error if ever called. The parameter is asserted to be never, useful with switch statements, union types etc. * * @example * ```typescript * // adding extra values to the enum will cause a compiler error * enum ETest { Foo = 1 }; * function test(value: ETest) * { * switch (value) { * case ETest.Foo: return "potato"; * default: return _Production.assertValueIsNever(value); * } * } * ``` */ static assertValueIsNever(_value) { throw _Production.createError("unexpected code path executed."); } constructor() { } } exports._Production = _Production; //# sourceMappingURL=_production.js.map