Skip to content

Commit 3832ab3

Browse files
committed
refactor(@angular-devkit/core): simplify Set operations with ES2025 Set methods (#34505)
PR Close #34505
1 parent 5416c9f commit 3832ab3

2 files changed

Lines changed: 6 additions & 24 deletions

File tree

‎packages/angular_devkit/core/src/json/schema/utility.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function getTypesOfSchema(schema: JsonSchema): Set<string> {
5353

5454
if (isJsonObject(schema.not)) {
5555
const notTypes = getTypesOfSchema(schema.not);
56-
potentials = new Set([...potentials].filter((p) => !notTypes.has(p)));
56+
potentials = potentials.difference(notTypes);
5757
}
5858

5959
if (Array.isArray(schema.allOf)) {
@@ -67,7 +67,7 @@ export function getTypesOfSchema(schema: JsonSchema): Set<string> {
6767
let options = new Set<string>();
6868
for (const sub of schema.oneOf) {
6969
const types = getTypesOfSchema(sub as JsonObject);
70-
options = new Set([...options, ...types]);
70+
options = options.union(types);
7171
}
7272
potentials = new Set([...options].filter((o) => potentials.has(o)));
7373
}
@@ -76,7 +76,7 @@ export function getTypesOfSchema(schema: JsonSchema): Set<string> {
7676
let options = new Set<string>();
7777
for (const sub of schema.anyOf) {
7878
const types = getTypesOfSchema(sub as JsonObject);
79-
options = new Set([...options, ...types]);
79+
options = options.union(types);
8080
}
8181
potentials = new Set([...options].filter((o) => potentials.has(o)));
8282
}

‎packages/angular_devkit/core/src/utils/partially-ordered-set.ts‎

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -84,34 +84,16 @@ export class PartiallyOrderedSet<T> {
8484
const itemDeps = this._items.get(item) || new Set<T>();
8585

8686
// If the dependency list is equal, just return, otherwise remove and keep going.
87-
let equal = true;
88-
for (const dep of deps) {
89-
if (!itemDeps.has(dep)) {
90-
equal = false;
91-
break;
92-
}
93-
}
94-
if (equal) {
95-
for (const dep of itemDeps) {
96-
if (!deps.has(dep)) {
97-
equal = false;
98-
break;
99-
}
100-
}
101-
}
102-
103-
if (equal) {
87+
if (deps.size === itemDeps.size && deps.isSubsetOf(itemDeps)) {
10488
return this;
10589
} else {
10690
this._items.delete(item);
10791
}
10892
}
10993

11094
// Verify all dependencies are part of the Set.
111-
for (const dep of deps) {
112-
if (!this._items.has(dep)) {
113-
throw new DependencyNotFoundException();
114-
}
95+
if (!deps.isSubsetOf(this._items)) {
96+
throw new DependencyNotFoundException();
11597
}
11698

11799
// Verify there's no dependency cycle.

0 commit comments

Comments
 (0)