Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4733,7 +4733,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
error(errorNode, resolutionDiagnostic, moduleReference, resolvedModule.resolvedFileName);
}

if (resolvedModule.resolvedUsingTsExtension && isDeclarationFileName(moduleReference)) {
if (errorNode && resolvedModule.resolvedUsingTsExtension && isDeclarationFileName(moduleReference)) {
const importOrExport = findAncestor(location, isImportDeclaration)?.importClause ||
findAncestor(location, or(isImportEqualsDeclaration, isExportDeclaration));
if (errorNode && importOrExport && !importOrExport.isTypeOnly || findAncestor(location, isImportCall)) {
Expand All @@ -4744,16 +4744,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
);
}
}
else if (resolvedModule.resolvedUsingTsExtension && !shouldAllowImportingTsExtension(compilerOptions, currentSourceFile.fileName)) {
else if (errorNode && resolvedModule.resolvedUsingTsExtension && !shouldAllowImportingTsExtension(compilerOptions, currentSourceFile.fileName)) {
const importOrExport = findAncestor(location, isImportDeclaration)?.importClause ||
findAncestor(location, or(isImportEqualsDeclaration, isExportDeclaration));
if (errorNode && !(importOrExport?.isTypeOnly || findAncestor(location, isImportTypeNode))) {
const tsExtension = Debug.checkDefined(tryExtractTSExtension(moduleReference));
error(errorNode, Diagnostics.An_import_path_can_only_end_with_a_0_extension_when_allowImportingTsExtensions_is_enabled, tsExtension);
}
}
else if (
compilerOptions.rewriteRelativeImportExtensions
else if (
errorNode
&& compilerOptions.rewriteRelativeImportExtensions
&& !(location.flags & NodeFlags.Ambient)
&& !isDeclarationFileName(moduleReference)
&& !isLiteralImportTypeNode(location)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// === Syntax and Semantic Diagnostics ===
Syntactic Diagnostics for file '/tests/cases/fourslash/server/rewriteRelativeImportExtensionsProjectReferences4.ts':


==== /tests/cases/fourslash/server/src/libs/utils/helper.ts (0 errors) ====
export function helper() { return 42; }
==== /tests/cases/fourslash/server/src/apps/main/index.ts (0 errors) ====
import { helper } from "../../libs/utils/helper.ts";

Semantic Diagnostics for file '/tests/cases/fourslash/server/rewriteRelativeImportExtensionsProjectReferences4.ts':
/tests/cases/fourslash/server/src/apps/main/index.ts(1,24): error TS2878: This import path is unsafe to rewrite because it resolves to another project, and the relative path between the projects' output files is not the same as the relative path between its input files.


==== /tests/cases/fourslash/server/src/libs/utils/helper.ts (0 errors) ====
export function helper() { return 42; }
==== /tests/cases/fourslash/server/src/apps/main/index.ts (1 errors) ====
import { helper } from "../../libs/utils/helper.ts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2878: This import path is unsafe to rewrite because it resolves to another project, and the relative path between the projects' output files is not the same as the relative path between its input files.
Loading
Loading