MCPcopy
hub / github.com/webpack/webpack / _create

Method _create

lib/stats/StatsFactory.js:273–417  ·  view source on GitHub ↗

* Returns created object. * @private * @template FactoryData * @template FallbackCreatedObject * @param {string} type type * @param {FactoryData} data factory data * @param {Omit<StatsFactoryContext, "type">} baseContext context used as base * @returns {CreatedObject<FactoryData, Fallb

(type, data, baseContext)

Source from the content-addressed store, hash-verified

271 * @returns {CreatedObject<FactoryData, FallbackCreatedObject>} created object
272 */
273 _create(type, data, baseContext) {
274 const context = /** @type {StatsFactoryContext} */ ({
275 ...baseContext,
276 type,
277 [type]: data
278 });
279 if (Array.isArray(data)) {
280 // run filter on unsorted items
281 const items = this._forEachLevelFilter(
282 this.hooks.filter,
283 this._caches.filter,
284 type,
285 data,
286 (h, r, idx, i) => h.call(r, context, idx, i),
287 true
288 );
289
290 // sort items
291 /** @type {Comparator[]} */
292 const comparators = [];
293 this._forEachLevel(this.hooks.sort, this._caches.sort, type, (h) =>
294 h.call(comparators, context)
295 );
296 if (comparators.length > 0) {
297 items.sort(
298 // @ts-expect-error number of arguments is correct
299 concatComparators(...comparators, keepOriginalOrder(items))
300 );
301 }
302
303 // run filter on sorted items
304 const items2 = this._forEachLevelFilter(
305 this.hooks.filterSorted,
306 this._caches.filterSorted,
307 type,
308 items,
309 (h, r, idx, i) => h.call(r, context, idx, i),
310 false
311 );
312
313 // for each item
314 let resultItems = items2.map((item, i) => {
315 /** @type {StatsFactoryContext} */
316 const itemContext = {
317 ...context,
318 _index: i
319 };
320
321 // run getItemName
322 const itemName = this._forEachLevel(
323 this.hooks.getItemName,
324 this._caches.getItemName,
325 `${type}[]`,
326 (h) => h.call(item, itemContext)
327 );
328 if (itemName) itemContext[itemName] = item;
329 const innerType = itemName ? `${type}[].${itemName}` : `${type}[]`;
330

Callers 1

createMethod · 0.95

Calls 10

_forEachLevelFilterMethod · 0.95
_forEachLevelMethod · 0.95
concatComparatorsFunction · 0.85
keepOriginalOrderFunction · 0.85
smartGroupingFunction · 0.85
isArrayMethod · 0.80
sortMethod · 0.80
callMethod · 0.45
createMethod · 0.45

Tested by

no test coverage detected