Skip to content

Commit

Permalink
Prevent duplicate analysis/infinite recursion (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Oct 6, 2023
1 parent a06925d commit 2d32eb1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ export const main = async (unresolvedConfiguration: CommandLineOptions) => {
const importedSymbols: Imports = new Map();

for (const principal of principals) {
const specifierFilePaths = new Set<string>();

const analyzeSourceFile = (filePath: string, _principal: ProjectPrincipal = principal) => {
const workspace = chief.findWorkspaceByFilePath(filePath);
if (workspace) {
Expand All @@ -274,8 +276,8 @@ export const main = async (unresolvedConfiguration: CommandLineOptions) => {
if (workspace) {
const principal = factory.getPrincipalByPackageName(workspace.pkgName);
if (principal && !principal.isGitIgnored(specifierFilePath)) {
analyzeSourceFile(specifierFilePath, principal);
analyzedFiles.add(specifierFilePath);
// Defer to outside loop to prevent potential duplicate analysis and/or infinite recursion
specifierFilePaths.add(specifierFilePath);
}
}
}
Expand Down Expand Up @@ -340,6 +342,13 @@ export const main = async (unresolvedConfiguration: CommandLineOptions) => {
analyzedFiles.add(filePath);
});
} while (size !== principal.entryPaths.size);

specifierFilePaths.forEach(specifierFilePath => {
if (!analyzedFiles.has(specifierFilePath)) {
analyzedFiles.add(specifierFilePath);
analyzeSourceFile(specifierFilePath, principal);
}
});
}

const isSymbolImported = (symbol: string, importingModule?: ImportedModule): boolean => {
Expand Down

0 comments on commit 2d32eb1

Please sign in to comment.