MCPcopy
hub / github.com/webpack/webpack / A

Function A

lib/config/defaults.js:268–295  ·  view source on GitHub ↗
(obj, prop, factory)

Source from the content-addressed store, hash-verified

266 * @returns {void}
267 */
268const A = (obj, prop, factory) => {
269 const value = obj[prop];
270 if (value === undefined) {
271 obj[prop] = factory();
272 } else if (Array.isArray(value)) {
273 /** @type {EXPECTED_ANY[] | undefined} */
274 let newArray;
275 for (let i = 0; i < value.length; i++) {
276 const item = value[i];
277 if (item === "...") {
278 if (newArray === undefined) {
279 newArray = value.slice(0, i);
280 obj[prop] = /** @type {T[P]} */ (/** @type {unknown} */ (newArray));
281 }
282 const items =
283 /** @type {EXPECTED_ANY[]} */
284 (/** @type {unknown} */ (factory()));
285 if (items !== undefined) {
286 for (const item of items) {
287 newArray.push(item);
288 }
289 }
290 } else if (newArray !== undefined) {
291 newArray.push(item);
292 }
293 }
294 }
295};
296
297/**
298 * Apply webpack options base defaults.

Callers 4

applySnapshotDefaultsFunction · 0.70
applyModuleDefaultsFunction · 0.70
applyOutputDefaultsFunction · 0.70

Calls 3

isArrayMethod · 0.80
sliceMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected