diff --git a/packages/eslint-scope/lib/assert.js b/packages/eslint-scope/lib/assert.js new file mode 100644 index 00000000..6300bce7 --- /dev/null +++ b/packages/eslint-scope/lib/assert.js @@ -0,0 +1,17 @@ +/** + * @fileoverview Assertion utilities. + * @author Nicholas C. Zakas + */ + +/** + * Throws an error if the given condition is not truthy. + * @param {boolean} condition The condition to check. + * @param {string} message The message to include with the error. + * @returns {void} + * @throws {Error} When the condition is not truthy. + */ +export function assert(condition, message = "Assertion failed.") { + if (!condition) { + throw new Error(message); + } +} diff --git a/packages/eslint-scope/lib/index.js b/packages/eslint-scope/lib/index.js index 5a27d062..7e79c923 100644 --- a/packages/eslint-scope/lib/index.js +++ b/packages/eslint-scope/lib/index.js @@ -46,7 +46,7 @@ * @module escope */ -import assert from "node:assert"; +import { assert } from "./assert.js"; import ScopeManager from "./scope-manager.js"; import Referencer from "./referencer.js"; diff --git a/packages/eslint-scope/lib/referencer.js b/packages/eslint-scope/lib/referencer.js index cf6ea999..f939aa83 100644 --- a/packages/eslint-scope/lib/referencer.js +++ b/packages/eslint-scope/lib/referencer.js @@ -28,7 +28,7 @@ import Reference from "./reference.js"; import Variable from "./variable.js"; import PatternVisitor from "./pattern-visitor.js"; import { Definition, ParameterDefinition } from "./definition.js"; -import assert from "node:assert"; +import { assert } from "./assert.js"; const { Syntax } = estraverse; diff --git a/packages/eslint-scope/lib/scope-manager.js b/packages/eslint-scope/lib/scope-manager.js index 077b0491..a136648f 100644 --- a/packages/eslint-scope/lib/scope-manager.js +++ b/packages/eslint-scope/lib/scope-manager.js @@ -36,7 +36,7 @@ import { SwitchScope, WithScope } from "./scope.js"; -import assert from "node:assert"; +import { assert } from "./assert.js"; /** * @constructor ScopeManager diff --git a/packages/eslint-scope/lib/scope.js b/packages/eslint-scope/lib/scope.js index 6c3f3cfe..b3ef0266 100644 --- a/packages/eslint-scope/lib/scope.js +++ b/packages/eslint-scope/lib/scope.js @@ -27,7 +27,7 @@ import estraverse from "estraverse"; import Reference from "./reference.js"; import Variable from "./variable.js"; import { Definition } from "./definition.js"; -import assert from "node:assert"; +import { assert } from "./assert.js"; const { Syntax } = estraverse;