Skip to content

Commit 3ee2b95

Browse files
typescript-botandrewbranch
andauthoredNov 5, 2024··
🤖 Pick PR #60415 (Fix false positive rewriteRelativeI...) into release-5.7 (#60424)
Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>
1 parent 44bd3f2 commit 3ee2b95

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed
 

‎src/compiler/utilities.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4306,7 +4306,7 @@ export function tryGetImportFromModuleSpecifier(node: StringLiteralLike): AnyVal
43064306

43074307
/** @internal */
43084308
export function shouldRewriteModuleSpecifier(specifier: string, compilerOptions: CompilerOptions): boolean {
4309-
return !!compilerOptions.rewriteRelativeImportExtensions && pathIsRelative(specifier) && !isDeclarationFileName(specifier);
4309+
return !!compilerOptions.rewriteRelativeImportExtensions && pathIsRelative(specifier) && !isDeclarationFileName(specifier) && hasTSFileExtension(specifier);
43104310
}
43114311

43124312
/** @internal */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [tests/cases/conformance/externalModules/rewriteRelativeImportExtensions/nonTSExtensions.ts] ////
2+
3+
//// [example.json]
4+
{}
5+
6+
//// [styles.d.css.ts]
7+
export {};
8+
9+
//// [index.mts]
10+
import {} from "./example.json" with { type: "json" }; // Ok
11+
import {} from "./styles.css"; // Ok
12+
13+
//// [index.mjs]
14+
export {};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @module: nodenext
2+
// @rewriteRelativeImportExtensions: true
3+
// @allowArbitraryExtensions: true
4+
// @resolveJsonModule: true
5+
// @noTypesAndSymbols: true
6+
7+
// @Filename: example.json
8+
{}
9+
10+
// @Filename: styles.d.css.ts
11+
export {};
12+
13+
// @Filename: index.mts
14+
import {} from "./example.json" with { type: "json" }; // Ok
15+
import {} from "./styles.css"; // Ok

0 commit comments

Comments
 (0)
Please sign in to comment.