Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Jan 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions tools/doc/allhtml.mjs
Expand Up @@ -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]);
}
Comment on lines 103 to 109
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional suggestion to get rid of a few statements:

const ids = new Set([...all.matchAll(idRe)].map((match) => match[1]));

Or even:

const ids =
  new Set([...all.matchAll(/ id="([^"]+)"/g)].map((match) => 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]}`);
}