Repository: eslint/eslint
File: lib/languages/js/source-code/source-code.js (JavaScript)

Code before:
//------------------------------------------------------------------------------
// Private
//------------------------------------------------------------------------------

const commentParser = new ConfigCommentParser();

const CODE_PATH_EVENTS = [
    "onCodePathStart",
    "onCodePathEnd",
    "onCodePathSegmentStart",
    "onCodePathSegmentEnd",
    "onCodePathSegmentLoop",
    "onUnreachableCodePathSegmentStart",
    "onUnreachableCodePathSegmentEnd"
];

/**
 * Validates that the given AST has the required information.
 * @param {ASTNode} ast The Program node of the AST to check.
 * @throws {Error} If the AST doesn't contain the correct information.
 * @returns {void}
 * @private
 */
function validate(ast) {
    if (!ast) {
        throw new Error(`AST is ${ast}.`);
    }

    if (!ast.tokens) {
        throw new Error("AST is missing the tokens array.");
    }

    if (!ast.comments) {
        throw new Error("AST is missing the comments array.");
    }

    if (!ast.loc) {
        throw new Error("AST is missing location information.");
    }

    if (!ast.range) {
        throw new Error("AST is missing range information");
    }
}

/**
 * Retrieves globals for the given ecmaVersion.
 * @param {number} ecmaVersion The version to retrieve globals for.
 * @returns {Object} The globals for the given ecmaVersion.
 */
function getGlobalsForEcmaVersion(ecmaVersion) {

Review comment (suggestion):
I'm not sure this is clear enough. It's stating what is but doesn't give any indication as to why it's undesirable. Something like this may be better:

```suggestion
        throw new TypeError(`Unexpected empty AST. (${ast})`);
```

Code after:
//------------------------------------------------------------------------------
// Private
//------------------------------------------------------------------------------

const commentParser = new ConfigCommentParser();

const CODE_PATH_EVENTS = [
    "onCodePathStart",
    "onCodePathEnd",
    "onCodePathSegmentStart",
    "onCodePathSegmentEnd",
    "onCodePathSegmentLoop",
    "onUnreachableCodePathSegmentStart",
    "onUnreachableCodePathSegmentEnd"
];

/**
 * Validates that the given AST has the required information.
 * @param {ASTNode} ast The Program node of the AST to check.
 * @throws {Error} If the AST doesn't contain the correct information.
 * @returns {void}
 * @private
 */
function validate(ast) {
    if (!ast) {
        throw new TypeError(`Unexpected empty AST. (${ast})`);
    }

    if (!ast.tokens) {
        throw new TypeError("AST is missing the tokens array.");
    }

    if (!ast.comments) {
        throw new TypeError("AST is missing the comments array.");
    }

    if (!ast.loc) {
        throw new TypeError("AST is missing location information.");
    }

    if (!ast.range) {
        throw new TypeError("AST is missing range information");
    }
}

/**
 * Retrieves globals for the given ecmaVersion.
 * @param {number} ecmaVersion The version to retrieve globals for.
 * @returns {Object} The globals for the given ecmaVersion.
 */
function getGlobalsForEcmaVersion(ecmaVersion) {