UNPKG

react-magnetic-di

Version:
16 lines (14 loc) 1.02 kB
"use strict"; var processReference = function processReference(t, ref) { var _nextSibling$node$exp; var container = ref.parentPath.container; if (container.type !== 'VariableDeclarator') return; var containerID = container.id; // check if display name already set by someone else right after def var nextSibling = ref.getStatementParent().getNextSibling(); if (nextSibling.isExpressionStatement() && ((_nextSibling$node$exp = nextSibling.node.expression) === null || _nextSibling$node$exp === void 0 || (_nextSibling$node$exp = _nextSibling$node$exp.left) === null || _nextSibling$node$exp === void 0 || (_nextSibling$node$exp = _nextSibling$node$exp.property) === null || _nextSibling$node$exp === void 0 ? 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;