arida/parse.js
想要成为RapStar吗? 04a6173d92 feat:Base Demo实现
2020-09-24 15:11:47 +08:00

40 lines
1012 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const babel = require('@babel/core')
var exports = new Map();
var functions = new Map();
var result = new Map();
function parse(code) {
let visitor = {
// 处理exports节点获取导出函数对应表
ExpressionStatement(path) {
let params = path.node.expression.right;
try {
params = params.properties
for (let i = 0; i < params.length; i++) {
exports.set(params[i].value.name, params[i].key.name)
}
} catch {
}
},
// 处理function获取函数名以及对应参数
FunctionDeclaration(path) {
let params = path.node;
var lst = new Array();
for (let i = 0; i < params.params.length; i++) {
lst.push(params.params[i].name)
}
functions.set(params.id.name, lst)
}
}
babel.transform(code, {
plugins: [
{
visitor
}
]
})
exports.forEach(function (value, key, map) {
result.set(value, functions.get(key))
})
return Object.fromEntries(result);
}