@danielblomma/cortex-mcp 1.3.1 → 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.
- package/README.md +62 -14
- package/package.json +2 -2
- package/scaffold/mcp/package-lock.json +3 -7
- package/scaffold/mcp/package.json +1 -1
- package/scaffold/scripts/dashboard.mjs +15 -1
- package/scaffold/scripts/doctor.sh +64 -10
- package/scaffold/scripts/ingest.mjs +323 -50
- package/scaffold/scripts/parsers/bash-treesitter.mjs +229 -0
- package/scaffold/scripts/parsers/cpp-dispatch.mjs +56 -0
- package/scaffold/scripts/parsers/cpp-treesitter.mjs +333 -0
- package/scaffold/scripts/parsers/csharp.mjs +197 -10
- package/scaffold/scripts/parsers/dotnet/CSharpParser/CSharpParser.csproj +1 -0
- package/scaffold/scripts/parsers/dotnet/CSharpParser/Program.cs +126 -21
- package/scaffold/scripts/parsers/go-treesitter.mjs +283 -0
- package/scaffold/scripts/parsers/java-treesitter.mjs +250 -0
- package/scaffold/scripts/parsers/javascript/ast.mjs +118 -12
- package/scaffold/scripts/parsers/javascript/chunks.mjs +4 -0
- package/scaffold/scripts/parsers/javascript/patterns.mjs +6 -0
- package/scaffold/scripts/parsers/javascript.mjs +4 -19
- package/scaffold/scripts/parsers/node_modules/.package-lock.json +57 -0
- package/scaffold/scripts/parsers/node_modules/acorn/CHANGELOG.md +972 -0
- package/scaffold/scripts/parsers/node_modules/acorn/LICENSE +21 -0
- package/scaffold/scripts/parsers/node_modules/acorn/README.md +301 -0
- package/scaffold/scripts/parsers/node_modules/acorn/bin/acorn +4 -0
- package/scaffold/scripts/parsers/node_modules/acorn/dist/acorn.d.mts +883 -0
- package/scaffold/scripts/parsers/node_modules/acorn/dist/acorn.d.ts +883 -0
- package/scaffold/scripts/parsers/node_modules/acorn/dist/acorn.js +6295 -0
- package/scaffold/scripts/parsers/node_modules/acorn/dist/acorn.mjs +6266 -0
- package/scaffold/scripts/parsers/node_modules/acorn/dist/bin.js +90 -0
- package/scaffold/scripts/parsers/node_modules/acorn/package.json +50 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/CHANGELOG.md +421 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/LICENSE +21 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/README.md +81 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/error.d.ts +103 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/error.js +78 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/error.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/decorators.d.ts +167 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/decorators.js +75 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/decorators.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/import-assertions.d.ts +177 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/import-assertions.js +56 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/import-assertions.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/index.d.ts +198 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/index.js +327 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/index.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/xhtml.d.ts +256 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/xhtml.js +256 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/extentions/jsx/xhtml.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/index.d.ts +472 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/index.js +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/index.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/index.mjs +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/middleware.d.ts +159 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/middleware.js +2 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/middleware.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/parseutil.d.ts +10 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/parseutil.js +38 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/parseutil.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/scopeflags.d.ts +12 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/scopeflags.js +29 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/scopeflags.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/tokenType.d.ts +2 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/tokenType.js +118 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/tokenType.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/types.d.ts +60 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/types.js +2 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/types.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/whitespace.d.ts +2 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/whitespace.js +19 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/lib/whitespace.js.map +1 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/package.json +53 -0
- package/scaffold/scripts/parsers/node_modules/acorn-typescript/tsconfig.json +19 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/CHANGELOG.md +209 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/LICENSE +21 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/README.md +124 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/dist/walk.d.mts +152 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/dist/walk.d.ts +152 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/dist/walk.js +485 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/dist/walk.mjs +467 -0
- package/scaffold/scripts/parsers/node_modules/acorn-walk/package.json +50 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/LICENSE +24 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/README.md +23 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-bash.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-c.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-c_sharp.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-cpp.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-css.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-dart.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-elisp.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-elixir.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-elm.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-embedded_template.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-go.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-html.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-java.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-javascript.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-json.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-kotlin.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-lua.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-objc.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-ocaml.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-php.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-python.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-ql.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-rescript.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-ruby.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-rust.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-scala.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-solidity.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-swift.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-systemrdl.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-tlaplus.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-toml.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-tsx.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-typescript.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-vue.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-yaml.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/out/tree-sitter-zig.wasm +0 -0
- package/scaffold/scripts/parsers/node_modules/tree-sitter-wasms/package.json +64 -0
- package/scaffold/scripts/parsers/node_modules/web-tree-sitter/LICENSE +21 -0
- package/scaffold/scripts/parsers/node_modules/web-tree-sitter/README.md +198 -0
- package/scaffold/scripts/parsers/node_modules/web-tree-sitter/package.json +37 -0
- package/scaffold/scripts/parsers/node_modules/web-tree-sitter/tree-sitter-web.d.ts +242 -0
- package/scaffold/scripts/parsers/node_modules/web-tree-sitter/tree-sitter.js +1 -0
- package/scaffold/scripts/parsers/node_modules/web-tree-sitter/tree-sitter.wasm +0 -0
- package/scaffold/scripts/parsers/package-lock.json +19 -1
- package/scaffold/scripts/parsers/package.json +3 -1
- package/scaffold/scripts/parsers/python-treesitter.mjs +271 -0
- package/scaffold/scripts/parsers/ruby-treesitter.mjs +271 -0
- package/scaffold/scripts/parsers/rust-dispatch.mjs +43 -0
- package/scaffold/scripts/parsers/rust-treesitter.mjs +291 -0
- package/scaffold/scripts/parsers/tree-sitter/base.mjs +163 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/bash.calls.scm +7 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/bash.chunks.scm +6 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/bash.imports.scm +5 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/cpp.calls.scm +17 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/cpp.chunks.scm +30 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/cpp.imports.scm +6 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/go.calls.scm +11 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/go.chunks.scm +19 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/go.imports.scm +6 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/java.calls.scm +6 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/java.chunks.scm +23 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/java.imports.scm +6 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/python.calls.scm +11 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/python.chunks.scm +11 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/python.imports.scm +13 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/ruby.calls.scm +6 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/ruby.chunks.scm +16 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/ruby.imports.scm +8 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/rust.calls.scm +31 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/rust.chunks.scm +29 -0
- package/scaffold/scripts/parsers/tree-sitter/queries/rust.imports.scm +5 -0
- 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>
|