MCPcopy
hub / github.com/angular/angular-cli / create

Function create

packages/angular_devkit/core/src/workspace/json/utilities.ts:60–152  ·  view source on GitHub ↗
(
  obj: JsonObject | JsonArray,
  path: string[],
  reporter: ChangeReporter,
  excluded = new Set<ProxyPropertyKey>(),
  included?: Set<ProxyPropertyKey>,
)

Source from the content-addressed store, hash-verified

58}
59
60function create(
61 obj: JsonObject | JsonArray,
62 path: string[],
63 reporter: ChangeReporter,
64 excluded = new Set<ProxyPropertyKey>(),
65 included?: Set<ProxyPropertyKey>,
66) {
67 return new Proxy(obj, {
68 getOwnPropertyDescriptor(target: {}, p: ProxyPropertyKey): PropertyDescriptor | undefined {
69 if (excluded.has(p) || (included && !included.has(p))) {
70 return undefined;
71 }
72
73 return Reflect.getOwnPropertyDescriptor(target, p);
74 },
75 has(target: {}, p: ProxyPropertyKey): boolean {
76 if (typeof p === 'symbol' || excluded.has(p)) {
77 return false;
78 }
79
80 return Reflect.has(target, p);
81 },
82 get(target: {}, p: ProxyPropertyKey): unknown {
83 if (excluded.has(p) || (included && !included.has(p))) {
84 return undefined;
85 }
86
87 const value = Reflect.get(target, p);
88 if (typeof p === 'symbol') {
89 return value;
90 }
91
92 if ((isJsonObject(value) && !(value instanceof Map)) || Array.isArray(value)) {
93 return create(value, [...path, p], reporter);
94 } else {
95 return value;
96 }
97 },
98 set(target: {}, p: ProxyPropertyKey, value: unknown): boolean {
99 if (excluded.has(p) || (included && !included.has(p))) {
100 return false;
101 }
102
103 if (value === undefined) {
104 // setting to undefined is equivalent to a delete.
105 return this.deleteProperty?.(target, p) ?? false;
106 }
107
108 if (typeof p === 'symbol') {
109 return Reflect.set(target, p, value);
110 }
111
112 const existingValue = getCurrentValue(target, p);
113 if (Reflect.set(target, p, value)) {
114 reporter([...path, p], target, existingValue, value as JsonValue);
115
116 return true;
117 }

Callers 2

createVirtualAstObjectFunction · 0.85
getFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected