1.espree使用
编写index.js代码 后,将在index.js目录下 npm -i espree
npm init -y生成pakage.json文件,node .\index.js 生成结果
index.js
const espree = require("espree");
const fs = require('fs');
ast = espree.parse(fs.readFileSync('D:/java/javascript/typescript@3.1.7.main.bundle.js'), {
loc: true,
range: true,
jsx: true,
// allowReserved: true,
allowReturnOutsideFunction: true,
onInsertedSemicolon: true,
allowImportExportEverywhere: true,
ecmaVersion: 2023,
sourceType: 'module',
ecmaFeatures: { impliedStrict: false, jsx: true, globalReturn: true }
})
console.log(ast);
2.修改 idea/bin目录下 idea.properties 修改idea.cycle.buffer.size=10240 console全部输出
3传函数体报错
3一个文件一个map,极端情况 100万 s函数->x0,
1个 s函数-》x0 其他t函数->x1
函数体内部的变量对应没问题
形参,函数体变量
3。20:0040行的修改 指纹值不变
全局定义的变量进行替换 a0 a1 (内置变量不修改,看成关键词)
console.log 项目上线 一般是会注释或删除
function f0(f0p0, f0p1) {
function f1(f1p0, f1p1) {
var f1x0 = ‘blah’;
f1p0 = 3;
f1x1 = 2;
var f1x2 = function f2() {
return 3;
}();
var f1x3 = f1p1;
return 5;
}
f0p0 = f0x0(1, 2);
}
var a0 = 1;
var a1 = 2;
-5490082951443034460
2229476176222531815
function f0(f0p0, f0p1) {
function f1(f1p0, f1p1) {
var f1x0 = ‘blah’;
f1p0 = 3;
f0p1 = 2;
var f1x2 = function f2() {
return 3;
}();
var f1x3 = f1p1;
return 5;
}
f0p0 = f1(1, 2);
}
var a0 = 1;
var a1 = 2;
-5634197040040816732
2231727976036741319
初始:
6295455724119913376
6556841691444057159
删除三百行、六百行:
一千行:
6295455724119913376
6556841691444057157
将10万+的f进行替换a
6871916498032391072
6525347254600904903
判断赋值语句的左node,若果节点名不在tempmap里(也就是不是当前函数的形参、函数体先定义的变量(先定义后操作)),temp加入一组键值对(都是当前名),等后面扫描identifier的时候就不会发生替换。