Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "dfatool", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "JavaScript Data Flow Analyze Tool", | ||
@@ -5,0 +5,0 @@ "main": "dfatool.js", |
@@ -1,2 +0,2 @@ | ||
**dfatool.js**([http://pissang.github.com/dfatool/](http://pissang.github.com/dfatool/)) is a data flow analyze tool for javascript code runs on node.js. | ||
**dfatool.js** is a data flow analyze tool for javascript code runs on node.js. | ||
@@ -21,3 +21,3 @@ The code analyze is based on [Parser API](https://developer.mozilla.org/en/SpiderMonkey/Parser_API) AST, which you can generated with [Esprima](esprima.org). And [Escodegen](https://github.com/Constellation/escodegen) is needed for the final output code regenerate. | ||
var globalScope = dfatool.globalScope | ||
var globalScope = dfatool.newGlobalScope(); | ||
dfatool.buildScope(ast, globalScope); | ||
@@ -57,2 +57,36 @@ | ||
var returnedVariable = value.execute(callExprAST, scope); | ||
var returnedVariable = value.execute(callExprAST, scope); | ||
### Example | ||
Here is a simple example to get code outline with dfatool | ||
// Parse AST with esprima, loc must be set true | ||
var ast = esprima.parse(code, { | ||
loc : true | ||
}); | ||
var globalScope = dfatool.newGlobalScope(); | ||
dfatool.buildScope(ast, globalScope); | ||
globalScope.initialize(); | ||
globalScope.derivation() | ||
var outline = {}; | ||
// Iterate all the defined variables and inference its value | ||
for(var name in globalScope._defines){ | ||
var variable = globalScope._defines[name]; | ||
var value = variable.inference(); | ||
if( value ){ | ||
outline[variable.name] = value.toJSON(); | ||
} | ||
} | ||
You can also run the test script under the tests folder | ||
### TODO | ||
There are still many works todo like repeatment statement support | ||
And sadly it seems doesn't work well on the minified code. Still can't find the problem. |
var global = {}; | ||
(function(g){ | ||
g.test = 10; | ||
g.test = 10; | ||
})(global) |
var mod = (function(){ | ||
var foo = 10; | ||
return { | ||
set : function(v){ | ||
foo = v; | ||
}, | ||
get : function(){ | ||
return foo; | ||
} | ||
} | ||
var foo = 10; | ||
return { | ||
set : function(v){ | ||
foo = v; | ||
}, | ||
get : function(){ | ||
return foo; | ||
} | ||
} | ||
})() | ||
@@ -12,0 +12,0 @@ |
var foo = { | ||
prop : "a" | ||
prop : "a" | ||
} | ||
var bar = { | ||
a : "text" | ||
a : "text" | ||
} | ||
var res = bar[foo.prop] |
function foo(arg){ | ||
if( arg == "first"){ | ||
return "first"; | ||
}else if(arg=="second"){ | ||
return "second"; | ||
}else{ | ||
return "third"; | ||
} | ||
if( arg == "first"){ | ||
return "first"; | ||
}else if(arg=="second"){ | ||
return "second"; | ||
}else{ | ||
return "third"; | ||
} | ||
} | ||
@@ -10,0 +10,0 @@ var first = foo("first"); |
var increase = function(param){ | ||
return param+1; | ||
return param+1; | ||
} | ||
var res = increase( increase( increase( increase(1) ) ) ); |
function getObject(){ | ||
return { | ||
a : { | ||
c : 2 | ||
} | ||
} | ||
return { | ||
a : { | ||
c : 2 | ||
} | ||
} | ||
} | ||
@@ -8,0 +8,0 @@ var c = getObject(); |
var Module = function(){ | ||
// private | ||
var privateProp = 10; | ||
var privateMethod = function(){ | ||
doSomething(); | ||
} | ||
// public | ||
var publicProp = 10; | ||
var publicMethod = function(){ | ||
doSomething(); | ||
} | ||
// private | ||
var privateProp = 10; | ||
var privateMethod = function(){ | ||
doSomething(); | ||
} | ||
// public | ||
var publicProp = 10; | ||
var publicMethod = function(){ | ||
doSomething(); | ||
} | ||
if( privateProp == 10){ | ||
publicProp = privateProp; | ||
} | ||
return { | ||
prop : publicProp, | ||
method : publicMethod | ||
} | ||
if( privateProp == 10){ | ||
publicProp = privateProp; | ||
} | ||
return { | ||
prop : publicProp, | ||
method : publicMethod | ||
} | ||
}; | ||
var module = Module(); |
function hyber(){ | ||
var foo = 1; | ||
var foo = 1; | ||
function outer(){ | ||
foo = 2; | ||
function inner(){ | ||
return foo; | ||
} | ||
return inner(); | ||
} | ||
return outer() | ||
function outer(){ | ||
foo = 2; | ||
function inner(){ | ||
return foo; | ||
} | ||
return inner(); | ||
} | ||
return outer() | ||
} | ||
var bar = hyber(); |
function clazz(opts){ | ||
this.name = opts.name; | ||
this.name = opts.name; | ||
this.type = "something"; | ||
this.type = "something"; | ||
} | ||
var res = new clazz({ | ||
name : 'first' | ||
name : 'first' | ||
}) |
function func(){ | ||
func(); | ||
func(); | ||
} | ||
func(); |
function foo(arg){ | ||
switch(arg){ | ||
case "first": | ||
return "first"; | ||
case "second": | ||
return "second"; | ||
case "third": | ||
return "third"; | ||
} | ||
switch(arg){ | ||
case "first": | ||
return "first"; | ||
case "second": | ||
return "second"; | ||
case "third": | ||
return "third"; | ||
} | ||
} | ||
@@ -11,0 +11,0 @@ var first = foo("first"); |
@@ -19,3 +19,3 @@ var esprima = require('esprima'); | ||
}); | ||
var globalScope = dfatool.globalScope | ||
var globalScope = dfatool.newGlobalScope(); | ||
dfatool.buildScope(ast, globalScope); | ||
@@ -22,0 +22,0 @@ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
95661
28
2754
91
3