UNPKG

1.52 kBTypeScriptView Raw
1import type CJSImportProcessor from "../CJSImportProcessor";
2import type NameManager from "../NameManager";
3import type TokenProcessor from "../TokenProcessor";
4import type RootTransformer from "./RootTransformer";
5import Transformer from "./Transformer";
6/**
7 * Implementation of babel-plugin-jest-hoist, which hoists up some jest method
8 * calls above the imports to allow them to override other imports.
9 *
10 * To preserve line numbers, rather than directly moving the jest.mock code, we
11 * wrap each invocation in a function statement and then call the function from
12 * the top of the file.
13 */
14export default class JestHoistTransformer extends Transformer {
15 readonly rootTransformer: RootTransformer;
16 readonly tokens: TokenProcessor;
17 readonly nameManager: NameManager;
18 readonly importProcessor: CJSImportProcessor | null;
19 private readonly hoistedFunctionNames;
20 constructor(rootTransformer: RootTransformer, tokens: TokenProcessor, nameManager: NameManager, importProcessor: CJSImportProcessor | null);
21 process(): boolean;
22 getHoistedCode(): string;
23 /**
24 * Extracts any methods calls on the jest-object that should be hoisted.
25 *
26 * According to the jest docs, https://jestjs.io/docs/en/jest-object#jestmockmodulename-factory-options,
27 * mock, unmock, enableAutomock, disableAutomock, are the methods that should be hoisted.
28 *
29 * We do not apply the same checks of the arguments as babel-plugin-jest-hoist does.
30 */
31 private extractHoistedCalls;
32}