From ccdd772e51c189a288e1bbf21b95af2baab6f22d Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Mon, 4 Nov 2024 22:17:21 +0100 Subject: [PATCH] Merge 33366d1a276ba5ac1e597ba99a575bf0eb3f57ff into c09e2ab4ff1abb69d2b4a9b361dbbde43b0d5667 --- 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