48 lines
1.7 KiB
Text
48 lines
1.7 KiB
Text
|
// default
|
||
|
function* loadCodeDefault(filepath, loader, esmError, tlaError) {
|
||
|
let async;
|
||
|
const ext = _path().extname(filepath);
|
||
|
const isTS = ext === ".ts" || ext === ".cts" || ext === ".mts";
|
||
|
const type = SUPPORTED_EXTENSIONS[hasOwnProperty.call(SUPPORTED_EXTENSIONS, ext) ? ext : ".js"];
|
||
|
const pattern = `${loader} ${type}`;
|
||
|
switch (pattern) {
|
||
|
case "require cjs":
|
||
|
case "auto cjs":
|
||
|
if (isTS) {
|
||
|
return ensureTsSupport(filepath, ext, () => loadCjsDefault(filepath));
|
||
|
} else {
|
||
|
return loadCjsDefault(filepath, arguments[2]);
|
||
|
}
|
||
|
case "auto unknown":
|
||
|
case "require unknown":
|
||
|
case "require esm":
|
||
|
try {
|
||
|
if (isTS) {
|
||
|
return ensureTsSupport(filepath, ext, () => loadCjsDefault(filepath));
|
||
|
} else {
|
||
|
return loadCjsDefault(filepath, arguments[2]);
|
||
|
}
|
||
|
} catch (e) {
|
||
|
if (e.code === "ERR_REQUIRE_ASYNC_MODULE" || e.code === "ERR_REQUIRE_CYCLE_MODULE" && asyncModules.has(filepath)) {
|
||
|
asyncModules.add(filepath);
|
||
|
if (!(async != null ? async : async = yield* (0, _async.isAsync)())) {
|
||
|
throw new _configError.default(tlaError, filepath);
|
||
|
}
|
||
|
} else if (e.code === "ERR_REQUIRE_ESM" || type === "esm") {} else {
|
||
|
throw e;
|
||
|
}
|
||
|
}
|
||
|
case "auto esm":
|
||
|
if (async != null ? async : async = yield* (0, _async.isAsync)()) {
|
||
|
const promise = isTS ? ensureTsSupport(filepath, ext, () => loadMjsFromPath(filepath)) : loadMjsFromPath(filepath);
|
||
|
return (yield* (0, _async.waitFor)(promise)).default;
|
||
|
}
|
||
|
throw new _configError.default(esmError, filepath);
|
||
|
default:
|
||
|
throw new Error("Internal Babel error: unreachable code.");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// supportsESM
|
||
|
true
|