diff --git a/packages/eslint-scope/lib/index.js b/packages/eslint-scope/lib/index.js index 5a27d062..74baa74c 100644 --- a/packages/eslint-scope/lib/index.js +++ b/packages/eslint-scope/lib/index.js @@ -46,14 +46,13 @@ * @module escope */ -import assert from "node:assert"; - import ScopeManager from "./scope-manager.js"; import Referencer from "./referencer.js"; import Reference from "./reference.js"; import Variable from "./variable.js"; - import eslintScopeVersion from "./version.js"; +import { assert } from "./util/assert.js"; + /** * Set the default options diff --git a/packages/eslint-scope/lib/referencer.js b/packages/eslint-scope/lib/referencer.js index cf6ea999..4016a9c5 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 "./util/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..f06f1357 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 "./util/assert.js"; /** * @constructor ScopeManager diff --git a/packages/eslint-scope/lib/scope.js b/packages/eslint-scope/lib/scope.js index 6c3f3cfe..694b2f82 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 "./util/assert.js"; const { Syntax } = estraverse; diff --git a/packages/eslint-scope/lib/util/assert.js b/packages/eslint-scope/lib/util/assert.js new file mode 100644 index 00000000..3680ecf5 --- /dev/null +++ b/packages/eslint-scope/lib/util/assert.js @@ -0,0 +1,18 @@ +/** + * @fileoverview This file provides a utility function `assert` that checks whether a given condition is true + * and throws an error with a specified message if the condition is false. + * @author Amaresh S M + */ + +/** + * Asserts that a condition is true. If the condition is false, an error is thrown with the provided message. + * @param {boolean} condition The condition that is being asserted. If `false`, an error will be thrown. + * @param {string} [message="Assertion failed."] The error message that will be thrown if the condition is false. + * @returns {void} + * @throws {Error} Throws an error if the condition is not met. + */ +export function assert(condition, message = "Assertion failed.") { + if (!condition) { + throw new Error(message); + } +} diff --git a/packages/eslint-scope/rollup.config.js b/packages/eslint-scope/rollup.config.js index 135e147a..564ff2f7 100644 --- a/packages/eslint-scope/rollup.config.js +++ b/packages/eslint-scope/rollup.config.js @@ -1,6 +1,6 @@ export default { input: "./lib/index.js", - external: ["assert", "estraverse", "esrecurse"], + external: ["estraverse", "esrecurse"], treeshake: false, output: { format: "cjs",