eslint-plugin-unicorn-x
Version:
More than 100 powerful ESLint rules
19 lines (14 loc) • 359 B
JavaScript
const isChainElement = (node) =>
node.type === 'MemberExpression' || node.type === 'CallExpression';
export default function hasOptionalChainElement(node) {
if (!isChainElement(node)) {
return false;
}
if (node.optional) {
return true;
}
if (node.type === 'MemberExpression') {
return hasOptionalChainElement(node.object);
}
return false;
}