eslint-plugin-unicorn
Version:
More than 100 powerful ESLint rules
18 lines (13 loc) • 356 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;
}