react-magnetic-di
Version:
Context driven dependency injection
14 lines (13 loc) • 883 B
JavaScript
const processReference = (t, ref) => {
var _nextSibling$node$exp;
const container = ref.parentPath.container;
if (container.type !== 'VariableDeclarator') return;
const containerID = container.id;
// check if display name already set by someone else right after def
const nextSibling = ref.getStatementParent().getNextSibling();
if (nextSibling.isExpressionStatement() && ((_nextSibling$node$exp = nextSibling.node.expression) == null || (_nextSibling$node$exp = _nextSibling$node$exp.left) == null || (_nextSibling$node$exp = _nextSibling$node$exp.property) == null ? void 0 : _nextSibling$node$exp.name) == 'displayName') {
return;
}
ref.getStatementParent().insertAfter(t.expressionStatement(t.assignmentExpression('=', t.memberExpression(containerID, t.identifier('displayName')), t.stringLiteral(containerID.name))));
};
module.exports = processReference;