UNPKG

@atlaskit/eslint-plugin-design-system

Version:

The essential plugin for use with the Atlassian Design System.

23 lines 974 B
import { isNodeOfType } from 'eslint-codemod-utils'; export var getImportName = function getImportName(scope, packageName, componentName) { var traversingScope = scope; var matchedVariable; while (traversingScope && traversingScope.type !== 'global') { matchedVariable = traversingScope.variables.find(function (variable) { var _variable$defs; var def = (_variable$defs = variable.defs) === null || _variable$defs === void 0 ? void 0 : _variable$defs[0]; if (!def || !def.node || !isNodeOfType(def.node, 'ImportSpecifier') || !def.parent || !isNodeOfType(def.parent, 'ImportDeclaration')) { return; } return def.parent.source.value === packageName && 'name' in def.node.imported && def.node.imported.name === componentName; }); if (matchedVariable) { break; } traversingScope = traversingScope.upper; } if (!matchedVariable) { return null; } return matchedVariable.defs[0].node.local.name; };