Ai
1 Star 0 Fork 0

奋斗的狮子/code-analysis-demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
classPlugin.js 4.72 KB
一键复制 编辑 原始数据 按行查看 历史
前端iceman 提交于 2023-02-05 20:49 +08:00 . feat: add classPlugin,yml config
exports.classPlugin = function (analysisContext) {
const mapName = 'classMap';
// 在分析实例上下文挂载副作用
analysisContext[mapName] = {};
function isClassCheck (context, tsCompiler, node, depth, apiName, matchImportItem, filePath, projectName, httpRepo, line) {
try{
if(node.parent && tsCompiler.isNewExpression(node.parent)){ // 存在于New调用表达式中
if(node.parent.expression.pos == node.pos && node.parent.expression.end == node.end){ // 命中关键词检测
if (!context[mapName][apiName]) {
context[mapName][apiName] = {};
context[mapName][apiName].callNum = 1;
context[mapName][apiName].callOrigin = matchImportItem.origin;
context[mapName][apiName].callFiles = {};
context[mapName][apiName].callFiles[filePath] = {};
context[mapName][apiName].callFiles[filePath].projectName = projectName;
context[mapName][apiName].callFiles[filePath].httpRepo = httpRepo;
context[mapName][apiName].callFiles[filePath].lines = [];
context[mapName][apiName].callFiles[filePath].lines.push(line);
} else {
context[mapName][apiName].callNum++;
if (!Object.keys(context[mapName][apiName].callFiles).includes(filePath)) {
context[mapName][apiName].callFiles[filePath] = {};
context[mapName][apiName].callFiles[filePath].projectName = projectName;
context[mapName][apiName].callFiles[filePath].httpRepo = httpRepo;
context[mapName][apiName].callFiles[filePath].lines = [];
context[mapName][apiName].callFiles[filePath].lines.push(line);
}else{
context[mapName][apiName].callFiles[filePath].lines.push(line);
}
}
return true; // true: 命中规则, 终止执行后序插件
}
}else if(node.parent && tsCompiler.isExpressionWithTypeArguments(node.parent) && tsCompiler.isHeritageClause(node.parent.parent)){ // 被继承表达式中
if (!context[mapName][apiName]) {
context[mapName][apiName] = {};
context[mapName][apiName].callNum = 1;
context[mapName][apiName].callOrigin = matchImportItem.origin;
context[mapName][apiName].callFiles = {};
context[mapName][apiName].callFiles[filePath] = {};
context[mapName][apiName].callFiles[filePath].projectName = projectName;
context[mapName][apiName].callFiles[filePath].httpRepo = httpRepo;
context[mapName][apiName].callFiles[filePath].lines = [];
context[mapName][apiName].callFiles[filePath].lines.push(line);
} else {
context[mapName][apiName].callNum++;
if (!Object.keys(context[mapName][apiName].callFiles).includes(filePath)) {
context[mapName][apiName].callFiles[filePath] = {};
context[mapName][apiName].callFiles[filePath].projectName = projectName;
context[mapName][apiName].callFiles[filePath].httpRepo = httpRepo;
context[mapName][apiName].callFiles[filePath].lines = [];
context[mapName][apiName].callFiles[filePath].lines.push(line);
}else{
context[mapName][apiName].callFiles[filePath].lines.push(line);
}
}
return true; // true: 命中规则, 终止执行后序插件
}
return false; // false: 未命中检测逻辑, 继续执行后序插件
}catch(e){
// console.log(e);
const info = {
projectName: projectName,
matchImportItem: matchImportItem,
apiName: apiName,
httpRepo: httpRepo + filePath.split('&')[1] + '#L' + line,
file: filePath.split('&')[1],
line: line,
stack: e.stack
};
context.addDiagnosisInfo(info);
return false; // false: 插件执行报错, 继续执行后序插件
}
}
// 返回分析Node节点的函数
return {
mapName : mapName,
checkFun: isClassCheck,
afterHook: null
};
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hewangjs/code-analysis-demo.git
git@gitee.com:hewangjs/code-analysis-demo.git
hewangjs
code-analysis-demo
code-analysis-demo
main

搜索帮助