@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
29 lines (28 loc) • 1.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getImportName = void 0;
var _eslintCodemodUtils = require("eslint-codemod-utils");
var getImportName = exports.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 || !(0, _eslintCodemodUtils.isNodeOfType)(def.node, 'ImportSpecifier') || !def.parent || !(0, _eslintCodemodUtils.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;
};