代码拉取完成,页面将自动刷新
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
};
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。