diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 75862dde0b9..d12ae297b81 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -4306,7 +4306,7 @@ export function tryGetImportFromModuleSpecifier(node: StringLiteralLike): AnyVal /** @internal */ export function shouldRewriteModuleSpecifier(specifier: string, compilerOptions: CompilerOptions): boolean { - return !!compilerOptions.rewriteRelativeImportExtensions && pathIsRelative(specifier) && !isDeclarationFileName(specifier); + return !!compilerOptions.rewriteRelativeImportExtensions && pathIsRelative(specifier) && !isDeclarationFileName(specifier) && hasTSFileExtension(specifier); } /** @internal */ diff --git a/tests/baselines/reference/nonTSExtensions.js b/tests/baselines/reference/nonTSExtensions.js new file mode 100644 index 00000000000..117d199aa7d --- /dev/null +++ b/tests/baselines/reference/nonTSExtensions.js @@ -0,0 +1,14 @@ +//// [tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/nonTSExtensions.ts] //// + +//// [example.json] +{} + +//// [styles.d.css.ts] +export {}; + +//// [index.mts] +import {} from "./example.json" with { type: "json" }; // Ok +import {} from "./styles.css"; // Ok + +//// [index.mjs] +export {}; diff --git a/tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/nonTSExtensions.ts b/tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/nonTSExtensions.ts new file mode 100644 index 00000000000..e7d6f2107d8 --- /dev/null +++ b/tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/nonTSExtensions.ts @@ -0,0 +1,15 @@ +// @module: nodenext +// @rewriteRelativeImportExtensions: true +// @allowArbitraryExtensions: true +// @resolveJsonModule: true +// @noTypesAndSymbols: true + +// @Filename: example.json +{} + +// @Filename: styles.d.css.ts +export {}; + +// @Filename: index.mts +import {} from "./example.json" with { type: "json" }; // Ok +import {} from "./styles.css"; // Ok \ No newline at end of file