diff --git a/src/esmockLoader.mjs b/src/esmockLoader.mjs index c43a1d6b..c20698be 100644 --- a/src/esmockLoader.mjs +++ b/src/esmockLoader.mjs @@ -40,30 +40,6 @@ export async function resolve (specifier, context, defaultResolve) { return resolved; } -// supported by node version less than 16.12 -export async function getSource (url, context, defaultGetSource) { - if (/#esmockModuleKeys/gi.test(url)) // parent of mocked modules - return defaultGetSource(url, context, defaultGetSource); - - [ url ] = url.split('?esmockGlobals='); - if (url.startsWith(urlDummy)) { - url = url.replace(/[^#]*#/, ''); - } - - const exportedNames = /exportNames=/.test(url) && - url.replace(/.*exportNames=(.*)/, '$1').split(','); - if (exportedNames) { - return { - source : exportedNames.map(name => name === 'default' - ? `export default global.esmockCacheGet("${url}").default` - : `export const ${name} = global.esmockCacheGet("${url}").${name}` - ).join('\n') - }; - } - - return defaultGetSource(url, context, defaultGetSource); -} - export async function load (url, context, defaultGetSource) { if (/#esmockModuleKeys/gi.test(url)) // parent of mocked modules return defaultGetSource(url, context, defaultGetSource); @@ -88,4 +64,7 @@ export async function load (url, context, defaultGetSource) { return defaultGetSource(url, context, defaultGetSource); } - +// supported by node version less than 16.12 +export async function getSource (url, context, defaultGetSource) { + return load(url, context, defaultGetSource); +}