source: imaps-frontend/node_modules/eslint-visitor-keys/lib/index.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/**
2 * @author Toru Nagashima <https://github.com/mysticatea>
3 * See LICENSE file in root directory for full license.
4 */
5import KEYS from "./visitor-keys.js";
6
7/**
8 * @typedef {import('./visitor-keys.js').VisitorKeys} VisitorKeys
9 */
10
11// List to ignore keys.
12const KEY_BLACKLIST = new Set([
13 "parent",
14 "leadingComments",
15 "trailingComments"
16]);
17
18/**
19 * Check whether a given key should be used or not.
20 * @param {string} key The key to check.
21 * @returns {boolean} `true` if the key should be used.
22 */
23function filterKey(key) {
24 return !KEY_BLACKLIST.has(key) && key[0] !== "_";
25}
26
27/**
28 * Get visitor keys of a given node.
29 * @param {object} node The AST node to get keys.
30 * @returns {readonly string[]} Visitor keys of the node.
31 */
32export function getKeys(node) {
33 return Object.keys(node).filter(filterKey);
34}
35
36// Disable valid-jsdoc rule because it reports syntax error on the type of @returns.
37// eslint-disable-next-line valid-jsdoc
38/**
39 * Make the union set with `KEYS` and given keys.
40 * @param {VisitorKeys} additionalKeys The additional keys.
41 * @returns {VisitorKeys} The union set.
42 */
43export function unionWith(additionalKeys) {
44 const retv = /** @type {{
45 [type: string]: ReadonlyArray<string>
46 }} */ (Object.assign({}, KEYS));
47
48 for (const type of Object.keys(additionalKeys)) {
49 if (Object.prototype.hasOwnProperty.call(retv, type)) {
50 const keys = new Set(additionalKeys[type]);
51
52 for (const key of retv[type]) {
53 keys.add(key);
54 }
55
56 retv[type] = Object.freeze(Array.from(keys));
57 } else {
58 retv[type] = Object.freeze(Array.from(additionalKeys[type]));
59 }
60 }
61
62 return Object.freeze(retv);
63}
64
65export { KEYS };
Note: See TracBrowser for help on using the repository browser.