@danielblomma/cortex-mcp 1.3.2 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/README.md +62 -14
  2. package/package.json +2 -2
  3. package/scaffold/mcp/package-lock.json +3 -7
  4. package/scaffold/mcp/package.json +1 -1
  5. package/scaffold/scripts/dashboard.mjs +15 -1
  6. package/scaffold/scripts/ingest.mjs +323 -50
  7. package/scaffold/scripts/parsers/bash-treesitter.mjs +229 -0
  8. package/scaffold/scripts/parsers/cpp-dispatch.mjs +56 -0
  9. package/scaffold/scripts/parsers/cpp-treesitter.mjs +333 -0
  10. package/scaffold/scripts/parsers/csharp.mjs +197 -10
  11. package/scaffold/scripts/parsers/dotnet/CSharpParser/CSharpParser.csproj +1 -0
  12. package/scaffold/scripts/parsers/dotnet/CSharpParser/Program.cs +126 -21
  13. package/scaffold/scripts/parsers/go-treesitter.mjs +283 -0
  14. package/scaffold/scripts/parsers/java-treesitter.mjs +250 -0
  15. package/scaffold/scripts/parsers/javascript/ast.mjs +118 -12
  16. package/scaffold/scripts/parsers/javascript/chunks.mjs +4 -0
  17. package/scaffold/scripts/parsers/javascript/patterns.mjs +6 -0
  18. package/scaffold/scripts/parsers/javascript.mjs +4 -19
  19. package/scaffold/scripts/parsers/node_modules/.package-lock.json +57 -0
  20. package/scaffold/scripts/parsers/node_modules/acorn/CHANGELOG.md +972 -0
  21. package/scaffold/scripts/parsers/node_modules/acorn/LICENSE +21 -0
  22. package/scaffold/scripts/parsers/node_modules/acorn/README.md +301 -0
  23. package/scaffold/scripts/parsers/node_modules/acorn/bin/acorn +4 -0
  24. package/scaffold/scripts/parsers/node_modules/acorn/dist/acorn.d.mts +883 -0
  25. package/scaffold/scripts/parsers/node_modules/acorn/dist/acorn.d.ts +883 -0
  26. package/scaffold/scripts/parsers/node_modules/acorn/dist/acorn.js +6295 -0
  27. package/scaffold/scripts/parsers/node_modules/acorn/dist/acorn.mjs +6266 -0
  28. package/scaffold/scripts/parsers/node_modules/acorn/dist/bin.js +90 -0
  29. package/scaffold/scripts/parsers/node_modules/acorn/package.json +50 -0
  30. package/scaffold/scripts/parsers/node_modules/acorn-typescript/CHANGELOG.md +421 -0
  31. package/scaffold/scripts/parsers/node_modules/acorn-typescript/LICENSE +21 -0
  32. package/scaffold/scripts/parsers/node_modules/acorn-typescript/README.md +81 -0
  33. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/error.d.ts +103 -0
  34. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/error.js +78 -0
  35. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/error.js.map +1 -0
  36. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/decorators.d.ts +167 -0
  37. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/decorators.js +75 -0
  38. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/decorators.js.map +1 -0
  39. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/import-assertions.d.ts +177 -0
  40. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/import-assertions.js +56 -0
  41. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/import-assertions.js.map +1 -0
  42. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/index.d.ts +198 -0
  43. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/index.js +327 -0
  44. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/index.js.map +1 -0
  45. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/xhtml.d.ts +256 -0
  46. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/xhtml.js +256 -0
  47. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/xhtml.js.map +1 -0
  48. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/index.d.ts +472 -0
  49. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/index.js +1 -0
  50. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/index.js.map +1 -0
  51. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/index.mjs +1 -0
  52. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/middleware.d.ts +159 -0
  53. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/middleware.js +2 -0
  54. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/middleware.js.map +1 -0
  55. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/parseutil.d.ts +10 -0
  56. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/parseutil.js +38 -0
  57. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/parseutil.js.map +1 -0
  58. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/scopeflags.d.ts +12 -0
  59. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/scopeflags.js +29 -0
  60. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/scopeflags.js.map +1 -0
  61. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/tokenType.d.ts +2 -0
  62. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/tokenType.js +118 -0
  63. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/tokenType.js.map +1 -0
  64. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/types.d.ts +60 -0
  65. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/types.js +2 -0
  66. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/types.js.map +1 -0
  67. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/whitespace.d.ts +2 -0
  68. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/whitespace.js +19 -0
  69. package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/whitespace.js.map +1 -0
  70. package/scaffold/scripts/parsers/node_modules/acorn-typescript/package.json +53 -0
  71. package/scaffold/scripts/parsers/node_modules/acorn-typescript/tsconfig.json +19 -0
  72. package/scaffold/scripts/parsers/node_modules/acorn-walk/CHANGELOG.md +209 -0
  73. package/scaffold/scripts/parsers/node_modules/acorn-walk/LICENSE +21 -0
  74. package/scaffold/scripts/parsers/node_modules/acorn-walk/README.md +124 -0
  75. package/scaffold/scripts/parsers/node_modules/acorn-walk/dist/walk.d.mts +152 -0
  76. package/scaffold/scripts/parsers/node_modules/acorn-walk/dist/walk.d.ts +152 -0
  77. package/scaffold/scripts/parsers/node_modules/acorn-walk/dist/walk.js +485 -0
  78. package/scaffold/scripts/parsers/node_modules/acorn-walk/dist/walk.mjs +467 -0
  79. package/scaffold/scripts/parsers/node_modules/acorn-walk/package.json +50 -0
  80. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/LICENSE +24 -0
  81. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/README.md +23 -0
  82. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-bash.wasm +0 -0
  83. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-c.wasm +0 -0
  84. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-c_sharp.wasm +0 -0
  85. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-cpp.wasm +0 -0
  86. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-css.wasm +0 -0
  87. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-dart.wasm +0 -0
  88. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-elisp.wasm +0 -0
  89. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-elixir.wasm +0 -0
  90. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-elm.wasm +0 -0
  91. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-embedded_template.wasm +0 -0
  92. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-go.wasm +0 -0
  93. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-html.wasm +0 -0
  94. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-java.wasm +0 -0
  95. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-javascript.wasm +0 -0
  96. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-json.wasm +0 -0
  97. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-kotlin.wasm +0 -0
  98. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-lua.wasm +0 -0
  99. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-objc.wasm +0 -0
  100. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-ocaml.wasm +0 -0
  101. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-php.wasm +0 -0
  102. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-python.wasm +0 -0
  103. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-ql.wasm +0 -0
  104. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-rescript.wasm +0 -0
  105. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-ruby.wasm +0 -0
  106. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-rust.wasm +0 -0
  107. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-scala.wasm +0 -0
  108. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-solidity.wasm +0 -0
  109. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-swift.wasm +0 -0
  110. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-systemrdl.wasm +0 -0
  111. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-tlaplus.wasm +0 -0
  112. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-toml.wasm +0 -0
  113. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-tsx.wasm +0 -0
  114. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-typescript.wasm +0 -0
  115. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-vue.wasm +0 -0
  116. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-yaml.wasm +0 -0
  117. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-zig.wasm +0 -0
  118. package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/package.json +64 -0
  119. package/scaffold/scripts/parsers/node_modules/web-tree-sitter/LICENSE +21 -0
  120. package/scaffold/scripts/parsers/node_modules/web-tree-sitter/README.md +198 -0
  121. package/scaffold/scripts/parsers/node_modules/web-tree-sitter/package.json +37 -0
  122. package/scaffold/scripts/parsers/node_modules/web-tree-sitter/tree-sitter-web.d.ts +242 -0
  123. package/scaffold/scripts/parsers/node_modules/web-tree-sitter/tree-sitter.js +1 -0
  124. package/scaffold/scripts/parsers/node_modules/web-tree-sitter/tree-sitter.wasm +0 -0
  125. package/scaffold/scripts/parsers/package-lock.json +19 -1
  126. package/scaffold/scripts/parsers/package.json +3 -1
  127. package/scaffold/scripts/parsers/python-treesitter.mjs +271 -0
  128. package/scaffold/scripts/parsers/ruby-treesitter.mjs +271 -0
  129. package/scaffold/scripts/parsers/rust-dispatch.mjs +43 -0
  130. package/scaffold/scripts/parsers/rust-treesitter.mjs +291 -0
  131. package/scaffold/scripts/parsers/tree-sitter/base.mjs +163 -0
  132. package/scaffold/scripts/parsers/tree-sitter/queries/bash.calls.scm +7 -0
  133. package/scaffold/scripts/parsers/tree-sitter/queries/bash.chunks.scm +6 -0
  134. package/scaffold/scripts/parsers/tree-sitter/queries/bash.imports.scm +5 -0
  135. package/scaffold/scripts/parsers/tree-sitter/queries/cpp.calls.scm +17 -0
  136. package/scaffold/scripts/parsers/tree-sitter/queries/cpp.chunks.scm +30 -0
  137. package/scaffold/scripts/parsers/tree-sitter/queries/cpp.imports.scm +6 -0
  138. package/scaffold/scripts/parsers/tree-sitter/queries/go.calls.scm +11 -0
  139. package/scaffold/scripts/parsers/tree-sitter/queries/go.chunks.scm +19 -0
  140. package/scaffold/scripts/parsers/tree-sitter/queries/go.imports.scm +6 -0
  141. package/scaffold/scripts/parsers/tree-sitter/queries/java.calls.scm +6 -0
  142. package/scaffold/scripts/parsers/tree-sitter/queries/java.chunks.scm +23 -0
  143. package/scaffold/scripts/parsers/tree-sitter/queries/java.imports.scm +6 -0
  144. package/scaffold/scripts/parsers/tree-sitter/queries/python.calls.scm +11 -0
  145. package/scaffold/scripts/parsers/tree-sitter/queries/python.chunks.scm +11 -0
  146. package/scaffold/scripts/parsers/tree-sitter/queries/python.imports.scm +13 -0
  147. package/scaffold/scripts/parsers/tree-sitter/queries/ruby.calls.scm +6 -0
  148. package/scaffold/scripts/parsers/tree-sitter/queries/ruby.chunks.scm +16 -0
  149. package/scaffold/scripts/parsers/tree-sitter/queries/ruby.imports.scm +8 -0
  150. package/scaffold/scripts/parsers/tree-sitter/queries/rust.calls.scm +31 -0
  151. package/scaffold/scripts/parsers/tree-sitter/queries/rust.chunks.scm +29 -0
  152. package/scaffold/scripts/parsers/tree-sitter/queries/rust.imports.scm +5 -0
  153. package/scaffold/scripts/parsers/vb6.mjs +395 -0
