MCPcopy
hub / github.com/webpack/webpack / _print

Method _print

lib/stats/StatsPrinter.js:218–311  ·  view source on GitHub ↗

* Returns printed result. * @private * @param {string} type type * @param {PrintObject} object object * @param {StatsPrinterContext=} baseContext context * @returns {string | undefined} printed result

(type, object, baseContext)

Source from the content-addressed store, hash-verified

216 * @returns {string | undefined} printed result
217 */
218 _print(type, object, baseContext) {
219 /** @type {StatsPrinterContext} */
220 const context = {
221 ...baseContext,
222 type,
223 [type]: object
224 };
225
226 /** @type {string | undefined} */
227 let printResult = this._forEachLevel(this.hooks.print, type, (hook) =>
228 hook.call(object, context)
229 );
230 if (printResult === undefined) {
231 if (Array.isArray(object)) {
232 const sortedItems = [...object];
233 this._forEachLevel(this.hooks.sortItems, type, (h) =>
234 h.call(
235 sortedItems,
236 /** @type {StatsPrinterContextWithExtra} */
237 (context)
238 )
239 );
240 const printedItems = sortedItems.map((item, i) => {
241 const itemContext =
242 /** @type {StatsPrinterContextWithExtra} */
243 ({
244 ...context,
245 _index: i
246 });
247 const itemName = this._forEachLevel(
248 this.hooks.getItemName,
249 `${type}[]`,
250 (h) => h.call(item, itemContext)
251 );
252 if (itemName) itemContext[itemName] = item;
253 return this.print(
254 itemName ? `${type}[].${itemName}` : `${type}[]`,
255 item,
256 itemContext
257 );
258 });
259 printResult = this._forEachLevel(this.hooks.printItems, type, (h) =>
260 h.call(
261 /** @type {string[]} */ (printedItems),
262 /** @type {StatsPrinterContextWithExtra} */
263 (context)
264 )
265 );
266 if (printResult === undefined) {
267 const result = printedItems.filter(Boolean);
268 if (result.length > 0) printResult = result.join("\n");
269 }
270 } else if (object !== null && typeof object === "object") {
271 const elements = Object.keys(object).filter(
272 (key) => object[key] !== undefined
273 );
274 this._forEachLevel(this.hooks.sortElements, type, (h) =>
275 h.call(

Callers 1

printMethod · 0.95

Calls 6

_forEachLevelMethod · 0.95
printMethod · 0.95
isArrayMethod · 0.80
keysMethod · 0.65
callMethod · 0.45

Tested by

no test coverage detected