laimFreeName("__jestHoist"); this.hoistedFunctionNames.push(hoistedFunctionName); this.tokens.replaceToken(`function ${hoistedFunctionName}(){${JEST_GLOBAL_NAME}.`); this.tokens.copyToken(); this.tokens.copyToken(); this.rootTransformer.processBalancedCode(); this.tokens.copyExpectedToken(_types.TokenType.parenR); this.tokens.appendCode(";}"); followsNonHoistedJestCall = false; } else { // This is a non-hoisted method, so just transform the code as usual. if (followsNonHoistedJestCall) { // If we didn't hoist the previous call, we can leave the code as-is to chain off of the // previous method call. It's important to preserve the code here because we don't know // for sure that the method actually returned the jest object for chaining. this.tokens.copyToken(); } else { // If we hoisted the previous call, we know it returns the jest object back, so we insert // the identifier `jest` to continue the chain. this.tokens.replaceToken(`${JEST_GLOBAL_NAME}.`); } this.tokens.copyToken(); this.tokens.copyToken(); this.rootTransformer.processBalancedCode(); this.tokens.copyExpectedToken(_types.TokenType.parenR); followsNonHoistedJestCall = true; } } return true; } } exports.default = JestHoistTransformer;