1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-29 16:30:56 -05:00
denoland-deno/ext/node/polyfills/_util/asserts.ts

25 lines
736 B
TypeScript
Raw Normal View History

// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
/** Assertion error class for node compat layer's internal code. */
export class NodeCompatAssertionError extends Error {
constructor(message: string) {
super(message);
this.name = "NodeCompatAssertionError";
}
}
/** Make an assertion, if not `true`, then throw. */
export function assert(expr: unknown, msg = ""): asserts expr {
if (!expr) {
throw new NodeCompatAssertionError(msg);
}
}
/** Use this to assert unreachable code. */
export function unreachable(): never {
throw new NodeCompatAssertionError("unreachable");
}