From 72d08965f9f1dd348b6017520ad63bc8373edc72 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 4 Jun 2024 13:52:18 +0900 Subject: [PATCH] perf(esm): only try extensions if file path --- src/esm/hook/resolve.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/esm/hook/resolve.ts b/src/esm/hook/resolve.ts index f2f7a8cef..167390d76 100644 --- a/src/esm/hook/resolve.ts +++ b/src/esm/hook/resolve.ts @@ -121,7 +121,8 @@ export const resolve: resolve = async ( } const parentNamespace = context.parentURL && getNamespace(context.parentURL); - if (requestAcceptsQuery(specifier)) { + const acceptsQuery = requestAcceptsQuery(specifier); + if (acceptsQuery) { // Inherit namespace from parent let requestNamespace = getNamespace(specifier); if (parentNamespace && !requestNamespace) { @@ -159,8 +160,11 @@ export const resolve: resolve = async ( // If `allowJs` is set in `tsconfig.json`, then we'll apply the same resolution logic // to files without a TypeScript extension. if ( - tsExtensionsPattern.test(context.parentURL!) - || allowJs + acceptsQuery // file path + && ( + tsExtensionsPattern.test(context.parentURL!) + || allowJs + ) ) { const tsPaths = resolveTsPath(specifier); if (tsPaths) {