refactor(schema): share changed schema fact recording (#17401)

This commit is contained in:
Vincent Koc
2026-12-06 13:44:17 +08:00
committed by GitHub
parent 9312efa658
commit 6ced6970fc
+10 -17
View File
@@ -136,6 +136,11 @@ const normalizationContext = (root: Readonly<Record<string, unknown>>) => {
fact: Fact;
}[] = [];
const changed: Fact[] = [];
const markChanged = (fact: Fact): void => {
if (fact.changed) return;
fact.changed = true;
changed.push(fact);
};
const untracked: Fact[] = [];
const factAt = (
schema: unknown,
@@ -174,10 +179,8 @@ const normalizationContext = (root: Readonly<Record<string, unknown>>) => {
!ignoresSiblings &&
(opaquePatternChanged ||
(sites.get(scope)?.has(schema) && hasWidenedPattern(schema)))
) {
fact.changed = true;
changed.push(fact);
}
)
markChanged(fact);
if (typeof schema.$ref === "string") {
const target = references.resolve(scope, schema.$ref);
if (
@@ -203,10 +206,7 @@ const normalizationContext = (root: Readonly<Record<string, unknown>>) => {
// moved target cannot make a negation stricter or leave a dangling
// reference.
fact.opaqueReference = fact;
if (!fact.changed) {
fact.changed = true;
changed.push(fact);
}
markChanged(fact);
} else untracked.push(fact);
}
if (
@@ -247,17 +247,10 @@ const normalizationContext = (root: Readonly<Record<string, unknown>>) => {
if (changed.length > 0)
for (const fact of untracked) {
fact.opaqueReference = fact;
if (!fact.changed) {
fact.changed = true;
changed.push(fact);
}
markChanged(fact);
}
for (let index = 0; index < changed.length; index++)
for (const dependent of changed[index]!.dependents)
if (!dependent.changed) {
dependent.changed = true;
changed.push(dependent);
}
for (const dependent of changed[index]!.dependents) markChanged(dependent);
const lost: Fact[] = [];
for (const { schema, scope, fact } of work)
if (