match-keys.js 762 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const { KEYS, getKeys } = require('eslint-visitor-keys');
  2. const ignoredKeys = new Set([
  3. 'start',
  4. 'end',
  5. 'loc',
  6. 'range',
  7. 'extra',
  8. '_babelType',
  9. // TODO: probably should not ignore (not sure yet)
  10. 'typeArguments',
  11. 'exportKind',
  12. 'importKind',
  13. // TODO: should not ignore
  14. 'optional',
  15. ]);
  16. const ignoredLiteralKeys = new Set([
  17. 'value',
  18. 'regex',
  19. ]);
  20. const getMatchKeys = node => {
  21. const keys = getKeys(node).filter(key => !ignoredKeys.has(key));
  22. const visitorKeys = KEYS[node.type];
  23. let equalityKeys = keys.filter(key => !visitorKeys.includes(key));
  24. if (node.type === 'Literal') {
  25. equalityKeys = equalityKeys.filter(key => !ignoredLiteralKeys.has(key));
  26. }
  27. return {
  28. visitorKeys,
  29. equalityKeys,
  30. };
  31. };
  32. module.exports = {
  33. getMatchKeys,
  34. };