tools: replace while+exec() with matchAll()

PR-URL: https://github.com/nodejs/node/pull/41406
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
Rich Trott
2022-01-08 19:46:56 -08:00
committed by GitHub
parent 1548578931
commit e247089057

View File

@@ -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]}`);
}