From ba79f263a1c3563ea2328576e69409e7dcdd7cc6 Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 11 May 2026 22:45:50 +0300 Subject: [PATCH] refactor(compiler-cli): replace forEach with for...of in entry_point Convert four `.forEach()` calls in `private_export_checker.ts` and `reference_graph.ts` to `for...of`, matching the iteration style used elsewhere in the compiler. The TODOs that forced these workarounds are obsolete. (cherry picked from commit e661f4d255d9b609d93b9302339efed37708bd91) --- .../entry_point/src/private_export_checker.ts | 16 +++++++--------- .../src/ngtsc/entry_point/src/reference_graph.ts | 15 +++++---------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/entry_point/src/private_export_checker.ts b/packages/compiler-cli/src/ngtsc/entry_point/src/private_export_checker.ts index f08b764c2d6..9ce925b7791 100644 --- a/packages/compiler-cli/src/ngtsc/entry_point/src/private_export_checker.ts +++ b/packages/compiler-cli/src/ngtsc/entry_point/src/private_export_checker.ts @@ -53,8 +53,7 @@ export function checkForPrivateExports( const exportedSymbols = checker.getExportsOfModule(moduleSymbol); // Loop through the exported symbols, de-alias if needed, and add them to `topLevelExports`. - // TODO(alxhub): use proper iteration when build.sh is removed. (#27762) - exportedSymbols.forEach((symbol) => { + for (let symbol of exportedSymbols) { if (symbol.flags & ts.SymbolFlags.Alias) { symbol = checker.getAliasedSymbol(symbol); } @@ -62,7 +61,7 @@ export function checkForPrivateExports( if (decl !== undefined) { topLevelExports.add(decl); } - }); + } // Next, go through each exported class and expand it to the set of classes it makes Visible, // using the `ReferenceGraph`. For each Visible class, verify that it's also Exported, and queue @@ -70,13 +69,12 @@ export function checkForPrivateExports( const checkedSet = new Set(); // Loop through each Exported class. - // TODO(alxhub): use proper iteration when the legacy build is removed. (#27762) - topLevelExports.forEach((mainExport) => { + for (const mainExport of topLevelExports) { // Loop through each class made Visible by the Exported class. - refGraph.transitiveReferencesOf(mainExport).forEach((transitiveReference) => { + for (const transitiveReference of refGraph.transitiveReferencesOf(mainExport)) { // Skip classes which have already been checked. if (checkedSet.has(transitiveReference)) { - return; + continue; } checkedSet.add(transitiveReference); @@ -106,8 +104,8 @@ export function checkForPrivateExports( diagnostics.push(diagnostic); } - }); - }); + } + } return diagnostics; } diff --git a/packages/compiler-cli/src/ngtsc/entry_point/src/reference_graph.ts b/packages/compiler-cli/src/ngtsc/entry_point/src/reference_graph.ts index aad3cf51c1c..129939ebd18 100644 --- a/packages/compiler-cli/src/ngtsc/entry_point/src/reference_graph.ts +++ b/packages/compiler-cli/src/ngtsc/entry_point/src/reference_graph.ts @@ -45,20 +45,16 @@ export class ReferenceGraph { return null; } else { // Look through the outgoing edges of `source`. - // TODO(alxhub): use proper iteration when the legacy build is removed. (#27762) let candidatePath: T[] | null = null; - this.references.get(source)!.forEach((edge) => { - // Early exit if a path has already been found. - if (candidatePath !== null) { - return; - } + for (const edge of this.references.get(source)!) { // Look for a path from this outgoing edge to `target`. const partialPath = this.collectPathFrom(edge, target, seen); if (partialPath !== null) { // A path exists from `edge` to `target`. Insert `source` at the beginning. candidatePath = [source, ...partialPath]; + break; } - }); + } return candidatePath; } @@ -66,13 +62,12 @@ export class ReferenceGraph { private collectTransitiveReferences(set: Set, decl: T): void { if (this.references.has(decl)) { - // TODO(alxhub): use proper iteration when the legacy build is removed. (#27762) - this.references.get(decl)!.forEach((ref) => { + for (const ref of this.references.get(decl)!) { if (!set.has(ref)) { set.add(ref); this.collectTransitiveReferences(set, ref); } - }); + } } } }