visitor-keys.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /* eslint-disable jsdoc/valid-types -- doesn't allow `readonly`.
  2. TODO: remove eslint-disable when https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/164 is fixed
  3. */
  4. /**
  5. * @typedef {{ readonly [type: string]: ReadonlyArray<string> }} VisitorKeys
  6. */
  7. /* eslint-enable jsdoc/valid-types -- doesn't allow `readonly string[]`. TODO: check why */
  8. /**
  9. * @type {VisitorKeys}
  10. */
  11. const KEYS = {
  12. ArrayExpression: [
  13. "elements"
  14. ],
  15. ArrayPattern: [
  16. "elements"
  17. ],
  18. ArrowFunctionExpression: [
  19. "params",
  20. "body"
  21. ],
  22. AssignmentExpression: [
  23. "left",
  24. "right"
  25. ],
  26. AssignmentPattern: [
  27. "left",
  28. "right"
  29. ],
  30. AwaitExpression: [
  31. "argument"
  32. ],
  33. BinaryExpression: [
  34. "left",
  35. "right"
  36. ],
  37. BlockStatement: [
  38. "body"
  39. ],
  40. BreakStatement: [
  41. "label"
  42. ],
  43. CallExpression: [
  44. "callee",
  45. "arguments"
  46. ],
  47. CatchClause: [
  48. "param",
  49. "body"
  50. ],
  51. ChainExpression: [
  52. "expression"
  53. ],
  54. ClassBody: [
  55. "body"
  56. ],
  57. ClassDeclaration: [
  58. "id",
  59. "superClass",
  60. "body"
  61. ],
  62. ClassExpression: [
  63. "id",
  64. "superClass",
  65. "body"
  66. ],
  67. ConditionalExpression: [
  68. "test",
  69. "consequent",
  70. "alternate"
  71. ],
  72. ContinueStatement: [
  73. "label"
  74. ],
  75. DebuggerStatement: [],
  76. DoWhileStatement: [
  77. "body",
  78. "test"
  79. ],
  80. EmptyStatement: [],
  81. ExperimentalRestProperty: [
  82. "argument"
  83. ],
  84. ExperimentalSpreadProperty: [
  85. "argument"
  86. ],
  87. ExportAllDeclaration: [
  88. "exported",
  89. "source"
  90. ],
  91. ExportDefaultDeclaration: [
  92. "declaration"
  93. ],
  94. ExportNamedDeclaration: [
  95. "declaration",
  96. "specifiers",
  97. "source"
  98. ],
  99. ExportSpecifier: [
  100. "exported",
  101. "local"
  102. ],
  103. ExpressionStatement: [
  104. "expression"
  105. ],
  106. ForInStatement: [
  107. "left",
  108. "right",
  109. "body"
  110. ],
  111. ForOfStatement: [
  112. "left",
  113. "right",
  114. "body"
  115. ],
  116. ForStatement: [
  117. "init",
  118. "test",
  119. "update",
  120. "body"
  121. ],
  122. FunctionDeclaration: [
  123. "id",
  124. "params",
  125. "body"
  126. ],
  127. FunctionExpression: [
  128. "id",
  129. "params",
  130. "body"
  131. ],
  132. Identifier: [],
  133. IfStatement: [
  134. "test",
  135. "consequent",
  136. "alternate"
  137. ],
  138. ImportDeclaration: [
  139. "specifiers",
  140. "source"
  141. ],
  142. ImportDefaultSpecifier: [
  143. "local"
  144. ],
  145. ImportExpression: [
  146. "source"
  147. ],
  148. ImportNamespaceSpecifier: [
  149. "local"
  150. ],
  151. ImportSpecifier: [
  152. "imported",
  153. "local"
  154. ],
  155. JSXAttribute: [
  156. "name",
  157. "value"
  158. ],
  159. JSXClosingElement: [
  160. "name"
  161. ],
  162. JSXClosingFragment: [],
  163. JSXElement: [
  164. "openingElement",
  165. "children",
  166. "closingElement"
  167. ],
  168. JSXEmptyExpression: [],
  169. JSXExpressionContainer: [
  170. "expression"
  171. ],
  172. JSXFragment: [
  173. "openingFragment",
  174. "children",
  175. "closingFragment"
  176. ],
  177. JSXIdentifier: [],
  178. JSXMemberExpression: [
  179. "object",
  180. "property"
  181. ],
  182. JSXNamespacedName: [
  183. "namespace",
  184. "name"
  185. ],
  186. JSXOpeningElement: [
  187. "name",
  188. "attributes"
  189. ],
  190. JSXOpeningFragment: [],
  191. JSXSpreadAttribute: [
  192. "argument"
  193. ],
  194. JSXSpreadChild: [
  195. "expression"
  196. ],
  197. JSXText: [],
  198. LabeledStatement: [
  199. "label",
  200. "body"
  201. ],
  202. Literal: [],
  203. LogicalExpression: [
  204. "left",
  205. "right"
  206. ],
  207. MemberExpression: [
  208. "object",
  209. "property"
  210. ],
  211. MetaProperty: [
  212. "meta",
  213. "property"
  214. ],
  215. MethodDefinition: [
  216. "key",
  217. "value"
  218. ],
  219. NewExpression: [
  220. "callee",
  221. "arguments"
  222. ],
  223. ObjectExpression: [
  224. "properties"
  225. ],
  226. ObjectPattern: [
  227. "properties"
  228. ],
  229. PrivateIdentifier: [],
  230. Program: [
  231. "body"
  232. ],
  233. Property: [
  234. "key",
  235. "value"
  236. ],
  237. PropertyDefinition: [
  238. "key",
  239. "value"
  240. ],
  241. RestElement: [
  242. "argument"
  243. ],
  244. ReturnStatement: [
  245. "argument"
  246. ],
  247. SequenceExpression: [
  248. "expressions"
  249. ],
  250. SpreadElement: [
  251. "argument"
  252. ],
  253. StaticBlock: [
  254. "body"
  255. ],
  256. Super: [],
  257. SwitchCase: [
  258. "test",
  259. "consequent"
  260. ],
  261. SwitchStatement: [
  262. "discriminant",
  263. "cases"
  264. ],
  265. TaggedTemplateExpression: [
  266. "tag",
  267. "quasi"
  268. ],
  269. TemplateElement: [],
  270. TemplateLiteral: [
  271. "quasis",
  272. "expressions"
  273. ],
  274. ThisExpression: [],
  275. ThrowStatement: [
  276. "argument"
  277. ],
  278. TryStatement: [
  279. "block",
  280. "handler",
  281. "finalizer"
  282. ],
  283. UnaryExpression: [
  284. "argument"
  285. ],
  286. UpdateExpression: [
  287. "argument"
  288. ],
  289. VariableDeclaration: [
  290. "declarations"
  291. ],
  292. VariableDeclarator: [
  293. "id",
  294. "init"
  295. ],
  296. WhileStatement: [
  297. "test",
  298. "body"
  299. ],
  300. WithStatement: [
  301. "object",
  302. "body"
  303. ],
  304. YieldExpression: [
  305. "argument"
  306. ]
  307. };
  308. // Types.
  309. const NODE_TYPES = Object.keys(KEYS);
  310. // Freeze the keys.
  311. for (const type of NODE_TYPES) {
  312. Object.freeze(KEYS[type]);
  313. }
  314. Object.freeze(KEYS);
  315. export default KEYS;