租房小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
2.7 KiB

3 months ago
  1. # eslint-visitor-keys
  2. [![npm version](https://img.shields.io/npm/v/eslint-visitor-keys.svg)](https://www.npmjs.com/package/eslint-visitor-keys)
  3. [![Downloads/month](https://img.shields.io/npm/dm/eslint-visitor-keys.svg)](http://www.npmtrends.com/eslint-visitor-keys)
  4. [![Build Status](https://github.com/eslint/eslint-visitor-keys/workflows/CI/badge.svg)](https://github.com/eslint/eslint-visitor-keys/actions)
  5. Constants and utilities about visitor keys to traverse AST.
  6. ## 💿 Installation
  7. Use [npm] to install.
  8. ```bash
  9. $ npm install eslint-visitor-keys
  10. ```
  11. ### Requirements
  12. - [Node.js] `^12.22.0`, `^14.17.0`, or `>=16.0.0`
  13. ## 📖 Usage
  14. To use in an ESM file:
  15. ```js
  16. import * as evk from "eslint-visitor-keys"
  17. ```
  18. To use in a CommonJS file:
  19. ```js
  20. const evk = require("eslint-visitor-keys")
  21. ```
  22. ### evk.KEYS
  23. > type: `{ [type: string]: string[] | undefined }`
  24. Visitor keys. This keys are frozen.
  25. This is an object. Keys are the type of [ESTree] nodes. Their values are an array of property names which have child nodes.
  26. For example:
  27. ```
  28. console.log(evk.KEYS.AssignmentExpression) // → ["left", "right"]
  29. ```
  30. ### evk.getKeys(node)
  31. > type: `(node: object) => string[]`
  32. Get the visitor keys of a given AST node.
  33. This is similar to `Object.keys(node)` of ES Standard, but some keys are excluded: `parent`, `leadingComments`, `trailingComments`, and names which start with `_`.
  34. This will be used to traverse unknown nodes.
  35. For example:
  36. ```js
  37. const node = {
  38. type: "AssignmentExpression",
  39. left: { type: "Identifier", name: "foo" },
  40. right: { type: "Literal", value: 0 }
  41. }
  42. console.log(evk.getKeys(node)) // → ["type", "left", "right"]
  43. ```
  44. ### evk.unionWith(additionalKeys)
  45. > type: `(additionalKeys: object) => { [type: string]: string[] | undefined }`
  46. Make the union set with `evk.KEYS` and the given keys.
  47. - The order of keys is, `additionalKeys` is at first, then `evk.KEYS` is concatenated after that.
  48. - It removes duplicated keys as keeping the first one.
  49. For example:
  50. ```js
  51. console.log(evk.unionWith({
  52. MethodDefinition: ["decorators"]
  53. })) // → { ..., MethodDefinition: ["decorators", "key", "value"], ... }
  54. ```
  55. ## 📰 Change log
  56. See [GitHub releases](https://github.com/eslint/eslint-visitor-keys/releases).
  57. ## 🍻 Contributing
  58. Welcome. See [ESLint contribution guidelines](https://eslint.org/docs/developer-guide/contributing/).
  59. ### Development commands
  60. - `npm test` runs tests and measures code coverage.
  61. - `npm run lint` checks source codes with ESLint.
  62. - `npm run test:open-coverage` opens the code coverage report of the previous test with your default browser.
  63. [npm]: https://www.npmjs.com/
  64. [Node.js]: https://nodejs.org/
  65. [ESTree]: https://github.com/estree/estree