2 * @author Toru Nagashima <https://github.com/mysticatea>
3 * See LICENSE file in root directory for full license.
7 const KEYS = require("./visitor-keys.json");
10 const NODE_TYPES = Object.freeze(Object.keys(KEYS));
13 for (const type of NODE_TYPES) {
14 Object.freeze(KEYS[type]);
18 // List to ignore keys.
19 const KEY_BLACKLIST = new Set([
26 * Check whether a given key should be used or not.
27 * @param {string} key The key to check.
28 * @returns {boolean} `true` if the key should be used.
30 function filterKey(key) {
31 return !KEY_BLACKLIST.has(key) && key[0] !== "_";
34 //------------------------------------------------------------------------------
36 //------------------------------------------------------------------------------
38 module.exports = Object.freeze({
42 * @type {{ [type: string]: string[] | undefined }}
47 * Get visitor keys of a given node.
48 * @param {Object} node The AST node to get keys.
49 * @returns {string[]} Visitor keys of the node.
52 return Object.keys(node).filter(filterKey);
55 // Disable valid-jsdoc rule because it reports syntax error on the type of @returns.
56 // eslint-disable-next-line valid-jsdoc
58 * Make the union set with `KEYS` and given keys.
59 * @param {Object} additionalKeys The additional keys.
60 * @returns {{ [type: string]: string[] | undefined }} The union set.
62 unionWith(additionalKeys) {
63 const retv = Object.assign({}, KEYS);
65 for (const type of Object.keys(additionalKeys)) {
66 if (retv.hasOwnProperty(type)) {
67 const keys = new Set(additionalKeys[type]);
69 for (const key of retv[type]) {
73 retv[type] = Object.freeze(Array.from(keys));
75 retv[type] = Object.freeze(Array.from(additionalKeys[type]));
79 return Object.freeze(retv);