@@ -0,0 +1,152 @@
1
+ import * as acorn from "acorn"
2
+
3
+ export type FullWalkerCallback<TState> = (
4
+ node: acorn.AnyNode,
5
+ state: TState,
6
+ type: string
7
+ ) => void
8
+
9
+ export type FullAncestorWalkerCallback<TState> = (
10
+ node: acorn.AnyNode,
11
+ state: TState,
12
+ ancestors: acorn.AnyNode[],
13
+ type: string
14
+ ) => void
15
+
16
+ type AggregateType = {
17
+ Expression: acorn.Expression,
18
+ Statement: acorn.Statement,
19
+ Function: acorn.Function,
20
+ Class: acorn.Class,
21
+ Pattern: acorn.Pattern,
22
+ ForInit: acorn.VariableDeclaration | acorn.Expression
23
+ }
24
+
25
+ export type SimpleVisitors<TState> = {
26
+ [type in acorn.AnyNode["type"]]?: (node: Extract<acorn.AnyNode, { type: type }>, state: TState) => void
27
+ } & {
28
+ [type in keyof AggregateType]?: (node: AggregateType[type], state: TState) => void
29
+ }
30
+
31
+ export type AncestorVisitors<TState> = {
32
+ [type in acorn.AnyNode["type"]]?: ( node: Extract<acorn.AnyNode, { type: type }>, state: TState, ancestors: acorn.AnyNode[]
33
+ ) => void
34
+ } & {
35
+ [type in keyof AggregateType]?: (node: AggregateType[type], state: TState, ancestors: acorn.AnyNode[]) => void
36
+ }
37
+
38
+ export type WalkerCallback<TState> = (node: acorn.AnyNode, state: TState) => void
39
+
40
+ export type RecursiveVisitors<TState> = {
41
+ [type in acorn.AnyNode["type"]]?: ( node: Extract<acorn.AnyNode, { type: type }>, state: TState, callback: WalkerCallback<TState>) => void
42
+ } & {
43
+ [type in keyof AggregateType]?: (node: AggregateType[type], state: TState, callback: WalkerCallback<TState>) => void
44
+ }
45
+
46
+ export type FindPredicate = (type: string, node: acorn.AnyNode) => boolean
47
+
48
+ export interface Found<TState> {
49
+ node: acorn.AnyNode,
50
+ state: TState
51
+ }
52
+
53
+ /**
54
+ * does a 'simple' walk over a tree
55
+ * @param node the AST node to walk
56
+ * @param visitors an object with properties whose names correspond to node types in the {@link https://github.com/estree/estree | ESTree spec}. The properties should contain functions that will be called with the node object and, if applicable the state at that point.
57
+ * @param base a walker algorithm
58
+ * @param state a start state. The default walker will simply visit all statements and expressions and not produce a meaningful state. (An example of a use of state is to track scope at each point in the tree.)
59
+ */
60
+ export function simple<TState>(
61
+ node: acorn.Node,
62
+ visitors: SimpleVisitors<TState>,
63
+ base?: RecursiveVisitors<TState>,
64
+ state?: TState
65
+ ): void
66
+
67
+ /**
68
+ * does a 'simple' walk over a tree, building up an array of ancestor nodes (including the current node) and passing the array to the callbacks as a third parameter.
69
+ */
70
+ export function ancestor<TState>(
71
+ node: acorn.Node,
72
+ visitors: AncestorVisitors<TState>,
73
+ base?: RecursiveVisitors<TState>,
74
+ state?: TState
75
+ ): void
76
+
77
+ /**
78
+ * does a 'recursive' walk, where the walker functions are responsible for continuing the walk on the child nodes of their target node.
79
+ * @param node
80
+ * @param state the start state
81
+ * @param functions contain an object that maps node types to walker functions
82
+ * @param base provides the fallback walker functions for node types that aren't handled in the {@link functions} object. If not given, the default walkers will be used.
83
+ */
84
+ export function recursive<TState>(
85
+ node: acorn.Node,
86
+ state: TState,
87
+ functions: RecursiveVisitors<TState>,
88
+ base?: RecursiveVisitors<TState>
89
+ ): void
90
+
91
+ /**
92
+ * does a 'full' walk over a tree, calling the {@link callback} with the arguments (node, state, type) for each node
93
+ */
94
+ export function full<TState>(
95
+ node: acorn.Node,
96
+ callback: FullWalkerCallback<TState>,
97
+ base?: RecursiveVisitors<TState>,
98
+ state?: TState
99
+ ): void
100
+
101
+ /**
102
+ * does a 'full' walk over a tree, building up an array of ancestor nodes (including the current node) and passing the array to the callbacks as a third parameter.
103
+ */
104
+ export function fullAncestor<TState>(
105
+ node: acorn.Node,
106
+ callback: FullAncestorWalkerCallback<TState>,
107
+ base?: RecursiveVisitors<TState>,
108
+ state?: TState
109
+ ): void
110
+
111
+ /**
112
+ * builds a new walker object by using the walker functions in {@link functions} and filling in the missing ones by taking defaults from {@link base}.
113
+ */
114
+ export function make<TState>(
115
+ functions: RecursiveVisitors<TState>,
116
+ base?: RecursiveVisitors<TState>
117
+ ): RecursiveVisitors<TState>
118
+
119
+ /**
120
+ * tries to locate a node in a tree at the given start and/or end offsets, which satisfies the predicate test. {@link start} and {@link end} can be either `null` (as wildcard) or a `number`. {@link test} may be a string (indicating a node type) or a function that takes (nodeType, node) arguments and returns a boolean indicating whether this node is interesting. {@link base} and {@link state} are optional, and can be used to specify a custom walker. Nodes are tested from inner to outer, so if two nodes match the boundaries, the inner one will be preferred.
121
+ */
122
+ export function findNodeAt<TState>(
123
+ node: acorn.Node,
124
+ start: number | undefined | null,
125
+ end?: number | undefined | null,
126
+ type?: FindPredicate | string,
127
+ base?: RecursiveVisitors<TState>,
128
+ state?: TState
129
+ ): Found<TState> | undefined
130
+
131
+ /**
132
+ * like {@link findNodeAt}, but will match any node that exists 'around' (spanning) the given position.
133
+ */
134
+ export function findNodeAround<TState>(
135
+ node: acorn.Node,
136
+ start: number | undefined | null,
137
+ type?: FindPredicate | string,
138
+ base?: RecursiveVisitors<TState>,
139
+ state?: TState
140
+ ): Found<TState> | undefined
141
+
142
+ /**
143
+ * Find the outermost matching node after a given position.
144
+ */
145
+ export const findNodeAfter: typeof findNodeAround
146
+
147
+ /**
148
+ * Find the outermost matching node before a given position.
149
+ */
150
+ export const findNodeBefore: typeof findNodeAround
151
+
152
+ export const base: RecursiveVisitors<any>
@@ -0,0 +1,152 @@
1
+ import * as acorn from "acorn"
2
+
3
+ export type FullWalkerCallback<TState> = (
4
+ node: acorn.AnyNode,
5
+ state: TState,
6
+ type: string
7
+ ) => void
8
+
9
+ export type FullAncestorWalkerCallback<TState> = (
10
+ node: acorn.AnyNode,
11
+ state: TState,
12
+ ancestors: acorn.AnyNode[],
13
+ type: string
14
+ ) => void
15
+
16
+ type AggregateType = {
17
+ Expression: acorn.Expression,
18
+ Statement: acorn.Statement,
19
+ Function: acorn.Function,
20
+ Class: acorn.Class,
21
+ Pattern: acorn.Pattern,
22
+ ForInit: acorn.VariableDeclaration | acorn.Expression
23
+ }
24
+
25
+ export type SimpleVisitors<TState> = {
26
+ [type in acorn.AnyNode["type"]]?: (node: Extract<acorn.AnyNode, { type: type }>, state: TState) => void
27
+ } & {
28
+ [type in keyof AggregateType]?: (node: AggregateType[type], state: TState) => void
29
+ }
30
+
31
+ export type AncestorVisitors<TState> = {
32
+ [type in acorn.AnyNode["type"]]?: ( node: Extract<acorn.AnyNode, { type: type }>, state: TState, ancestors: acorn.AnyNode[]
33
+ ) => void
34
+ } & {
35
+ [type in keyof AggregateType]?: (node: AggregateType[type], state: TState, ancestors: acorn.AnyNode[]) => void
36
+ }
37
+
38
+ export type WalkerCallback<TState> = (node: acorn.AnyNode, state: TState) => void
39
+
40
+ export type RecursiveVisitors<TState> = {
41
+ [type in acorn.AnyNode["type"]]?: ( node: Extract<acorn.AnyNode, { type: type }>, state: TState, callback: WalkerCallback<TState>) => void
42
+ } & {
43
+ [type in keyof AggregateType]?: (node: AggregateType[type], state: TState, callback: WalkerCallback<TState>) => void
44
+ }
45
+
46
+ export type FindPredicate = (type: string, node: acorn.AnyNode) => boolean
47
+
48
+ export interface Found<TState> {
49
+ node: acorn.AnyNode,
50
+ state: TState
51
+ }
52
+
53
+ /**
54
+ * does a 'simple' walk over a tree
55
+ * @param node the AST node to walk
56
+ * @param visitors an object with properties whose names correspond to node types in the {@link https://github.com/estree/estree | ESTree spec}. The properties should contain functions that will be called with the node object and, if applicable the state at that point.
57
+ * @param base a walker algorithm
58
+ * @param state a start state. The default walker will simply visit all statements and expressions and not produce a meaningful state. (An example of a use of state is to track scope at each point in the tree.)
59
+ */
60
+ export function simple<TState>(
61
+ node: acorn.Node,
62
+ visitors: SimpleVisitors<TState>,
63
+ base?: RecursiveVisitors<TState>,
64
+ state?: TState
65
+ ): void
66
+
67
+ /**
68
+ * does a 'simple' walk over a tree, building up an array of ancestor nodes (including the current node) and passing the array to the callbacks as a third parameter.
69
+ */
70
+ export function ancestor<TState>(
71
+ node: acorn.Node,
72
+ visitors: AncestorVisitors<TState>,
73
+ base?: RecursiveVisitors<TState>,
74
+ state?: TState
75
+ ): void
76
+
77
+ /**
78
+ * does a 'recursive' walk, where the walker functions are responsible for continuing the walk on the child nodes of their target node.
79
+ * @param node
80
+ * @param state the start state
81
+ * @param functions contain an object that maps node types to walker functions
82
+ * @param base provides the fallback walker functions for node types that aren't handled in the {@link functions} object. If not given, the default walkers will be used.
83
+ */
84
+ export function recursive<TState>(
85
+ node: acorn.Node,
86
+ state: TState,
87
+ functions: RecursiveVisitors<TState>,
88
+ base?: RecursiveVisitors<TState>
89
+ ): void
90
+
91
+ /**
92
+ * does a 'full' walk over a tree, calling the {@link callback} with the arguments (node, state, type) for each node
93
+ */
94
+ export function full<TState>(
95
+ node: acorn.Node,
96
+ callback: FullWalkerCallback<TState>,
97
+ base?: RecursiveVisitors<TState>,
98
+ state?: TState
99
+ ): void
100
+
101
+ /**
102
+ * does a 'full' walk over a tree, building up an array of ancestor nodes (including the current node) and passing the array to the callbacks as a third parameter.
103
+ */
104
+ export function fullAncestor<TState>(
105
+ node: acorn.Node,
106
+ callback: FullAncestorWalkerCallback<TState>,
107
+ base?: RecursiveVisitors<TState>,
108
+ state?: TState
109
+ ): void
110
+
111
+ /**
112
+ * builds a new walker object by using the walker functions in {@link functions} and filling in the missing ones by taking defaults from {@link base}.
113
+ */
114
+ export function make<TState>(
115
+ functions: RecursiveVisitors<TState>,
116
+ base?: RecursiveVisitors<TState>
117
+ ): RecursiveVisitors<TState>
118
+
119
+ /**
120
+ * tries to locate a node in a tree at the given start and/or end offsets, which satisfies the predicate test. {@link start} and {@link end} can be either `null` (as wildcard) or a `number`. {@link test} may be a string (indicating a node type) or a function that takes (nodeType, node) arguments and returns a boolean indicating whether this node is interesting. {@link base} and {@link state} are optional, and can be used to specify a custom walker. Nodes are tested from inner to outer, so if two nodes match the boundaries, the inner one will be preferred.
121
+ */
122
+ export function findNodeAt<TState>(
123
+ node: acorn.Node,
124
+ start: number | undefined | null,
125
+ end?: number | undefined | null,
126
+ type?: FindPredicate | string,
127
+ base?: RecursiveVisitors<TState>,
128
+ state?: TState
129
+ ): Found<TState> | undefined
130
+
131
+ /**
132
+ * like {@link findNodeAt}, but will match any node that exists 'around' (spanning) the given position.
133
+ */
134
+ export function findNodeAround<TState>(
135
+ node: acorn.Node,
136
+ start: number | undefined | null,
137
+ type?: FindPredicate | string,
138
+ base?: RecursiveVisitors<TState>,
139
+ state?: TState
140
+ ): Found<TState> | undefined
141
+
142
+ /**
143
+ * Find the outermost matching node after a given position.
144
+ */
145
+ export const findNodeAfter: typeof findNodeAround
146
+
147
+ /**
148
+ * Find the outermost matching node before a given position.
149
+ */
150
+ export const findNodeBefore: typeof findNodeAround
151
+
152
+ export const base: RecursiveVisitors<any>