MCPcopy
hub / github.com/webpack/webpack / serializeObject

Function serializeObject

lib/util/cleverMerge.js:239–273  ·  view source on GitHub ↗
(info, dynamicInfo)

Source from the content-addressed store, hash-verified

237 * @returns {T} the object
238 */
239const serializeObject = (info, dynamicInfo) => {
240 const obj = /** @type {EXPECTED_ANY} */ ({});
241 // Setup byProperty structure
242 for (const entry of info.values()) {
243 if (entry.byProperty !== undefined) {
244 const byProperty = entry.byProperty;
245 const byObj = (obj[byProperty] = obj[byProperty] || {});
246 for (const byValue of /** @type {ByValues} */ (entry.byValues).keys()) {
247 byObj[byValue] = byObj[byValue] || {};
248 }
249 }
250 }
251 for (const [key, entry] of info) {
252 if (entry.base !== undefined) {
253 obj[key] = entry.base;
254 }
255 // Fill byProperty structure
256 if (entry.byProperty !== undefined) {
257 const byProperty = entry.byProperty;
258 const byObj = (obj[byProperty] = obj[byProperty] || {});
259 for (const byValue of Object.keys(byObj)) {
260 const value = getFromByValues(
261 /** @type {ByValues} */
262 (entry.byValues),
263 byValue
264 );
265 if (value !== undefined) byObj[byValue][key] = value;
266 }
267 }
268 }
269 if (dynamicInfo !== undefined) {
270 obj[dynamicInfo.byProperty] = dynamicInfo.fn;
271 }
272 return obj;
273};
274
275const VALUE_TYPE_UNDEFINED = 0;
276const VALUE_TYPE_ATOM = 1;

Callers 1

_cleverMergeFunction · 0.85

Calls 3

getFromByValuesFunction · 0.85
keysMethod · 0.65
valuesMethod · 0.45

Tested by

no test coverage detected