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

1234567891011121314151617181920212223242526
  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. }
  13. case 'AssignmentExpression': {
  14. return node.left.type === 'ObjectPattern' || node.left.type === 'ArrayPattern';
  15. }
  16. default: {
  17. return false;
  18. }
  19. }
  20. }
  21. module.exports = shouldAddParenthesesToExpressionStatementExpression;