lib/rules/no-var.js
function hasReferenceInTDZ(node) {
    const initStart = node.range[0];
    const initEnd = node.range[1];

    return variable => {
        const id = variable.defs[0].name;
        const idStart = id.range[0];
        const defaultValue = (id.parent.type === "AssignmentPattern" ? id.parent.right : null);
        const defaultStart = defaultValue && defaultValue.range[0];
        const defaultEnd = defaultValue && defaultValue.range[1];

        return variable.references.some(reference => {
            const start = reference.identifier.range[0];
            const end = reference.identifier.range[1];

            return !reference.init && (
                start < idStart ||
                (defaultValue !== null && start >= defaultStart && end <= defaultEnd) ||
                (start >= initStart && end <= initEnd)
            );
        });
    };
}
function hasReferenceInTDZ(node) {
    const initStart = node.range[0];
    const initEnd = node.range[1];

    return variable => {
        const id = variable.defs[0].name;
        const idStart = id.range[0];
        const defaultValue = (id.parent.type === "AssignmentPattern" ? id.parent.right : null);
        const defaultStart = defaultValue && defaultValue.range[0];
        const defaultEnd = defaultValue && defaultValue.range[1];

        return variable.references.some(reference => {
            const start = reference.identifier.range[0];
            const end = reference.identifier.range[1];

            return !reference.init && (
                start < idStart ||
                (defaultValue !== null && start >= defaultStart && end <= defaultEnd) ||
                (start >= initStart && end <= initEnd)
            );
        });
    };
}
function hasReferenceInTDZ ( node ) { const initStart = node . range [ 0 ] ; const initEnd = node . range [ 1 ] ; return variable => { const id = variable . defs [ 0 ] . name ; const idStart = id . range [ 0 ] ; const defaultValue = ( id . parent . type === "AssignmentPattern" ? id . parent . right : null ) ; const defaultStart = defaultValue && defaultValue . range [ 0 ] ; const defaultEnd = defaultValue && defaultValue . range [ 1 ] ; return variable . references . some ( reference => { const start = reference . identifier . range [ 0 ] ; const end = reference . identifier . range [ 1 ] ; return ! reference . init && ( start < idStart || ( defaultValue !== null && start >= defaultStart && end <= defaultEnd ) || ( start >= initStart && end <= initEnd ) ) ; } ) ; } ; }
Creates the predicate function which checks whether a variable has their references in TDZ.

The predicate function would return `true`:

- if a reference is before the declarator. E.g. (var a = b, b = 1;)(var {a = b, b} = {};)
- if a reference is in the expression of their default value.  E.g. (var {a = a} = {};)
- if a reference is in the expression of their initializer.  E.g. (var a = a;)

@param {ASTNode} node - The initializer node of VariableDeclarator.
@returns {Function} The predicate function.
@private
Creates the predicate function which checks whether a variable has their references in TDZ .