should-add-parentheses-to-expression-statement-expression.js 607 B

123456789101112131415161718192021
  1. 'use strict';
  2. /**
  3. Check if parentheses should to be added to a `node` when it's used as an `expression` of `ExpressionStatement`.
  4. @param {Node} node - The AST node to check.
  5. @param {SourceCode} sourceCode - The source code object.
  6. @returns {boolean}
  7. */
  8. function shouldAddParenthesesToExpressionStatementExpression(node) {
  9. switch (node.type) {
  10. case 'ObjectExpression':
  11. return true;
  12. case 'AssignmentExpression':
  13. return node.left.type === 'ObjectPattern' || node.left.type === 'ArrayPattern';
  14. default:
  15. return false;
  16. }
  17. }
  18. module.exports = shouldAddParenthesesToExpressionStatementExpression;