MCPcopy
hub / github.com/webpack/webpack / popNodes

Method popNodes

lib/util/deterministicGrouping.js:248–278  ·  view source on GitHub ↗

* Returns removed nodes. * @param {(node: Node<T>) => boolean} filter filter function * @returns {Node<T>[] | undefined} removed nodes

(filter)

Source from the content-addressed store, hash-verified

246 * @returns {Node<T>[] | undefined} removed nodes
247 */
248 popNodes(filter) {
249 /** @type {Node<T>[]} */
250 const newNodes = [];
251 /** @type {Similarities} */
252 const newSimilarities = [];
253 /** @type {Node<T>[]} */
254 const resultNodes = [];
255 /** @type {undefined | Node<T>} */
256 let lastNode;
257 for (let i = 0; i < this.nodes.length; i++) {
258 const node = this.nodes[i];
259 if (filter(node)) {
260 resultNodes.push(node);
261 } else {
262 if (newNodes.length > 0) {
263 newSimilarities.push(
264 lastNode === this.nodes[i - 1]
265 ? /** @type {Similarities} */ (this.similarities)[i - 1]
266 : similarity(/** @type {Node<T>} */ (lastNode).key, node.key)
267 );
268 }
269 newNodes.push(node);
270 lastNode = node;
271 }
272 }
273 if (resultNodes.length === this.nodes.length) return;
274 this.nodes = newNodes;
275 this.similarities = newSimilarities;
276 this.size = sumSize(newNodes);
277 return resultNodes;
278 }
279}
280
281/**

Callers 1

removeProblematicNodesFunction · 0.80

Calls 4

similarityFunction · 0.85
sumSizeFunction · 0.85
filterFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected