should-add-parentheses-to-spread-element-argument.js 532 B

12345678910111213141516171819202122
  1. 'use strict';
  2. const nodeTypesDoNotNeedParentheses = new Set([
  3. 'CallExpression',
  4. 'Identifier',
  5. 'Literal',
  6. 'MemberExpression',
  7. 'NewExpression',
  8. 'TemplateLiteral',
  9. 'ThisExpression',
  10. ]);
  11. /**
  12. Check if parentheses should be added to a `node` when it's used as `argument` of `SpreadElement`.
  13. @param {Node} node - The AST node to check.
  14. @returns {boolean}
  15. */
  16. const shouldAddParenthesesToSpreadElementArgument = node =>
  17. !nodeTypesDoNotNeedParentheses.has(node.type);
  18. module.exports = shouldAddParenthesesToSpreadElementArgument;