Ste*_*hlf 3 javascript parsing scope v8 node.js
var code = 'var n = a; x = y; status.show();\n// todo: \nconsole.log(xyz, "todo: // tests.", params);';
function parse (c) {
var myFunc = new Function("myFunc", c);
}
Run Code Online (Sandbox Code Playgroud)
我正在使用V8 NODEJS环境.那么也许有可能获得有关已声明变量及其现有函数范围的信息?
其实我需要的失踪变量名a,x,y,status,xyz和params.
有人能指出我正确的方向吗?
最好的祝福.
以下是使用UglifyJS的方法:
var UglifyJS = require("uglifyjs");
var parsed = UglifyJS.parse(code);
parsed.figure_out_scope();
parsed.globals.each(function(g) {console.log(g.name)});
Run Code Online (Sandbox Code Playgroud)
您可以通过运行尝试了这一点npm install uglifyjs,然后node在终端.复制并粘贴问题中的var code = (...);位,然后复制上面的代码; 这是我得到的结果:
> parsed.globals.each(function(g) {console.log(g.name)});
a
x
y
status
console
xyz
params
Run Code Online (Sandbox Code Playgroud)