forked from javert2/JaVerT2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstrumenter.js
55 lines (47 loc) · 1.18 KB
/
instrumenter.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const esprima = require("esprima-next");
const yargs = require("yargs");
const fs = require("fs");
const generate = require("escodegen").generate
const argv = yargs
.option("input", { alias: "i", description: "JS input file", type: "string" })
.option("output", {
alias: "o",
description: "ECMA-SL output file",
type: "string",
})
.demandOption("input")
.usage("Usage: $0 -i [filepath]")
.help()
.alias("help", "h").argv;
function ast2str (e) {
try {
const option = {
format : {
quotes : 'single',
indent : {
style : '\t'
}
}
};
return generate(e, option);
} catch (err) {
if ((typeof e) === "object") {
console.log("converting the following ast to str:\n" + e);
} else {
console.log("e is not an object!!!")
}
throw "ast2str failed.";
}
}
fs.readFile(argv.input, "utf-8", (err, data) => {
if (err) throw err;
const FUNC_NAME = argv.name ? argv.name : "buildAST";
let prog;
try {
progObj = esprima.parseScript(data);
console.log(progObj);
console.log(generate(progObj))
} catch (ex) {
console.log("error")
}
})