插件功能
获取实参,计算出全局函数调用的结果,并用结果替换该全局函数的调用表达式。
处理实例
处理前:
var a = parseInt("12345",16),b = Number("123"),c = String(true),d = unescape("hello%2CAST%21");
eval("a = 1");
处理后:
var a = 74565,b = 123,c = "true",d = "hello,AST!";
eval("a = 1");
插件源码:
const types = require("@babel/types");
const evaluate_global_func =
{
"CallExpression"(path)
{
let {callee,arguments} = path.node;
if (!types.isIdentifier(callee) || callee.name == "eval") return;
if (!arguments.every(arg=>types.isLiteral(arg))) return;
let func = global[callee.name];
if (typeof func !== "function") return;
let args = [];
arguments.forEach(