@@ -6,6 +6,7 @@ import buildDebug from "debug";
66import path from "path" ;
77import type { Handler } from "gensync" ;
88import loadCjsOrMjsDefault from "./module-types" ;
9+ import { isAsync } from "../../gensync-utils/async" ;
910
1011import { createRequire } from "module" ;
1112const require = createRequire ( import . meta. url ) ;
@@ -149,18 +150,25 @@ function resolveStandardizedName(
149150 }
150151}
151152
152- const LOADING_MODULES = new Set ( ) ;
153+ if ( ! process . env . BABEL_8_BREAKING ) {
154+ // eslint-disable-next-line no-var
155+ var LOADING_MODULES = new Set ( ) ;
156+ }
153157function * requireModule ( type : string , name : string ) : Handler < unknown > {
154- if ( LOADING_MODULES . has ( name ) ) {
155- throw new Error (
156- `Reentrant ${ type } detected trying to load "${ name } ". This module is not ignored ` +
157- "and is trying to load itself while compiling itself, leading to a dependency cycle. " +
158- 'We recommend adding it to your "ignore" list in your babelrc, or to a .babelignore.' ,
159- ) ;
158+ if ( ! process . env . BABEL_8_BREAKING ) {
159+ if ( ! ( yield * isAsync ( ) ) && LOADING_MODULES . has ( name ) ) {
160+ throw new Error (
161+ `Reentrant ${ type } detected trying to load "${ name } ". This module is not ignored ` +
162+ "and is trying to load itself while compiling itself, leading to a dependency cycle. " +
163+ 'We recommend adding it to your "ignore" list in your babelrc, or to a .babelignore.' ,
164+ ) ;
165+ }
160166 }
161167
162168 try {
163- LOADING_MODULES . add ( name ) ;
169+ if ( ! process . env . BABEL_8_BREAKING ) {
170+ LOADING_MODULES . add ( name ) ;
171+ }
164172 return yield * loadCjsOrMjsDefault (
165173 name ,
166174 `You appear to be using a native ECMAScript module ${ type } , ` +
@@ -175,6 +183,8 @@ function* requireModule(type: string, name: string): Handler<unknown> {
175183 err . message = `[BABEL]: ${ err . message } (While processing: ${ name } )` ;
176184 throw err ;
177185 } finally {
178- LOADING_MODULES . delete ( name ) ;
186+ if ( ! process . env . BABEL_8_BREAKING ) {
187+ LOADING_MODULES . delete ( name ) ;
188+ }
179189 }
180190}
0 commit comments