Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@angular-devkit/core): improve handling of set schema values #20598

Merged
merged 1 commit into from
Apr 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 8 additions & 37 deletions packages/angular_devkit/core/src/json/schema/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ export class CoreSchemaRegistry implements SchemaRegistry {
CoreSchemaRegistry._set(
data,
pathFragments,
answers[path] as {},
answers[path],
null,
undefined,
true,
Expand All @@ -567,51 +567,22 @@ export class CoreSchemaRegistry implements SchemaRegistry {
}

private static _set(
// tslint:disable-next-line:no-any
// tslint:disable-next-line: no-any
data: any,
fragments: string[],
value: {},
// tslint:disable-next-line:no-any
parent: any | null = null,
value: unknown,
parent: Record<string, unknown> | null = null,
parentProperty?: string,
force?: boolean,
): void {
for (let i = 0; i < fragments.length; i++) {
const f = fragments[i];

if (f[0] == 'i') {
if (!Array.isArray(data)) {
return;
}

for (let j = 0; j < data.length; j++) {
CoreSchemaRegistry._set(data[j], fragments.slice(i + 1), value, data, '' + j);
}

return;
}

if (f.startsWith('key')) {
if (typeof data !== 'object') {
return;
}

for (const property in data) {
CoreSchemaRegistry._set(data[property], fragments.slice(i + 1), value, data, property);
}

return;
}


// We know we need an object because the fragment is a property key.
for (const fragment of fragments) {
if (!data && parent !== null && parentProperty) {
data = parent[parentProperty] = {};
}
parent = data;
parentProperty = f;

data = data[f];
parent = data;
parentProperty = fragment;
data = data[fragment];
}

if (parent && parentProperty && (force || parent[parentProperty] === undefined)) {
Expand Down