Repository URL to install this package:
|
Version:
1.2.11 ▾
|
"use strict";
Object.defineProperty(exports, '__esModule', {
value: true
}); // eslint-disable-next-line
exports.default = void 0;
const t = global._interopRequireWildcard(require('@babel/types'));
/**
* Get the name of variable that contains node
*
* @param {Path} path to the node
*
* @return {String} The target
*/
function getName(path) {
let namedNode; // foo.bar -> bar
path.find(function (path) {
// const X = styled
if (path.isAssignmentExpression()) {
// const X = { Y: styled }
namedNode = path.node.left;
} else if (path.isObjectProperty()) {
// let X; X = styled
namedNode = path.node.key;
} else if (path.isVariableDeclarator()) {
namedNode = path.node.id;
} else if (path.isStatement()) {
// we've hit a statement, we should stop crawling up
return true;
} // we've got an displayName (if we need it) no need to continue
if (namedNode) {
return true;
}
}); // identifiers are the only thing we can reliably get a name from
if (t.isMemberExpression(namedNode)) {
namedNode = namedNode.property;
}
return t.isIdentifier(namedNode) ? namedNode.name : undefined;
}
exports.default = getName;
module.exports = getName;