not-dom-node.js 797 B

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. const {isUndefined} = require('../ast/index.js');
  3. // AST Types:
  4. // https://github.com/eslint/espree/blob/master/lib/ast-node-types.js#L18
  5. // Only types possible to be `callee` or `argument` are listed
  6. const impossibleNodeTypes = [
  7. 'ArrayExpression',
  8. 'ArrowFunctionExpression',
  9. 'ClassExpression',
  10. 'FunctionExpression',
  11. 'Literal',
  12. 'ObjectExpression',
  13. 'TemplateLiteral',
  14. ];
  15. // We might need this later
  16. /* c8 ignore start */
  17. const isNotDomNode = node =>
  18. impossibleNodeTypes.includes(node.type)
  19. || isUndefined(node);
  20. /* c8 ignore end */
  21. const notDomNodeSelector = node => [
  22. ...impossibleNodeTypes.map(type => `[${node}.type!="${type}"]`),
  23. `:not([${node}.type="Identifier"][${node}.name="undefined"])`,
  24. ].join('');
  25. module.exports = {
  26. isNotDomNode,
  27. notDomNodeSelector,
  28. };