Skip to content
Closed
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
5 changes: 5 additions & 0 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
let projectReferenceRedirects: Map<Path, ResolvedProjectReference | false> | undefined;
let mapFromFileToProjectReferenceRedirects: Map<Path, Path> | undefined;
let mapFromToProjectReferenceRedirectSource: Map<Path, SourceOfProjectReferenceRedirect> | undefined;
let hasResolvedReferencencesInNodeModules = false;
Copy link

Copilot AI May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo in the variable name hasResolvedReferencencesInNodeModules. Consider renaming it to hasResolvedReferencesInNodeModules for clarity and consistency.

Suggested change
let hasResolvedReferencencesInNodeModules = false;
let hasResolvedReferencesInNodeModules = false;

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This flag controls when to start resolving .d.ts sources from node_modules. Adding a brief comment above its declaration would improve maintainability and help future readers understand its purpose.

Suggested change
let hasResolvedReferencencesInNodeModules = false;
// Tracks whether `.d.ts` sources from `node_modules` have been resolved.
let hasResolvedReferencencesInNodeModules = false;

Copilot uses AI. Check for mistakes.

const useSourceOfProjectReferenceRedirect = !!host.useSourceOfProjectReferenceRedirect?.() &&
!options.disableSourceOfProjectReferenceRedirect;
Expand Down Expand Up @@ -3823,6 +3824,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro

function getSourceOfProjectReferenceRedirect(path: Path) {
if (!isDeclarationFileName(path)) return undefined;
if (!hasResolvedReferencencesInNodeModules && pathContainsNodeModules(path)) return undefined;
if (mapFromToProjectReferenceRedirectSource === undefined) {
Comment on lines 3825 to 3828
Copy link

Copilot AI May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The pathContainsNodeModules check appears in multiple places. Extracting it into a well-named helper (e.g., isInNodeModules(path)) could reduce duplication and improve readability.

Suggested change
function getSourceOfProjectReferenceRedirect(path: Path) {
if (!isDeclarationFileName(path)) return undefined;
if (!hasResolvedReferencencesInNodeModules && pathContainsNodeModules(path)) return undefined;
if (mapFromToProjectReferenceRedirectSource === undefined) {
function isInNodeModules(path: Path): boolean {
return pathContainsNodeModules(path);
}
function getSourceOfProjectReferenceRedirect(path: Path) {
if (!isDeclarationFileName(path)) return undefined;
if (!hasResolvedReferencencesInNodeModules && isInNodeModules(path)) return undefined;
if (mapFromToProjectReferenceRedirectSource === undefined) {

Copilot uses AI. Check for mistakes.
mapFromToProjectReferenceRedirectSource = new Map();
forEachResolvedProjectReference(resolvedRef => {
Expand Down Expand Up @@ -4140,6 +4142,9 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
sourceFile.path = sourceFilePath;
sourceFile.resolvedPath = sourceFilePath;
sourceFile.originalFileName = refPath;
if (!hasResolvedReferencencesInNodeModules && (pathContainsNodeModules(sourceFile.resolvedPath) || pathContainsNodeModules(sourceFile.path))) {
hasResolvedReferencencesInNodeModules = true;
}

const resolvedRef: ResolvedProjectReference = { commandLine, sourceFile };
projectReferenceRedirects.set(sourceFilePath, resolvedRef);
Expand Down