File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
packages/babel-plugin-jest-hoist/src Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -189,6 +189,36 @@ export default (): {visitor: Visitor} => {
189
189
path . node . _blockHoist = Infinity ;
190
190
}
191
191
} ,
192
+ VariableDeclaration ( path ) {
193
+ const declarations = path . get ( 'declarations' ) ;
194
+
195
+ if ( declarations . length === 1 ) {
196
+ const declarationInit = declarations [ 0 ] . get ( 'init' ) ;
197
+
198
+ if ( declarationInit . isCallExpression ( ) ) {
199
+ const callee = declarationInit . get ( 'callee' ) as NodePath ;
200
+ const callArguments = declarationInit . get ( 'arguments' ) as Array <
201
+ NodePath
202
+ > ;
203
+
204
+ if (
205
+ callee . isIdentifier ( ) &&
206
+ callee . node . name === 'require' &&
207
+ callArguments . length === 1
208
+ ) {
209
+ const [ argument ] = callArguments ;
210
+
211
+ if (
212
+ argument . isStringLiteral ( ) &&
213
+ argument . node . value === '@jest/globals'
214
+ ) {
215
+ // @ts -ignore: private, magical property
216
+ path . node . _blockHoist = Infinity ;
217
+ }
218
+ }
219
+ }
220
+ }
221
+ } ,
192
222
} ;
193
223
194
224
return { visitor} ;
You can’t perform that action at this time.
0 commit comments