not-dom-node.js 771 B

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