Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
JamsonChan committed Oct 10, 2024
1 parent 3b788a9 commit 3cf56ec
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions babel-plugin-expose-private-functions-and-variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,23 +179,29 @@ module.exports = function ({types: t}) {
}

function callExp(callPath) {
const callee = callPath.node.callee;
if (t.isIdentifier(callee)) {
// case: FUNC() -> window.PACKAGE._.FUNC()
// this case includes `FUNC() in ?: conditional`
if (privateFuncs.has(callee.name)) {
funcCallCount.set(callee.name, funcCallCount.get(callee.name) + 1);
callPath.node.callee = createNestedMemberExpression([callee.name, ...dir]);
}
const args = callPath.get('arguments');
args.forEach(arg => {
// case: xxx(FUNC) -> xxx(window.PACKAGE._.FUNC)
if (t.isIdentifier(arg.node) && privateFuncs.has(arg.node.name)) {
funcCallCount.set(arg.node.name, funcCallCount.get(arg.node.name) + 1);
arg.replaceWith(createNestedMemberExpression([arg.node.name, ...dir]));
}
});
// CallExpression (callee, arguments)
// x(y...) -> callee: x, arguments: y...


dfs(callPath.get('callee'));

const { callee, arguments: args } = callPath.node;

// case: FUNC() -> window.PACKAGE._.FUNC()
if (t.isIdentifier(callee) && privateFuncs.has(callee.name)) {
funcCallCount.set(callee.name, funcCallCount.get(callee.name) + 1);
callPath.node.callee = createNestedMemberExpression([callee.name, ...dir]);
}

// const args = callPath.get('arguments');
args.forEach(arg => {
// dfs(arg);
// case: xxx(FUNC...) -> xxx(window.PACKAGE._.FUNC...)
if (t.isIdentifier(arg.node) && privateFuncs.has(arg.node.name)) {
funcCallCount.set(arg.node.name, funcCallCount.get(arg.node.name) + 1);
arg.replaceWith(createNestedMemberExpression([arg.node.name, ...dir]));
}
});
}

function objExp(objectPath) {
Expand Down

0 comments on commit 3cf56ec

Please sign in to comment.