Simplify NewExpression|CallExpression visitor
This commit is contained in:
@@ -34,36 +34,34 @@ export default function ({ types: t }) {
|
||||
));
|
||||
},
|
||||
|
||||
"NewExpression|CallExpression": {
|
||||
exit(path) {
|
||||
if (!path.node.optional) {
|
||||
return;
|
||||
}
|
||||
"NewExpression|CallExpression"(path) {
|
||||
if (!path.node.optional) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { scope, node } = path;
|
||||
const { callee } = node;
|
||||
const { scope, node } = path;
|
||||
const { callee } = node;
|
||||
|
||||
node.optional = false;
|
||||
node.optional = false;
|
||||
|
||||
const ref = scope.generateUidIdentifierBasedOnNode(callee);
|
||||
scope.push({ id: ref });
|
||||
node.callee = ref;
|
||||
const ref = scope.generateUidIdentifierBasedOnNode(callee);
|
||||
scope.push({ id: ref });
|
||||
node.callee = ref;
|
||||
|
||||
if (t.isMemberExpression(callee) && !t.isNewExpression(node)) {
|
||||
const context = scope.generateUidIdentifierBasedOnNode(callee.object);
|
||||
scope.push({ id: context });
|
||||
callee.object = t.assignmentExpression("=", context, callee.object);
|
||||
if (t.isMemberExpression(callee) && !t.isNewExpression(node)) {
|
||||
const context = scope.generateUidIdentifierBasedOnNode(callee.object);
|
||||
scope.push({ id: context });
|
||||
callee.object = t.assignmentExpression("=", context, callee.object);
|
||||
|
||||
node.arguments.unshift(context);
|
||||
node.callee = t.memberExpression(node.callee, t.identifier("call"));
|
||||
}
|
||||
node.arguments.unshift(context);
|
||||
node.callee = t.memberExpression(node.callee, t.identifier("call"));
|
||||
}
|
||||
|
||||
path.replaceWith(t.conditionalExpression(
|
||||
t.binaryExpression("==", t.assignmentExpression("=", ref, callee), t.nullLiteral()),
|
||||
scope.buildUndefinedNode(),
|
||||
node
|
||||
));
|
||||
},
|
||||
path.replaceWith(t.conditionalExpression(
|
||||
t.binaryExpression("==", t.assignmentExpression("=", ref, callee), t.nullLiteral()),
|
||||
scope.buildUndefinedNode(),
|
||||
node
|
||||
));
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user