Skip to content

Commit b82c25e

Browse files
author
Andy Hanson
committed
For classic resolution, don't provide a codefix for a location inside node_modules
1 parent 192fabf commit b82c25e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/services/codefixes/importFixes.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,9 @@ namespace ts.codefix {
329329

330330
const relativePath = removeExtensionAndIndexPostFix(getRelativePath(moduleFileName, sourceDirectory, getCanonicalFileName), options);
331331
if (!baseUrl) {
332-
return [relativePath];
332+
// Don't use a relative path that would pass through node_modules -- should have handled that that in `tryGetModuleNameAsNodeModule`,
333+
// but would do nothing there if we're in classic resolution, so return no result in that case.
334+
return forEachAncestorDirectory(relativePath, p => getBaseFileName(p) === "node_modules" ? true : undefined) ? [] : [relativePath];
333335
}
334336

335337
const relativeToBaseUrl = getRelativePathIfInDirectory(moduleFileName, baseUrl, getCanonicalFileName);

tests/cases/fourslash/importNameCodeFixNewImportIndex_notForClassicResolution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ foo;`
2424
]);
2525

2626
goTo.file("/c.ts");
27-
// TODO: GH#20050 verify.not.codeFixAvailable();
27+
verify.not.codeFixAvailable();

0 commit comments

Comments
 (0)