Skip to content

Commit 9418250

Browse files
committed
good
1 parent a47f6d0 commit 9418250

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

babel-plugin-expose-private-functions-and-variables.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ module.exports = function ({types: t}) {
4747
// collect private functions and replace them with `window.PACKAGE._._func = function (args) {...}`
4848
} else if (t.isFunctionDeclaration(node) && t.isIdentifier(node.id)) {
4949
if (node.id.name === '_zk') return;
50-
// if (node.id.name === 'echoGx') return;
5150
privateFuncs.add(node.id.name);
5251
funcCallCount.set(node.id.name, 0);
5352
path.get('body')[index].replaceWith(
@@ -124,7 +123,6 @@ module.exports = function ({types: t}) {
124123
const left = assignPath.node.left,
125124
right = assignPath.node.right;
126125
// case: FUNC.x = x -> window.PACKAGE._.FUNC.x = x
127-
// FIXME: useless
128126
if (t.isMemberExpression(left)) {
129127
const object = left.object;
130128
if (t.isIdentifier(object) && privateFuncs.has(object.name)) {
@@ -138,16 +136,6 @@ module.exports = function ({types: t}) {
138136
assignPath.node.right = createNestedMemberExpression([right.name, ...dir]);
139137
}
140138
},
141-
// FIXME: useless
142-
// MemberExpression(memberPath) {
143-
// const { object, property } = memberPath.node,
144-
// callee = object.callee;
145-
// // case: FUNC.x = y -> window.PACKAGE._.FUNC.x = y
146-
// if (t.isIdentifier(callee) && privateFuncs.has(callee.name)) {
147-
// funcCallCount.set(callee.name, funcCallCount.get(callee.name) + 1);
148-
// memberPath = createNestedMemberExpression([callee.name, ...dir]);
149-
// }
150-
// },
151139
ConditionalExpression(condPath) {
152140
const { test, consequent, alternate } = condPath.node;
153141
// TODO: test ?
@@ -183,10 +171,11 @@ module.exports = function ({types: t}) {
183171
},
184172
ObjectExpression(objectPath) {
185173
objectPath.node.properties.forEach((property) => {
174+
const {key, value} = property;
186175
// case: x = { x: FUNC } -> x = { x: window.PACKAGE._.FUNC }
187176
// case: x.x = FUNC -> x.x = window.PACKAGE._.FUNC
188-
if (t.isIdentifier(property.value) && privateFuncs.has(property.value.name)) {
189-
funcCallCount.set(property.value.name, funcCallCount.get(property.value.name) + 1);
177+
if (t.isIdentifier(value) && privateFuncs.has(value.name)) {
178+
funcCallCount.set(value.name, funcCallCount.get(value.name) + 1);
190179
property.value = createNestedMemberExpression([property.value.name, ...dir]);
191180
}
192181
});

0 commit comments

Comments
 (0)