From 3ee2b95689943c720d47db01b4a1da2b6ab9d9ff Mon Sep 17 00:00:00 2001 From: TypeScript Bot <23042052+typescript-bot@users.noreply.github.com> Date: Tue, 5 Nov 2024 12:51:46 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Pick=20PR=20#60415=20(Fix=20fals?= =?UTF-8?q?e=20positive=20rewriteRelativeI...)=20into=20release-5.7=20(#60?= =?UTF-8?q?424)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Andrew Branch --- src/compiler/utilities.ts | 2 +- tests/baselines/reference/nonTSExtensions.js | 14 ++++++++++++++ .../nonTSExtensions.ts | 15 +++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/nonTSExtensions.js create mode 100644 tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/nonTSExtensions.ts diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 75862dde0b9db..d12ae297b81ad 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 0000000000000..117d199aa7df9 --- /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 0000000000000..e7d6f2107d8d9 --- /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