diff --git a/src/utils/map-ts-extensions.ts b/src/utils/map-ts-extensions.ts index b83ce8acf..e074227c5 100644 --- a/src/utils/map-ts-extensions.ts +++ b/src/utils/map-ts-extensions.ts @@ -12,29 +12,26 @@ export const mapTsExtensions = ( filePath: string, handleMissingExtension?: boolean, ) => { - const [pathname, search] = filePath.split('?'); + const splitPath = filePath.split('?'); + let [pathname] = splitPath; const extension = path.extname(pathname); - const tryExtensions = ( - extension - ? tsExtensions[extension] - : (handleMissingExtension ? noExtension : undefined) - ); - if (!tryExtensions) { - return; - } + let tryExtensions = tsExtensions[extension]; + if (tryExtensions) { + pathname = pathname.slice(0, -extension.length); + } else { + if (!handleMissingExtension) { + return; + } - const extensionlessPath = ( - extension - ? pathname.slice(0, -extension.length) - : pathname - ); + tryExtensions = noExtension; + } return tryExtensions.map( tsExtension => ( - extensionlessPath + pathname + tsExtension - + (search ? `?${search}` : '') + + (splitPath[1] ? `?${splitPath[1]}` : '') ), ); }; diff --git a/tests/fixtures.ts b/tests/fixtures.ts index 5c749b322..80dda65b2 100644 --- a/tests/fixtures.ts +++ b/tests/fixtures.ts @@ -174,41 +174,45 @@ export const files = { 'value.mjs': 'export default 1', }, - 'ts/index.ts': sourcemap.tag` - import assert from 'assert'; - import type {Type} from 'resolved-by-tsc' + ts: { + 'index.ts': sourcemap.tag` + import assert from 'assert'; + import type {Type} from 'resolved-by-tsc' - interface Foo {} + interface Foo {} - type Foo = number + type Foo = number - declare module 'foo' {} + declare module 'foo' {} - enum BasicEnum { - Left, - Right, - } + enum BasicEnum { + Left, + Right, + } - enum NamedEnum { - SomeEnum = 'some-value', - } + enum NamedEnum { + SomeEnum = 'some-value', + } - export const a = BasicEnum.Left; + export const a = BasicEnum.Left; - export const b = NamedEnum.SomeEnum; + export const b = NamedEnum.SomeEnum; - export default function foo(): string { - return 'foo' - } + export default function foo(): string { + return 'foo' + } - // For "ts as tsx" test - const bar = (value: T) => fn(); + // For "ts as tsx" test + const bar = (value: T) => fn(); - ${preserveName} - ${sourcemap.test('ts')} - export const cjsContext = ${cjsContextCheck}; - ${tsCheck}; - `, + ${preserveName} + ${sourcemap.test('ts')} + export const cjsContext = ${cjsContextCheck}; + ${tsCheck}; + `, + + 'period.in.name.ts': 'export const periodInName = true as const', + }, // TODO: test resolution priority for files 'index.tsx` & 'index.tsx.ts` via 'index.tsx' diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index 35f0de252..d6a6ad3cd 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -268,6 +268,7 @@ export default testSuite(async ({ describe }, { tsx, supports, version }: NodeAp import './ts/index.jsx'; import './ts/index'; import './ts/'; + import './ts/period.in.name'; // .jsx import * as jsx from './jsx/index.jsx';