MCPcopy
hub / github.com/webpack/webpack / find

Function find

test/buildHtmlAst.unittest.js:52–66  ·  view source on GitHub ↗
(src, tagName)

Source from the content-addressed store, hash-verified

50 * @returns {import("../lib/html/syntax").HtmlElement} first matching element anywhere
51 */
52const find = (src, tagName) => {
53 /** @type {import("../lib/html/syntax").HtmlElement | undefined} */
54 let found;
55 /** @param {import("../lib/html/syntax").HtmlNode} node node to search */
56 const walk = (node) => {
57 if (found || node.type !== NodeType.Element) return;
58 if (node.tagName === tagName) {
59 found = node;
60 return;
61 }
62 for (const c of node.children) walk(c);
63 };
64 for (const c of buildHtmlAst(src).children) walk(c);
65 return /** @type {import("../lib/html/syntax").HtmlElement} */ (found);
66};
67
68describe("buildHtmlAst", () => {
69 it("should produce an empty document with html/head/body scaffolding", () => {

Callers 1

Calls 2

buildHtmlAstFunction · 0.85
walkFunction · 0.70

Tested by

no test coverage detected