-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionVisitor.js
More file actions
46 lines (38 loc) · 1.05 KB
/
FunctionVisitor.js
File metadata and controls
46 lines (38 loc) · 1.05 KB
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
var FunctionVisitor = function FunctionVisitor(){
this.visitProgram = function visitProgram(AST){
console.log(AST);
this.program = AST;
}
this.visitFunctionDeclaration = function visitFunctionDeclaration(AST){
this.visitFunction(AST);
}
this.visitFunctionExpression = function visitFunctionExpression(AST){
this.visitFunction(AST);
}
this.visitFunction = function visitFunction(AST){
var context = this.getContext(2);
if(context.functions === undefined){
context.functions = [];
}
context.functions.push(AST);
}
this.getFunctionJSON = function getFunctionJSON(){
var aux = function aux(AST){
var obj = {};
obj.name = (AST.id === null || AST.id === undefined) ? 'anon' : AST.id.name ;
obj.size = AST.range[1] - AST.range[0];
obj.AST = AST;
if(AST.functions != undefined){
obj.children = [];
for(var k in AST.functions){
var fun = AST.functions[k];
var a = aux(fun);
obj.children.push(a);
}
}
return obj;
}
return aux(this.program);
}
}
FunctionVisitor.prototype = new ASTVisitor();