-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgadgets.infer-properties.js
37 lines (34 loc) · 1.32 KB
/
gadgets.infer-properties.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
let wrench = require("wrench");
const {Parser} = require("acorn")
let estraverse = require("estraverse");
let fs = require("fs");
const nodeSrcPath = "../benchmark-nodejs"
function analyzeProps(targetDir) {
let files = wrench.readdirSyncRecursive(targetDir);
let props = new Set();
files = files.filter((file) => file.match(/.*\.js$/));
console.log(`JS files: ${files.length}`)
for (let i = 0; i < files.length; i++) {
// console.log(`${i} ${props.size}`);
let file = files[i];
try {
let ast = Parser.parse(fs.readFileSync(`${targetDir}/${file}`).toString());
estraverse.traverse(ast, {
enter: function (node, parent) {
if (node.type == 'MemberExpression') {
if (node.property.type === "Identifier")
return props.add(node.property.name);
if (node.property.type === "Literal")
return props.add(node.property.value);
}
}
});
} catch(e) {
//console.log(e);
}
}
return Array.from(props);
}
const props = analyzeProps(nodeSrcPath)
console.log("Total properties: " + props.length)
fs.writeFileSync("../raw-data/nodejs-properties.json", JSON.stringify(props));