ghagga-core 2.6.0 → 2.8.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/dist/agents/consensus.d.ts +2 -0
- package/dist/agents/consensus.d.ts.map +1 -1
- package/dist/agents/consensus.js +1 -0
- package/dist/agents/consensus.js.map +1 -1
- package/dist/agents/diagnostic.d.ts +2 -0
- package/dist/agents/diagnostic.d.ts.map +1 -1
- package/dist/agents/diagnostic.js +1 -0
- package/dist/agents/diagnostic.js.map +1 -1
- package/dist/agents/fan-out-lenses.d.ts +92 -0
- package/dist/agents/fan-out-lenses.d.ts.map +1 -0
- package/dist/agents/fan-out-lenses.js +424 -0
- package/dist/agents/fan-out-lenses.js.map +1 -0
- package/dist/agents/simple.d.ts +2 -0
- package/dist/agents/simple.d.ts.map +1 -1
- package/dist/agents/simple.js +1 -0
- package/dist/agents/simple.js.map +1 -1
- package/dist/agents/workflow.d.ts +2 -0
- package/dist/agents/workflow.d.ts.map +1 -1
- package/dist/agents/workflow.js +2 -1
- package/dist/agents/workflow.js.map +1 -1
- package/dist/checklist/config.d.ts +22 -0
- package/dist/checklist/config.d.ts.map +1 -0
- package/dist/checklist/config.js +85 -0
- package/dist/checklist/config.js.map +1 -0
- package/dist/checklist/context.d.ts +22 -0
- package/dist/checklist/context.d.ts.map +1 -0
- package/dist/checklist/context.js +76 -0
- package/dist/checklist/context.js.map +1 -0
- package/dist/checklist/defaults.d.ts +12 -0
- package/dist/checklist/defaults.d.ts.map +1 -0
- package/dist/checklist/defaults.js +172 -0
- package/dist/checklist/defaults.js.map +1 -0
- package/dist/checklist/index.d.ts +14 -0
- package/dist/checklist/index.d.ts.map +1 -0
- package/dist/checklist/index.js +15 -0
- package/dist/checklist/index.js.map +1 -0
- package/dist/checklist/scorer.d.ts +58 -0
- package/dist/checklist/scorer.d.ts.map +1 -0
- package/dist/checklist/scorer.js +142 -0
- package/dist/checklist/scorer.js.map +1 -0
- package/dist/checklist/types.d.ts +39 -0
- package/dist/checklist/types.d.ts.map +1 -0
- package/dist/checklist/types.js +17 -0
- package/dist/checklist/types.js.map +1 -0
- package/dist/exploitability/analyzer.d.ts +75 -0
- package/dist/exploitability/analyzer.d.ts.map +1 -0
- package/dist/exploitability/analyzer.js +299 -0
- package/dist/exploitability/analyzer.js.map +1 -0
- package/dist/exploitability/index.d.ts +10 -0
- package/dist/exploitability/index.d.ts.map +1 -0
- package/dist/exploitability/index.js +10 -0
- package/dist/exploitability/index.js.map +1 -0
- package/dist/exploitability/types.d.ts +32 -0
- package/dist/exploitability/types.d.ts.map +1 -0
- package/dist/exploitability/types.js +9 -0
- package/dist/exploitability/types.js.map +1 -0
- package/dist/index.d.ts +15 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/index.js.map +1 -1
- package/dist/memory/context.d.ts +2 -0
- package/dist/memory/context.d.ts.map +1 -1
- package/dist/memory/context.js +2 -1
- package/dist/memory/context.js.map +1 -1
- package/dist/memory/contradiction.d.ts +46 -0
- package/dist/memory/contradiction.d.ts.map +1 -0
- package/dist/memory/contradiction.js +110 -0
- package/dist/memory/contradiction.js.map +1 -0
- package/dist/memory/decay.d.ts +25 -0
- package/dist/memory/decay.d.ts.map +1 -0
- package/dist/memory/decay.js +51 -0
- package/dist/memory/decay.js.map +1 -0
- package/dist/memory/search.d.ts.map +1 -1
- package/dist/memory/search.js +1 -0
- package/dist/memory/search.js.map +1 -1
- package/dist/memory/sqlite.d.ts +21 -0
- package/dist/memory/sqlite.d.ts.map +1 -1
- package/dist/memory/sqlite.js +82 -7
- package/dist/memory/sqlite.js.map +1 -1
- package/dist/memory/versioning.d.ts +94 -0
- package/dist/memory/versioning.d.ts.map +1 -0
- package/dist/memory/versioning.js +350 -0
- package/dist/memory/versioning.js.map +1 -0
- package/dist/pipeline.d.ts.map +1 -1
- package/dist/pipeline.js +117 -0
- package/dist/pipeline.js.map +1 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +7 -2
- package/dist/providers/index.js.map +1 -1
- package/dist/recursive/index.d.ts +45 -0
- package/dist/recursive/index.d.ts.map +1 -0
- package/dist/recursive/index.js +159 -0
- package/dist/recursive/index.js.map +1 -0
- package/dist/recursive/patch-extractor.d.ts +49 -0
- package/dist/recursive/patch-extractor.d.ts.map +1 -0
- package/dist/recursive/patch-extractor.js +133 -0
- package/dist/recursive/patch-extractor.js.map +1 -0
- package/dist/recursive/re-reviewer.d.ts +31 -0
- package/dist/recursive/re-reviewer.d.ts.map +1 -0
- package/dist/recursive/re-reviewer.js +66 -0
- package/dist/recursive/re-reviewer.js.map +1 -0
- package/dist/recursive/types.d.ts +62 -0
- package/dist/recursive/types.d.ts.map +1 -0
- package/dist/recursive/types.js +11 -0
- package/dist/recursive/types.js.map +1 -0
- package/dist/scope/context-builder.d.ts +37 -0
- package/dist/scope/context-builder.d.ts.map +1 -0
- package/dist/scope/context-builder.js +108 -0
- package/dist/scope/context-builder.js.map +1 -0
- package/dist/scope/diff-mapper.d.ts +29 -0
- package/dist/scope/diff-mapper.d.ts.map +1 -0
- package/dist/scope/diff-mapper.js +76 -0
- package/dist/scope/diff-mapper.js.map +1 -0
- package/dist/scope/extractor.d.ts +25 -0
- package/dist/scope/extractor.d.ts.map +1 -0
- package/dist/scope/extractor.js +264 -0
- package/dist/scope/extractor.js.map +1 -0
- package/dist/scope/index.d.ts +13 -0
- package/dist/scope/index.d.ts.map +1 -0
- package/dist/scope/index.js +16 -0
- package/dist/scope/index.js.map +1 -0
- package/dist/scope/parser.d.ts +47 -0
- package/dist/scope/parser.d.ts.map +1 -0
- package/dist/scope/parser.js +97 -0
- package/dist/scope/parser.js.map +1 -0
- package/dist/scope/queries.d.ts +23 -0
- package/dist/scope/queries.d.ts.map +1 -0
- package/dist/scope/queries.js +134 -0
- package/dist/scope/queries.js.map +1 -0
- package/dist/scope/types.d.ts +55 -0
- package/dist/scope/types.d.ts.map +1 -0
- package/dist/scope/types.js +8 -0
- package/dist/scope/types.js.map +1 -0
- package/dist/tools/execution.d.ts.map +1 -1
- package/dist/tools/execution.js +2 -0
- package/dist/tools/execution.js.map +1 -1
- package/dist/tools/plugins/index.d.ts +1 -0
- package/dist/tools/plugins/index.d.ts.map +1 -1
- package/dist/tools/plugins/index.js +6 -5
- package/dist/tools/plugins/index.js.map +1 -1
- package/dist/tools/plugins/sonarqube.d.ts +54 -0
- package/dist/tools/plugins/sonarqube.d.ts.map +1 -0
- package/dist/tools/plugins/sonarqube.js +145 -0
- package/dist/tools/plugins/sonarqube.js.map +1 -0
- package/dist/tools/plugins/trivy.js +1 -1
- package/dist/tools/plugins/trivy.js.map +1 -1
- package/dist/tools/types.d.ts +7 -1
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/types.d.ts +80 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symbol Extractor
|
|
3
|
+
*
|
|
4
|
+
* Extracts symbol definitions (functions, classes, methods, interfaces)
|
|
5
|
+
* from source code using tree-sitter AST walking.
|
|
6
|
+
*
|
|
7
|
+
* Uses cursor-based traversal instead of S-expression queries for
|
|
8
|
+
* maximum compatibility across grammar versions.
|
|
9
|
+
*
|
|
10
|
+
* Pure function signature: (source, language, tree) => SymbolInfo[]
|
|
11
|
+
*/
|
|
12
|
+
const NODE_CONFIGS = {
|
|
13
|
+
typescript: {
|
|
14
|
+
functions: ['function_declaration', 'arrow_function'],
|
|
15
|
+
classes: ['class_declaration'],
|
|
16
|
+
methods: ['method_definition'],
|
|
17
|
+
interfaces: ['interface_declaration'],
|
|
18
|
+
nameField: 'name',
|
|
19
|
+
methodNameField: 'name',
|
|
20
|
+
bodyField: 'body',
|
|
21
|
+
},
|
|
22
|
+
javascript: {
|
|
23
|
+
functions: ['function_declaration', 'arrow_function'],
|
|
24
|
+
classes: ['class_declaration'],
|
|
25
|
+
methods: ['method_definition'],
|
|
26
|
+
interfaces: [],
|
|
27
|
+
nameField: 'name',
|
|
28
|
+
methodNameField: 'name',
|
|
29
|
+
bodyField: 'body',
|
|
30
|
+
},
|
|
31
|
+
python: {
|
|
32
|
+
functions: ['function_definition'],
|
|
33
|
+
classes: ['class_definition'],
|
|
34
|
+
methods: ['function_definition'], // methods are function_definition inside class
|
|
35
|
+
interfaces: [],
|
|
36
|
+
nameField: 'name',
|
|
37
|
+
methodNameField: 'name',
|
|
38
|
+
bodyField: 'body',
|
|
39
|
+
},
|
|
40
|
+
go: {
|
|
41
|
+
functions: ['function_declaration'],
|
|
42
|
+
classes: ['type_declaration'], // struct type
|
|
43
|
+
methods: ['method_declaration'],
|
|
44
|
+
interfaces: ['type_declaration'], // interface type
|
|
45
|
+
nameField: 'name',
|
|
46
|
+
methodNameField: 'name',
|
|
47
|
+
bodyField: 'body',
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
// ─── Extractor ─────────────────────────────────────────────────
|
|
51
|
+
/**
|
|
52
|
+
* Extract symbol definitions from a parsed tree-sitter tree.
|
|
53
|
+
*
|
|
54
|
+
* Walks the AST using a cursor and identifies functions, classes,
|
|
55
|
+
* methods, and interfaces based on language-specific node types.
|
|
56
|
+
*
|
|
57
|
+
* @param tree - Parsed tree-sitter tree
|
|
58
|
+
* @param language - The scope language
|
|
59
|
+
* @returns Array of extracted symbols
|
|
60
|
+
*/
|
|
61
|
+
export function extractSymbolsFromTree(tree, language) {
|
|
62
|
+
const config = NODE_CONFIGS[language];
|
|
63
|
+
if (!config)
|
|
64
|
+
return [];
|
|
65
|
+
const symbols = [];
|
|
66
|
+
if (language === 'go') {
|
|
67
|
+
extractGoSymbols(tree.rootNode, config, symbols);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
extractGenericSymbols(tree.rootNode, config, language, symbols, undefined);
|
|
71
|
+
}
|
|
72
|
+
return symbols;
|
|
73
|
+
}
|
|
74
|
+
// ─── Generic Extraction (TS/JS/Python) ─────────────────────────
|
|
75
|
+
function extractGenericSymbols(node, config, language, symbols, parentClassName) {
|
|
76
|
+
const nodeType = node.type;
|
|
77
|
+
// Check if this is a function
|
|
78
|
+
if (config.functions.includes(nodeType) && !parentClassName) {
|
|
79
|
+
const name = extractName(node, config.nameField, language);
|
|
80
|
+
if (name) {
|
|
81
|
+
symbols.push(buildSymbol(name, 'function', node));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Check if this is a class
|
|
85
|
+
if (config.classes.includes(nodeType)) {
|
|
86
|
+
const name = extractName(node, config.nameField, language);
|
|
87
|
+
if (name) {
|
|
88
|
+
symbols.push(buildSymbol(name, 'class', node));
|
|
89
|
+
// Walk children to find methods
|
|
90
|
+
const body = node.childForFieldName(config.bodyField ?? 'body');
|
|
91
|
+
if (body) {
|
|
92
|
+
for (let i = 0; i < body.childCount; i++) {
|
|
93
|
+
const child = body.child(i);
|
|
94
|
+
if (child) {
|
|
95
|
+
extractMethodsFromClassBody(child, config, language, symbols, name);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return; // Don't recurse into class children again
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Check if this is an interface (TS only)
|
|
103
|
+
if (config.interfaces.includes(nodeType)) {
|
|
104
|
+
const name = extractName(node, config.nameField, language);
|
|
105
|
+
if (name) {
|
|
106
|
+
symbols.push(buildSymbol(name, 'interface', node));
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// Check for arrow function assigned to variable (TS/JS)
|
|
111
|
+
if ((language === 'typescript' || language === 'javascript') &&
|
|
112
|
+
(nodeType === 'lexical_declaration' || nodeType === 'variable_declaration')) {
|
|
113
|
+
extractArrowFunctionVariable(node, symbols);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
// Check for exported declarations (TS/JS)
|
|
117
|
+
if (nodeType === 'export_statement') {
|
|
118
|
+
const declaration = node.childForFieldName('declaration');
|
|
119
|
+
if (declaration) {
|
|
120
|
+
extractGenericSymbols(declaration, config, language, symbols, parentClassName);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Python: method inside class is function_definition with parent context
|
|
125
|
+
if (language === 'python' && parentClassName && nodeType === 'function_definition') {
|
|
126
|
+
const name = extractName(node, config.nameField, language);
|
|
127
|
+
if (name) {
|
|
128
|
+
symbols.push(buildSymbol(name, 'method', node, parentClassName));
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// Recurse into children
|
|
133
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
134
|
+
const child = node.child(i);
|
|
135
|
+
if (child) {
|
|
136
|
+
extractGenericSymbols(child, config, language, symbols, parentClassName);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function extractMethodsFromClassBody(node, config, language, symbols, className) {
|
|
141
|
+
if (config.methods.includes(node.type)) {
|
|
142
|
+
const name = extractName(node, config.methodNameField ?? config.nameField, language);
|
|
143
|
+
if (name) {
|
|
144
|
+
symbols.push(buildSymbol(name, 'method', node, className));
|
|
145
|
+
}
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
// Python: methods are function_definition inside class body block
|
|
149
|
+
if (language === 'python' && node.type === 'function_definition') {
|
|
150
|
+
const name = extractName(node, config.nameField, language);
|
|
151
|
+
if (name) {
|
|
152
|
+
symbols.push(buildSymbol(name, 'method', node, className));
|
|
153
|
+
}
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
// Recurse for nested blocks (Python class body has a block node)
|
|
157
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
158
|
+
const child = node.child(i);
|
|
159
|
+
if (child) {
|
|
160
|
+
extractMethodsFromClassBody(child, config, language, symbols, className);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function extractArrowFunctionVariable(node, symbols) {
|
|
165
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
166
|
+
const declarator = node.child(i);
|
|
167
|
+
if (declarator?.type === 'variable_declarator') {
|
|
168
|
+
const nameNode = declarator.childForFieldName('name');
|
|
169
|
+
const valueNode = declarator.childForFieldName('value');
|
|
170
|
+
if (nameNode && valueNode?.type === 'arrow_function') {
|
|
171
|
+
// Use the full declaration node for ranges (includes const/let)
|
|
172
|
+
symbols.push(buildSymbol(nameNode.text, 'function', node));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
// ─── Go Extraction ─────────────────────────────────────────────
|
|
178
|
+
function extractGoSymbols(node, config, symbols) {
|
|
179
|
+
const nodeType = node.type;
|
|
180
|
+
if (nodeType === 'function_declaration') {
|
|
181
|
+
const name = node.childForFieldName('name');
|
|
182
|
+
if (name) {
|
|
183
|
+
symbols.push(buildSymbol(name.text, 'function', node));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
else if (nodeType === 'method_declaration') {
|
|
187
|
+
const name = node.childForFieldName('name');
|
|
188
|
+
const receiver = node.childForFieldName('receiver');
|
|
189
|
+
let parentName;
|
|
190
|
+
if (receiver) {
|
|
191
|
+
// Extract receiver type: (s *Svc) or (s Svc)
|
|
192
|
+
parentName = extractGoReceiverType(receiver);
|
|
193
|
+
}
|
|
194
|
+
if (name) {
|
|
195
|
+
symbols.push(buildSymbol(name.text, 'method', node, parentName));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else if (nodeType === 'type_declaration') {
|
|
199
|
+
// Go type declarations contain type_spec children
|
|
200
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
201
|
+
const child = node.child(i);
|
|
202
|
+
if (child?.type === 'type_spec') {
|
|
203
|
+
const nameNode = child.childForFieldName('name');
|
|
204
|
+
const typeNode = child.childForFieldName('type');
|
|
205
|
+
if (nameNode && typeNode) {
|
|
206
|
+
const kind = typeNode.type === 'interface_type' ? 'interface' : 'class';
|
|
207
|
+
symbols.push(buildSymbol(nameNode.text, kind, node));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
// Recurse into children (skip already-processed node types to avoid duplication)
|
|
213
|
+
if (nodeType !== 'function_declaration' &&
|
|
214
|
+
nodeType !== 'method_declaration' &&
|
|
215
|
+
nodeType !== 'type_declaration') {
|
|
216
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
217
|
+
const child = node.child(i);
|
|
218
|
+
if (child) {
|
|
219
|
+
extractGoSymbols(child, config, symbols);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function extractGoReceiverType(receiver) {
|
|
225
|
+
// parameter_list > parameter_declaration > type (pointer_type > type_identifier | type_identifier)
|
|
226
|
+
for (let i = 0; i < receiver.childCount; i++) {
|
|
227
|
+
const param = receiver.child(i);
|
|
228
|
+
if (param?.type === 'parameter_declaration') {
|
|
229
|
+
const typeNode = param.childForFieldName('type');
|
|
230
|
+
if (typeNode) {
|
|
231
|
+
if (typeNode.type === 'pointer_type') {
|
|
232
|
+
// *Svc → extract Svc
|
|
233
|
+
for (let j = 0; j < typeNode.childCount; j++) {
|
|
234
|
+
const inner = typeNode.child(j);
|
|
235
|
+
if (inner?.type === 'type_identifier')
|
|
236
|
+
return inner.text;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
else if (typeNode.type === 'type_identifier') {
|
|
240
|
+
return typeNode.text;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
// ─── Helpers ───────────────────────────────────────────────────
|
|
248
|
+
function extractName(node, fieldName, _language) {
|
|
249
|
+
const nameNode = node.childForFieldName(fieldName);
|
|
250
|
+
return nameNode?.text;
|
|
251
|
+
}
|
|
252
|
+
function buildSymbol(name, kind, node, parent) {
|
|
253
|
+
return {
|
|
254
|
+
name,
|
|
255
|
+
kind,
|
|
256
|
+
// tree-sitter uses 0-based rows, we use 1-based lines
|
|
257
|
+
startLine: node.startPosition.row + 1,
|
|
258
|
+
endLine: node.endPosition.row + 1,
|
|
259
|
+
startByte: node.startIndex,
|
|
260
|
+
endByte: node.endIndex,
|
|
261
|
+
...(parent ? { parent } : {}),
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
//# sourceMappingURL=extractor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../src/scope/extractor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAyBH,MAAM,YAAY,GAA4C;IAC5D,UAAU,EAAE;QACV,SAAS,EAAE,CAAC,sBAAsB,EAAE,gBAAgB,CAAC;QACrD,OAAO,EAAE,CAAC,mBAAmB,CAAC;QAC9B,OAAO,EAAE,CAAC,mBAAmB,CAAC;QAC9B,UAAU,EAAE,CAAC,uBAAuB,CAAC;QACrC,SAAS,EAAE,MAAM;QACjB,eAAe,EAAE,MAAM;QACvB,SAAS,EAAE,MAAM;KAClB;IACD,UAAU,EAAE;QACV,SAAS,EAAE,CAAC,sBAAsB,EAAE,gBAAgB,CAAC;QACrD,OAAO,EAAE,CAAC,mBAAmB,CAAC;QAC9B,OAAO,EAAE,CAAC,mBAAmB,CAAC;QAC9B,UAAU,EAAE,EAAE;QACd,SAAS,EAAE,MAAM;QACjB,eAAe,EAAE,MAAM;QACvB,SAAS,EAAE,MAAM;KAClB;IACD,MAAM,EAAE;QACN,SAAS,EAAE,CAAC,qBAAqB,CAAC;QAClC,OAAO,EAAE,CAAC,kBAAkB,CAAC;QAC7B,OAAO,EAAE,CAAC,qBAAqB,CAAC,EAAE,+CAA+C;QACjF,UAAU,EAAE,EAAE;QACd,SAAS,EAAE,MAAM;QACjB,eAAe,EAAE,MAAM;QACvB,SAAS,EAAE,MAAM;KAClB;IACD,EAAE,EAAE;QACF,SAAS,EAAE,CAAC,sBAAsB,CAAC;QACnC,O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J,sDAAsD;QACtD,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,GAAG,GAAG,CAAC;QACrC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,GAAG,GAAG,CAAC;QACjC,SAAS,EAAE,IAAI,CAAC,UAAU;QAC1B,OAAO,EAAE,IAAI,CAAC,QAAQ;QACtB,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC9B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scope module barrel export.
|
|
3
|
+
*
|
|
4
|
+
* Tree-sitter based symbol-level scoping for code reviews.
|
|
5
|
+
* Extracts symbol definitions, maps diff changes to affected symbols,
|
|
6
|
+
* and builds focused review context.
|
|
7
|
+
*/
|
|
8
|
+
export type { AffectedSymbol, DiffHunk, ScopeLanguage, ScopedFile, SymbolInfo, SymbolKind, } from './types.js';
|
|
9
|
+
export { buildScopedContext } from './context-builder.js';
|
|
10
|
+
export { mapDiffToSymbols, parseHunks } from './diff-mapper.js';
|
|
11
|
+
export { extractSymbolsFromTree } from './extractor.js';
|
|
12
|
+
export { initParser, loadLanguage, parseSource, resetParser, resolveGrammarPath, } from './parser.js';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scope/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,YAAY,EACV,cAAc,EACd,QAAQ,EACR,aAAa,EACb,UAAU,EACV,UAAU,EACV,UAAU,GACX,MAAM,YAAY,CAAC;AAIpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAI1D,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAIhE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAIxD,OAAO,EACL,UAAU,EACV,YAAY,EACZ,WAAW,EACX,WAAW,EACX,kBAAkB,GACnB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scope module barrel export.
|
|
3
|
+
*
|
|
4
|
+
* Tree-sitter based symbol-level scoping for code reviews.
|
|
5
|
+
* Extracts symbol definitions, maps diff changes to affected symbols,
|
|
6
|
+
* and builds focused review context.
|
|
7
|
+
*/
|
|
8
|
+
// ─── Context Builder ───────────────────────────────────────────
|
|
9
|
+
export { buildScopedContext } from './context-builder.js';
|
|
10
|
+
// ─── Diff Mapper ───────────────────────────────────────────────
|
|
11
|
+
export { mapDiffToSymbols, parseHunks } from './diff-mapper.js';
|
|
12
|
+
// ─── Symbol Extractor ──────────────────────────────────────────
|
|
13
|
+
export { extractSymbolsFromTree } from './extractor.js';
|
|
14
|
+
// ─── Parser ────────────────────────────────────────────────────
|
|
15
|
+
export { initParser, loadLanguage, parseSource, resetParser, resolveGrammarPath, } from './parser.js';
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/scope/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAaH,kEAAkE;AAElE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,kEAAkE;AAElE,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEhE,kEAAkE;AAElE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAExD,kEAAkE;AAElE,OAAO,EACL,UAAU,EACV,YAAY,EACZ,WAAW,EACX,WAAW,EACX,kBAAkB,GACnB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree-sitter Parser
|
|
3
|
+
*
|
|
4
|
+
* Initializes the web-tree-sitter WASM runtime and provides
|
|
5
|
+
* functions to parse source code and walk the AST.
|
|
6
|
+
*
|
|
7
|
+
* The parser is lazily initialized on first use and cached
|
|
8
|
+
* for subsequent calls. WASM grammars are loaded from the
|
|
9
|
+
* `tree-sitter-wasms` package.
|
|
10
|
+
*/
|
|
11
|
+
import { Language } from 'web-tree-sitter';
|
|
12
|
+
import type { Tree } from 'web-tree-sitter';
|
|
13
|
+
import type { ScopeLanguage } from './types.js';
|
|
14
|
+
/**
|
|
15
|
+
* Initialize the tree-sitter WASM runtime.
|
|
16
|
+
* Safe to call multiple times — only initializes once.
|
|
17
|
+
*/
|
|
18
|
+
export declare function initParser(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Load a tree-sitter language grammar from a WASM file.
|
|
21
|
+
* Caches loaded grammars for reuse.
|
|
22
|
+
*
|
|
23
|
+
* @param wasmPath - Absolute path to the .wasm grammar file
|
|
24
|
+
* @returns The loaded Language object
|
|
25
|
+
*/
|
|
26
|
+
export declare function loadLanguage(wasmPath: string): Promise<Language>;
|
|
27
|
+
/**
|
|
28
|
+
* Parse source code into a tree-sitter syntax tree.
|
|
29
|
+
*
|
|
30
|
+
* @param source - The source code string
|
|
31
|
+
* @param language - The loaded tree-sitter Language
|
|
32
|
+
* @returns The parsed Tree (caller must call tree.delete() when done)
|
|
33
|
+
*/
|
|
34
|
+
export declare function parseSource(source: string, language: Language): Tree;
|
|
35
|
+
/**
|
|
36
|
+
* Resolve the WASM file path for a language grammar.
|
|
37
|
+
* Uses the `tree-sitter-wasms` package which bundles prebuilt grammars.
|
|
38
|
+
*
|
|
39
|
+
* @param language - The scope language
|
|
40
|
+
* @returns Path to the .wasm file, or undefined if not found
|
|
41
|
+
*/
|
|
42
|
+
export declare function resolveGrammarPath(language: ScopeLanguage): string | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Reset parser state. Used in tests to ensure clean initialization.
|
|
45
|
+
*/
|
|
46
|
+
export declare function resetParser(): void;
|
|
47
|
+
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/scope/parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EAAE,QAAQ,EAAU,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAWhD;;;GAGG;AACH,wBAAsB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAIhD;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAQtE;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,CASpE;AAYD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,aAAa,GAAG,MAAM,GAAG,SAAS,CAW9E;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAGlC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree-sitter Parser
|
|
3
|
+
*
|
|
4
|
+
* Initializes the web-tree-sitter WASM runtime and provides
|
|
5
|
+
* functions to parse source code and walk the AST.
|
|
6
|
+
*
|
|
7
|
+
* The parser is lazily initialized on first use and cached
|
|
8
|
+
* for subsequent calls. WASM grammars are loaded from the
|
|
9
|
+
* `tree-sitter-wasms` package.
|
|
10
|
+
*/
|
|
11
|
+
import { createRequire } from 'node:module';
|
|
12
|
+
import { resolve } from 'node:path';
|
|
13
|
+
import { Language, Parser } from 'web-tree-sitter';
|
|
14
|
+
const require = createRequire(import.meta.url);
|
|
15
|
+
// ─── State ─────────────────────────────────────────────────────
|
|
16
|
+
let initialized = false;
|
|
17
|
+
const languageCache = new Map();
|
|
18
|
+
// ─── Initialization ────────────────────────────────────────────
|
|
19
|
+
/**
|
|
20
|
+
* Initialize the tree-sitter WASM runtime.
|
|
21
|
+
* Safe to call multiple times — only initializes once.
|
|
22
|
+
*/
|
|
23
|
+
export async function initParser() {
|
|
24
|
+
if (initialized)
|
|
25
|
+
return;
|
|
26
|
+
await Parser.init();
|
|
27
|
+
initialized = true;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Load a tree-sitter language grammar from a WASM file.
|
|
31
|
+
* Caches loaded grammars for reuse.
|
|
32
|
+
*
|
|
33
|
+
* @param wasmPath - Absolute path to the .wasm grammar file
|
|
34
|
+
* @returns The loaded Language object
|
|
35
|
+
*/
|
|
36
|
+
export async function loadLanguage(wasmPath) {
|
|
37
|
+
const cached = languageCache.get(wasmPath);
|
|
38
|
+
if (cached)
|
|
39
|
+
return cached;
|
|
40
|
+
await initParser();
|
|
41
|
+
const language = await Language.load(wasmPath);
|
|
42
|
+
languageCache.set(wasmPath, language);
|
|
43
|
+
return language;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Parse source code into a tree-sitter syntax tree.
|
|
47
|
+
*
|
|
48
|
+
* @param source - The source code string
|
|
49
|
+
* @param language - The loaded tree-sitter Language
|
|
50
|
+
* @returns The parsed Tree (caller must call tree.delete() when done)
|
|
51
|
+
*/
|
|
52
|
+
export function parseSource(source, language) {
|
|
53
|
+
const parser = new Parser();
|
|
54
|
+
parser.setLanguage(language);
|
|
55
|
+
const tree = parser.parse(source);
|
|
56
|
+
parser.delete();
|
|
57
|
+
if (!tree) {
|
|
58
|
+
throw new Error('Tree-sitter parsing returned null');
|
|
59
|
+
}
|
|
60
|
+
return tree;
|
|
61
|
+
}
|
|
62
|
+
// ─── WASM Grammar Resolution ──────────────────────────────────
|
|
63
|
+
/** WASM file names inside the tree-sitter-wasms/out/ directory. */
|
|
64
|
+
const GRAMMAR_WASM_FILES = {
|
|
65
|
+
typescript: 'tree-sitter-typescript.wasm',
|
|
66
|
+
javascript: 'tree-sitter-javascript.wasm',
|
|
67
|
+
python: 'tree-sitter-python.wasm',
|
|
68
|
+
go: 'tree-sitter-go.wasm',
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Resolve the WASM file path for a language grammar.
|
|
72
|
+
* Uses the `tree-sitter-wasms` package which bundles prebuilt grammars.
|
|
73
|
+
*
|
|
74
|
+
* @param language - The scope language
|
|
75
|
+
* @returns Path to the .wasm file, or undefined if not found
|
|
76
|
+
*/
|
|
77
|
+
export function resolveGrammarPath(language) {
|
|
78
|
+
const wasmFile = GRAMMAR_WASM_FILES[language];
|
|
79
|
+
if (!wasmFile)
|
|
80
|
+
return undefined;
|
|
81
|
+
try {
|
|
82
|
+
const packageDir = require.resolve('@cursorless/tree-sitter-wasms/package.json');
|
|
83
|
+
const dir = packageDir.replace('/package.json', '');
|
|
84
|
+
return resolve(dir, 'out', wasmFile);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Reset parser state. Used in tests to ensure clean initialization.
|
|
92
|
+
*/
|
|
93
|
+
export function resetParser() {
|
|
94
|
+
initialized = false;
|
|
95
|
+
languageCache.clear();
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/scope/parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAInD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C,kEAAkE;AAElE,IA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;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAuB;IACxD,MAAM,QAAQ,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IAC9C,IAAI,CAAC,QAAQ;QAAE,OAAO,SAAS,CAAC;IAEhC,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,4CAA4C,CAAC,CAAC;QACjF,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;QACpD,OAAO,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;IACvC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW;IACzB,WAAW,GAAG,KAAK,CAAC;IACpB,aAAa,CAAC,KAAK,EAAE,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree-sitter S-expression Queries
|
|
3
|
+
*
|
|
4
|
+
* Per-language queries that extract symbol definitions (functions,
|
|
5
|
+
* classes, methods, interfaces) from parsed ASTs.
|
|
6
|
+
*
|
|
7
|
+
* Each query uses named captures:
|
|
8
|
+
* @name — the symbol's identifier node
|
|
9
|
+
* @node — the full definition node (for byte/line ranges)
|
|
10
|
+
* @parent — parent class/struct name (for methods)
|
|
11
|
+
*/
|
|
12
|
+
import type { ScopeLanguage } from './types.js';
|
|
13
|
+
/**
|
|
14
|
+
* Get the tree-sitter query string for a given language.
|
|
15
|
+
* Returns undefined for unsupported languages.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getQuery(language: ScopeLanguage): string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Get the WASM grammar name for tree-sitter Language.load().
|
|
20
|
+
* Maps scope languages to their grammar identifiers.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getGrammarName(language: ScopeLanguage): string;
|
|
23
|
+
//# sourceMappingURL=queries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../src/scope/queries.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AA6GhD;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,aAAa,GAAG,MAAM,GAAG,SAAS,CAEpE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,aAAa,GAAG,MAAM,CAW9D"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree-sitter S-expression Queries
|
|
3
|
+
*
|
|
4
|
+
* Per-language queries that extract symbol definitions (functions,
|
|
5
|
+
* classes, methods, interfaces) from parsed ASTs.
|
|
6
|
+
*
|
|
7
|
+
* Each query uses named captures:
|
|
8
|
+
* @name — the symbol's identifier node
|
|
9
|
+
* @node — the full definition node (for byte/line ranges)
|
|
10
|
+
* @parent — parent class/struct name (for methods)
|
|
11
|
+
*/
|
|
12
|
+
// ─── TypeScript / JavaScript ───────────────────────────────────
|
|
13
|
+
const TYPESCRIPT_QUERY = `
|
|
14
|
+
; top-level function declarations
|
|
15
|
+
(function_declaration
|
|
16
|
+
name: (identifier) @name) @node
|
|
17
|
+
|
|
18
|
+
; arrow functions assigned to const/let/var
|
|
19
|
+
(lexical_declaration
|
|
20
|
+
(variable_declarator
|
|
21
|
+
name: (identifier) @name
|
|
22
|
+
value: (arrow_function))) @node
|
|
23
|
+
|
|
24
|
+
; class declarations
|
|
25
|
+
(class_declaration
|
|
26
|
+
name: (identifier) @name) @node
|
|
27
|
+
|
|
28
|
+
; methods inside classes
|
|
29
|
+
(class_declaration
|
|
30
|
+
name: (identifier) @parent
|
|
31
|
+
body: (class_body
|
|
32
|
+
(method_definition
|
|
33
|
+
name: (property_identifier) @name) @node))
|
|
34
|
+
|
|
35
|
+
; interface declarations (TypeScript only — ignored in JS grammars)
|
|
36
|
+
(interface_declaration
|
|
37
|
+
name: (identifier) @name) @node
|
|
38
|
+
|
|
39
|
+
; export function
|
|
40
|
+
(export_statement
|
|
41
|
+
declaration: (function_declaration
|
|
42
|
+
name: (identifier) @name)) @node
|
|
43
|
+
|
|
44
|
+
; export class
|
|
45
|
+
(export_statement
|
|
46
|
+
declaration: (class_declaration
|
|
47
|
+
name: (identifier) @name)) @node
|
|
48
|
+
|
|
49
|
+
; export interface
|
|
50
|
+
(export_statement
|
|
51
|
+
declaration: (interface_declaration
|
|
52
|
+
name: (identifier) @name)) @node
|
|
53
|
+
|
|
54
|
+
; export const arrow
|
|
55
|
+
(export_statement
|
|
56
|
+
declaration: (lexical_declaration
|
|
57
|
+
(variable_declarator
|
|
58
|
+
name: (identifier) @name
|
|
59
|
+
value: (arrow_function)))) @node
|
|
60
|
+
`;
|
|
61
|
+
// ─── Python ────────────────────────────────────────────────────
|
|
62
|
+
const PYTHON_QUERY = `
|
|
63
|
+
; function definitions
|
|
64
|
+
(function_definition
|
|
65
|
+
name: (identifier) @name) @node
|
|
66
|
+
|
|
67
|
+
; class definitions
|
|
68
|
+
(class_definition
|
|
69
|
+
name: (identifier) @name) @node
|
|
70
|
+
|
|
71
|
+
; methods inside classes
|
|
72
|
+
(class_definition
|
|
73
|
+
name: (identifier) @parent
|
|
74
|
+
body: (block
|
|
75
|
+
(function_definition
|
|
76
|
+
name: (identifier) @name) @node))
|
|
77
|
+
`;
|
|
78
|
+
// ─── Go ────────────────────────────────────────────────────────
|
|
79
|
+
const GO_QUERY = `
|
|
80
|
+
; function declarations
|
|
81
|
+
(function_declaration
|
|
82
|
+
name: (identifier) @name) @node
|
|
83
|
+
|
|
84
|
+
; method declarations (with receiver)
|
|
85
|
+
(method_declaration
|
|
86
|
+
name: (field_identifier) @name
|
|
87
|
+
receiver: (parameter_list
|
|
88
|
+
(parameter_declaration
|
|
89
|
+
type: [(pointer_type (type_identifier) @parent)
|
|
90
|
+
(type_identifier) @parent]))) @node
|
|
91
|
+
|
|
92
|
+
; type declarations (struct)
|
|
93
|
+
(type_declaration
|
|
94
|
+
(type_spec
|
|
95
|
+
name: (type_identifier) @name
|
|
96
|
+
type: (struct_type))) @node
|
|
97
|
+
|
|
98
|
+
; interface type declarations
|
|
99
|
+
(type_declaration
|
|
100
|
+
(type_spec
|
|
101
|
+
name: (type_identifier) @name
|
|
102
|
+
type: (interface_type))) @node
|
|
103
|
+
`;
|
|
104
|
+
// ─── Query Registry ────────────────────────────────────────────
|
|
105
|
+
const QUERIES = {
|
|
106
|
+
typescript: TYPESCRIPT_QUERY,
|
|
107
|
+
javascript: TYPESCRIPT_QUERY, // Same grammar family
|
|
108
|
+
python: PYTHON_QUERY,
|
|
109
|
+
go: GO_QUERY,
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Get the tree-sitter query string for a given language.
|
|
113
|
+
* Returns undefined for unsupported languages.
|
|
114
|
+
*/
|
|
115
|
+
export function getQuery(language) {
|
|
116
|
+
return QUERIES[language];
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Get the WASM grammar name for tree-sitter Language.load().
|
|
120
|
+
* Maps scope languages to their grammar identifiers.
|
|
121
|
+
*/
|
|
122
|
+
export function getGrammarName(language) {
|
|
123
|
+
switch (language) {
|
|
124
|
+
case 'typescript':
|
|
125
|
+
return 'tree-sitter-typescript';
|
|
126
|
+
case 'javascript':
|
|
127
|
+
return 'tree-sitter-javascript';
|
|
128
|
+
case 'python':
|
|
129
|
+
return 'tree-sitter-python';
|
|
130
|
+
case 'go':
|
|
131
|
+
return 'tree-sitter-go';
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=queries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../src/scope/queries.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,kEAAkE;AAElE,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+CxB,CAAC;AAEF,kEAAkE;AAElE,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;CAepB,CAAC;AAEF,kEAAkE;AAElE,MAAM,QAAQ,GAAG;;;;;;;;;;;;;;;;;;;;;;;;CAwBhB,CAAC;AAEF,kEAAkE;AAElE,MAAM,OAAO,GAAkC;IAC7C,UAAU,EAAE,gBAAgB;IAC5B,UAAU,EAAE,gBAAgB,EAAE,sBAAsB;IACpD,MAAM,EAAE,YAAY;IACpB,EAAE,EAAE,QAAQ;CACb,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,QAAuB;IAC9C,OAAO,OAAO,CAAC,QAAQ,CAAC,CAAC;AAC3B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,QAAuB;IACpD,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,YAAY;YACf,OAAO,wBAAwB,CAAC;QAClC,KAAK,YAAY;YACf,OAAO,wBAAwB,CAAC;QAClC,KAAK,QAAQ;YACX,OAAO,oBAAoB,CAAC;QAC9B,KAAK,IAAI;YACP,OAAO,gBAAgB,CAAC;IAC5B,CAAC;AACH,CAAC"}
|