From 62450d38a815233aad825588faa1afb5f7bf5adb Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 8 Jan 2022 19:46:56 -0800 Subject: [PATCH] tools: replace while+exec() with matchAll() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/41406 Reviewed-By: Tobias Nießen Reviewed-By: Michaël Zasso --- tools/doc/allhtml.mjs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/doc/allhtml.mjs b/tools/doc/allhtml.mjs index 13fda2c573f668..c597bebdbcf99a 100644 --- a/tools/doc/allhtml.mjs +++ b/tools/doc/allhtml.mjs @@ -103,12 +103,13 @@ fs.writeFileSync(new URL('./all.html', source), all, 'utf8'); // Validate all hrefs have a target. const ids = new Set(); const idRe = / id="([^"]+)"/g; -let match; -while (match = idRe.exec(all)) { +const idMatches = all.matchAll(idRe); +for (const match of idMatches) { ids.add(match[1]); } const hrefRe = / href="#([^"]+)"/g; -while (match = hrefRe.exec(all)) { +const hrefMatches = all.matchAll(hrefRe); +for (const match of hrefMatches) { if (!ids.has(match[1])) throw new Error(`link not found: ${match[1]}`); }