This commit is contained in:
@@ -1,12 +1,36 @@
|
||||
// @ts-check
|
||||
import * as fs from "node:fs";
|
||||
const globalRegex = / (?:var|function) (\w+)/g;
|
||||
const symbolRegex = /(?:var|function) (\w+)/g;
|
||||
const globalSymbols = [];
|
||||
let buffer = '';
|
||||
for (const basename of fs.readdirSync("node_modules/@types/node/web-globals")) {
|
||||
buffer += fs.readFileSync("node_modules/@types/node/web-globals/" + basename, "utf8");
|
||||
|
||||
const fileQueue = []
|
||||
const dirQueue = ["node_modules/@types/node"]
|
||||
|
||||
while (dirQueue.length !== 0) {
|
||||
const dirname = dirQueue.pop()
|
||||
for (const basename of fs.readdirSync(dirname)) {
|
||||
const path = dirname + "/" + basename
|
||||
if (fs.statSync(path).isDirectory()) {
|
||||
dirQueue.push(path)
|
||||
} else {
|
||||
fileQueue.push(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const match of buffer.matchAll(globalRegex)) {
|
||||
|
||||
for (const path of fileQueue) {
|
||||
const filebuffer = fs.readFileSync(path, "utf8");
|
||||
const lines = filebuffer.split('\n')
|
||||
let startLine=0
|
||||
for (const line of lines) {
|
||||
if (line.trim().endsWith("global {")) {
|
||||
break
|
||||
}
|
||||
startLine++
|
||||
}
|
||||
buffer+=lines.slice(startLine).join('\n')
|
||||
}
|
||||
for (const match of buffer.matchAll(symbolRegex)) {
|
||||
globalSymbols.push(match[0].trim());
|
||||
}
|
||||
const declarationRegex = /(?:^\/\*\*[\s\S]+?\*\/\n)?^(interface|type|declare \w+) (\w+).+\n(?:(?: .+\n)*};?\n)?/gm;
|
||||
|
||||
Reference in New Issue
Block a user