You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: babel-plugin-jest-hoist hoists entire braceless if statement above its condition #16538
The if (useMock) statement remains in place after const useMock = true (matching the braced form if (useMock) { jest.mock('./dep'); }), or only the jest.mock() call is hoisted while preserving valid control flow.
Actual behavior
babel-plugin-jest-hoist hoists the entire IfStatement to the top of the enclosing block above const useMock = true:
if(useMock)_getJestObj().mock('./dep');function_getJestObj(){const{
jest
}=require("@jest/globals");_getJestObj=()=>jest;returnjest;}constuseMock=true;
Running this in Jest throws ReferenceError: Cannot access 'useMock' before initialization (or evaluates useMock as undefined with var), whereas the braced form if (useMock) { jest.mock('./dep'); } leaves the if statement in place after const useMock = true.
Additional context
callExpr.getStatementParent() returns the nearest ancestor in a statement list, which for a braceless if consequent (or else, while, or for body) is the enclosing control-flow statement rather than the ExpressionStatement.
changed the title [-]babel-plugin-jest-hoist hoists entire braceless if statement above its condition[/-][+][Bug]: babel-plugin-jest-hoist hoists entire braceless if statement above its condition[/+]on Nov 7, 2026
Activity
[-]babel-plugin-jest-hoist hoists entire braceless if statement above its condition[/-][+][Bug]: babel-plugin-jest-hoist hoists entire braceless if statement above its condition[/+]