Skip to content

Commit

Permalink
🤖 Pick PR #60415 (Fix false positive rewriteRelativeI...) into releas…
Browse files Browse the repository at this point in the history
…e-5.7 (#60424)

Co-authored-by: Andrew Branch <[email protected]>
  • Loading branch information
typescript-bot and andrewbranch authored Nov 5, 2024
1 parent 44bd3f2 commit 3ee2b95
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
14 changes: 14 additions & 0 deletions tests/baselines/reference/nonTSExtensions.js
Original file line number Diff line number Diff line change
@@ -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 {};
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3ee2b95

Please sign in to comment.