is-logical-expression.js 675 B

12345678910111213141516
  1. 'use strict';
  2. /**
  3. Check if the given node is a true logical expression or not.
  4. The three binary expressions logical-or (`||`), logical-and (`&&`), and coalesce (`??`) are known as `ShortCircuitExpression`, but ESTree represents these by the `LogicalExpression` node type. This function rejects coalesce expressions of `LogicalExpression` node type.
  5. @param {Node} node - The node to check.
  6. @returns {boolean} `true` if the node is `&&` or `||`.
  7. @see https://tc39.es/ecma262/#prod-ShortCircuitExpression
  8. */
  9. const isLogicalExpression = node =>
  10. node?.type === 'LogicalExpression'
  11. && (node.operator === '&&' || node.operator === '||');
  12. module.exports = isLogicalExpression;