Skip to content

Commit 928169a

Browse files
committed
refactor(@angular/build): simplify Set operations with ES2025 Set methods (#34505)
PR Close #34505
1 parent 3832ab3 commit 928169a

3 files changed

Lines changed: 11 additions & 49 deletions

File tree

‎packages/angular/build/src/builders/library/builder-state.ts‎

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,8 @@ export class BuilderState {
256256
return true;
257257
}
258258

259-
for (const file of this.#pendingCompilationFiles) {
260-
if (this.#watchedCompilationFiles.has(file)) {
261-
return true;
262-
}
259+
if (!this.#pendingCompilationFiles.isDisjointFrom(this.#watchedCompilationFiles)) {
260+
return true;
263261
}
264262

265263
this.#pendingCompilationFiles.clear();
@@ -281,12 +279,7 @@ export class BuilderState {
281279
return undefined;
282280
}
283281

284-
const files = new Set(modifiedFiles);
285-
for (const file of this.#pendingCompilationFiles) {
286-
files.add(file);
287-
}
288-
289-
return files;
282+
return modifiedFiles.union(this.#pendingCompilationFiles);
290283
}
291284

292285
/**
@@ -380,7 +373,7 @@ export class BuilderState {
380373
collectedAssets: CollectedAssets,
381374
manifestFiles?: readonly OutputFile[],
382375
): ReadonlySet<string> {
383-
const filesToDelete = new Set<string>();
376+
let filesToDelete = new Set<string>();
384377

385378
if (this.#hasUpdatedBundles) {
386379
this.#hasUpdatedBundles = false;
@@ -394,21 +387,14 @@ export class BuilderState {
394387
}
395388
}
396389

397-
for (const prevFile of this.#emittedBundleFiles) {
398-
if (!nextBundleFiles.has(prevFile)) {
399-
filesToDelete.add(prevFile);
400-
}
401-
}
402-
390+
filesToDelete = this.#emittedBundleFiles.difference(nextBundleFiles);
403391
this.#emittedBundleFiles = nextBundleFiles;
404392
}
405393

406394
if (manifestFiles) {
407395
const nextManifestFiles = new Set(manifestFiles.map((file) => file.path));
408-
for (const prevFile of this.#emittedManifestFiles) {
409-
if (!nextManifestFiles.has(prevFile)) {
410-
filesToDelete.add(prevFile);
411-
}
396+
for (const prevFile of this.#emittedManifestFiles.difference(nextManifestFiles)) {
397+
filesToDelete.add(prevFile);
412398
}
413399

414400
this.#emittedManifestFiles = nextManifestFiles;

‎packages/angular/build/src/builders/library/pipeline/entry-points.ts‎

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,10 @@ export function collectEntryPointsToBundle(
308308
const previousBundleResult = previousBundleResults.get(entryPoint.name);
309309
const hasEsmChanges =
310310
!previousBundleResult ||
311-
hasEntryPointChanges(previousBundleResult.esmModuleIds, pendingChangedEsmFiles);
311+
!previousBundleResult.esmModuleIds.isDisjointFrom(pendingChangedEsmFiles);
312312
const hasDtsChanges =
313313
!previousBundleResult ||
314-
hasEntryPointChanges(previousBundleResult.dtsModuleIds, pendingChangedDtsFiles);
314+
!previousBundleResult.dtsModuleIds.isDisjointFrom(pendingChangedDtsFiles);
315315

316316
if (hasEsmChanges || hasDtsChanges) {
317317
executionResult.addLog(`Compiling ${entryPoint.displayName}...`);
@@ -326,27 +326,3 @@ export function collectEntryPointsToBundle(
326326

327327
return itemsToBundle;
328328
}
329-
330-
/**
331-
* Checks whether any file in `changedFiles` belongs to the given entry point's `moduleIds`.
332-
*
333-
* @param moduleIds Set of virtual POSIX module IDs referenced by the entry point's previous bundle.
334-
* @param changedFiles Set of POSIX file paths that changed during compilation.
335-
* @returns `true` if at least one changed file is part of `moduleIds`; otherwise `false`.
336-
*/
337-
function hasEntryPointChanges(
338-
moduleIds: ReadonlySet<string>,
339-
changedFiles: ReadonlySet<string>,
340-
): boolean {
341-
if (changedFiles.size === 0) {
342-
return false;
343-
}
344-
345-
for (const file of changedFiles) {
346-
if (moduleIds.has(file)) {
347-
return true;
348-
}
349-
}
350-
351-
return false;
352-
}

‎packages/angular/build/src/tools/sass/rebasing-importer.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ export class RelativeUrlRebasingImporter extends UrlRebasingImporter {
209209
// If there is a preprocessed cache of the directory, perform an intersection of the potentials
210210
// and the directory files.
211211
const { files, directories } = cachedEntries;
212-
foundDefaults = [...defaultPotentials].filter((potential) => files.has(potential));
213-
foundImports = [...importPotentials].filter((potential) => files.has(potential));
212+
foundDefaults = [...defaultPotentials.intersection(files)];
213+
foundImports = [...importPotentials.intersection(files)];
214214
hasPotentialIndex = checkDirectory && !hasStyleExtension && directories.has(filename);
215215
} else {
216216
// If no preprocessed cache exists, get the entries from the file system and, while searching,

0 commit comments

Comments
 (0)