Skip to content

Commit

Permalink
tools: use Set instead of { [key]: true } object
Browse files Browse the repository at this point in the history
Refs: #41675

PR-URL: #41695
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Mestery <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
tniessen authored and ruyadorno committed Feb 7, 2022
1 parent 2a18859 commit 3190e36
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions tools/doc/alljson.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,14 @@ const results = {

// Identify files that should be skipped. As files are processed, they
// are added to this list to prevent dupes.
const seen = {
'all.json': true,
'index.json': true
};
const seen = new Set(['all.json', 'index.json']);

// Extract (and concatenate) the selected data from each document.
// Expand hrefs found in json to include source HTML file.
for (const link of toc.match(/<a.*?>/g)) {
const href = /href="(.*?)"/.exec(link)[1];
const json = href.replace('.html', '.json');
if (!jsonFiles.includes(json) || seen[json]) continue;
if (!jsonFiles.includes(json) || seen.has(json)) continue;
const data = JSON.parse(
fs.readFileSync(new URL(`./${json}`, source), 'utf8')
.replace(/<a href=\\"#/g, `<a href=\\"${href}#`)
Expand All @@ -49,7 +46,7 @@ for (const link of toc.match(/<a.*?>/g)) {
}

// Mark source as seen.
seen[json] = true;
seen.add(json);
}

// Write results.
Expand Down

0 comments on commit 3190e36

Please sign in to comment.