Repository: eslint/eslint
File: lib/linter/code-path-analysis/code-path-state.js (JavaScript)

Code before:
     * @throws {Error} (Unreachable.)
     * @returns {void}
     */
    makeLogicalRight() {
        const currentChoiceContext = this.choiceContext;
        const forkContext = this.forkContext;

        if (currentChoiceContext.processed) {

            /*
             * This context was already assigned segments from a child
             * choice context. In this case, we are concerned only about
             * the path that does not short-circuit and so ends up on the
             * right-hand operand of the logical expression.
             */
            let prevForkContext;

            switch (currentChoiceContext.kind) {
                case "&&": // if true then go to the right-hand side.
                    prevForkContext = currentChoiceContext.trueForkContext;
                    break;
                case "||": // if false then go to the right-hand side.
                    prevForkContext = currentChoiceContext.falseForkContext;
                    break;
                case "??": // Both true/false can short-circuit, so needs the third path to go to the right-hand side. That's qqForkContext.
                    prevForkContext = currentChoiceContext.nullishForkContext; // s1_1->s1_4
                    break;
                default:
                    throw new Error("unreachable");
            }

            /*
             * Create the segment for the right-hand operand of the logical expression
             * and adjust the fork context pointer to point there. The right-hand segment
             * is added at the end of all segments in `prevForkContext`.
             */
            forkContext.replaceHead(prevForkContext.makeNext(0, -1));

            /*
             * We no longer need this list of segments.
             *
             * Reset `processed` because we've removed the segments from the child
             * choice context. This allows `popChoiceContext()` to continue adding
             * segments later.
             */
            prevForkContext.clear();
            currentChoiceContext.processed = false;

        } else {

            /*

Review comment (bug):
```suggestion
                    prevForkContext = currentChoiceContext.nullishForkContext;
```

This was probably for debugging.

Code after:
     * @throws {Error} (Unreachable.)
     * @returns {void}
     */
    makeLogicalRight() {
        const currentChoiceContext = this.choiceContext;
        const forkContext = this.forkContext;

        if (currentChoiceContext.processed) {

            /*
             * This context was already assigned segments from a child
             * choice context. In this case, we are concerned only about
             * the path that does not short-circuit and so ends up on the
             * right-hand operand of the logical expression.
             */
            let prevForkContext;

            switch (currentChoiceContext.kind) {
                case "&&": // if true then go to the right-hand side.
                    prevForkContext = currentChoiceContext.trueForkContext;
                    break;
                case "||": // if false then go to the right-hand side.
                    prevForkContext = currentChoiceContext.falseForkContext;
                    break;
                case "??": // Both true/false can short-circuit, so needs the third path to go to the right-hand side. That's nullishForkContext.
                    prevForkContext = currentChoiceContext.nullishForkContext;
                    break;
                default:
                    throw new Error("unreachable");
            }

            /*
             * Create the segment for the right-hand operand of the logical expression
             * and adjust the fork context pointer to point there. The right-hand segment
             * is added at the end of all segments in `prevForkContext`.
             */
            forkContext.replaceHead(prevForkContext.makeNext(0, -1));

            /*
             * We no longer need this list of segments.
             *
             * Reset `processed` because we've removed the segments from the child
             * choice context. This allows `popChoiceContext()` to continue adding
             * segments later.
             */
            prevForkContext.clear();
            currentChoiceContext.processed = false;

        } else {

            /*