Skip to content

Commit

Permalink
Fix false positive rewriteRelativeImportExtensions error on non-TS ex…
Browse files Browse the repository at this point in the history
…tensions (#60415)
  • Loading branch information
andrewbranch authored Nov 5, 2024
1 parent 131f673 commit 82a04b2
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 82a04b2

Please sign in to comment.