-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
43 lines (34 loc) · 890 Bytes
/
index.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
var recast = require("recast");
var types = recast.types;
var through = require("through");
var esprima = require("esprima-fb");
var visitor = require("./visitor");
// Make sure that this esprima can parse async functions.
esprima.parse("async function test() {}");
function exports() {
var data = [];
return through(write, end);
function write(buf) {
data.push(buf);
}
function end() {
this.queue(compile(data.join("")).code);
this.queue(null);
}
}
function compile(source, options) {
options = options || {};
var ast = recast.parse(source, {
esprima: esprima,
sourceFileName: options.sourceFileName
});
return recast.print(transform(ast), {
sourceMapName: options.sourceMapName
});
}
function transform(ast) {
return recast.visit(ast, visitor);
}
module.exports = exports;
exports.compile = compile;
exports.transform = transform;