tree-sitter-analyzer 1.9.17.1__py3-none-any.whl
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.
- tree_sitter_analyzer/__init__.py +132 -0
- tree_sitter_analyzer/__main__.py +11 -0
- tree_sitter_analyzer/api.py +853 -0
- tree_sitter_analyzer/cli/__init__.py +39 -0
- tree_sitter_analyzer/cli/__main__.py +12 -0
- tree_sitter_analyzer/cli/argument_validator.py +89 -0
- tree_sitter_analyzer/cli/commands/__init__.py +26 -0
- tree_sitter_analyzer/cli/commands/advanced_command.py +226 -0
- tree_sitter_analyzer/cli/commands/base_command.py +181 -0
- tree_sitter_analyzer/cli/commands/default_command.py +18 -0
- tree_sitter_analyzer/cli/commands/find_and_grep_cli.py +188 -0
- tree_sitter_analyzer/cli/commands/list_files_cli.py +133 -0
- tree_sitter_analyzer/cli/commands/partial_read_command.py +139 -0
- tree_sitter_analyzer/cli/commands/query_command.py +109 -0
- tree_sitter_analyzer/cli/commands/search_content_cli.py +161 -0
- tree_sitter_analyzer/cli/commands/structure_command.py +156 -0
- tree_sitter_analyzer/cli/commands/summary_command.py +116 -0
- tree_sitter_analyzer/cli/commands/table_command.py +414 -0
- tree_sitter_analyzer/cli/info_commands.py +124 -0
- tree_sitter_analyzer/cli_main.py +472 -0
- tree_sitter_analyzer/constants.py +85 -0
- tree_sitter_analyzer/core/__init__.py +15 -0
- tree_sitter_analyzer/core/analysis_engine.py +580 -0
- tree_sitter_analyzer/core/cache_service.py +333 -0
- tree_sitter_analyzer/core/engine.py +585 -0
- tree_sitter_analyzer/core/parser.py +293 -0
- tree_sitter_analyzer/core/query.py +605 -0
- tree_sitter_analyzer/core/query_filter.py +200 -0
- tree_sitter_analyzer/core/query_service.py +340 -0
- tree_sitter_analyzer/encoding_utils.py +530 -0
- tree_sitter_analyzer/exceptions.py +747 -0
- tree_sitter_analyzer/file_handler.py +246 -0
- tree_sitter_analyzer/formatters/__init__.py +1 -0
- tree_sitter_analyzer/formatters/base_formatter.py +201 -0
- tree_sitter_analyzer/formatters/csharp_formatter.py +367 -0
- tree_sitter_analyzer/formatters/formatter_config.py +197 -0
- tree_sitter_analyzer/formatters/formatter_factory.py +84 -0
- tree_sitter_analyzer/formatters/formatter_registry.py +377 -0
- tree_sitter_analyzer/formatters/formatter_selector.py +96 -0
- tree_sitter_analyzer/formatters/go_formatter.py +368 -0
- tree_sitter_analyzer/formatters/html_formatter.py +498 -0
- tree_sitter_analyzer/formatters/java_formatter.py +423 -0
- tree_sitter_analyzer/formatters/javascript_formatter.py +611 -0
- tree_sitter_analyzer/formatters/kotlin_formatter.py +268 -0
- tree_sitter_analyzer/formatters/language_formatter_factory.py +123 -0
- tree_sitter_analyzer/formatters/legacy_formatter_adapters.py +228 -0
- tree_sitter_analyzer/formatters/markdown_formatter.py +725 -0
- tree_sitter_analyzer/formatters/php_formatter.py +301 -0
- tree_sitter_analyzer/formatters/python_formatter.py +830 -0
- tree_sitter_analyzer/formatters/ruby_formatter.py +278 -0
- tree_sitter_analyzer/formatters/rust_formatter.py +233 -0
- tree_sitter_analyzer/formatters/sql_formatter_wrapper.py +689 -0
- tree_sitter_analyzer/formatters/sql_formatters.py +536 -0
- tree_sitter_analyzer/formatters/typescript_formatter.py +543 -0
- tree_sitter_analyzer/formatters/yaml_formatter.py +462 -0
- tree_sitter_analyzer/interfaces/__init__.py +9 -0
- tree_sitter_analyzer/interfaces/cli.py +535 -0
- tree_sitter_analyzer/interfaces/cli_adapter.py +359 -0
- tree_sitter_analyzer/interfaces/mcp_adapter.py +224 -0
- tree_sitter_analyzer/interfaces/mcp_server.py +428 -0
- tree_sitter_analyzer/language_detector.py +553 -0
- tree_sitter_analyzer/language_loader.py +271 -0
- tree_sitter_analyzer/languages/__init__.py +10 -0
- tree_sitter_analyzer/languages/csharp_plugin.py +1076 -0
- tree_sitter_analyzer/languages/css_plugin.py +449 -0
- tree_sitter_analyzer/languages/go_plugin.py +836 -0
- tree_sitter_analyzer/languages/html_plugin.py +496 -0
- tree_sitter_analyzer/languages/java_plugin.py +1299 -0
- tree_sitter_analyzer/languages/javascript_plugin.py +1622 -0
- tree_sitter_analyzer/languages/kotlin_plugin.py +656 -0
- tree_sitter_analyzer/languages/markdown_plugin.py +1928 -0
- tree_sitter_analyzer/languages/php_plugin.py +862 -0
- tree_sitter_analyzer/languages/python_plugin.py +1636 -0
- tree_sitter_analyzer/languages/ruby_plugin.py +757 -0
- tree_sitter_analyzer/languages/rust_plugin.py +673 -0
- tree_sitter_analyzer/languages/sql_plugin.py +2444 -0
- tree_sitter_analyzer/languages/typescript_plugin.py +1892 -0
- tree_sitter_analyzer/languages/yaml_plugin.py +695 -0
- tree_sitter_analyzer/legacy_table_formatter.py +860 -0
- tree_sitter_analyzer/mcp/__init__.py +34 -0
- tree_sitter_analyzer/mcp/resources/__init__.py +43 -0
- tree_sitter_analyzer/mcp/resources/code_file_resource.py +208 -0
- tree_sitter_analyzer/mcp/resources/project_stats_resource.py +586 -0
- tree_sitter_analyzer/mcp/server.py +869 -0
- tree_sitter_analyzer/mcp/tools/__init__.py +28 -0
- tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +779 -0
- tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py +291 -0
- tree_sitter_analyzer/mcp/tools/base_tool.py +139 -0
- tree_sitter_analyzer/mcp/tools/fd_rg_utils.py +816 -0
- tree_sitter_analyzer/mcp/tools/find_and_grep_tool.py +686 -0
- tree_sitter_analyzer/mcp/tools/list_files_tool.py +413 -0
- tree_sitter_analyzer/mcp/tools/output_format_validator.py +148 -0
- tree_sitter_analyzer/mcp/tools/query_tool.py +443 -0
- tree_sitter_analyzer/mcp/tools/read_partial_tool.py +464 -0
- tree_sitter_analyzer/mcp/tools/search_content_tool.py +836 -0
- tree_sitter_analyzer/mcp/tools/table_format_tool.py +572 -0
- tree_sitter_analyzer/mcp/tools/universal_analyze_tool.py +653 -0
- tree_sitter_analyzer/mcp/utils/__init__.py +113 -0
- tree_sitter_analyzer/mcp/utils/error_handler.py +569 -0
- tree_sitter_analyzer/mcp/utils/file_output_factory.py +217 -0
- tree_sitter_analyzer/mcp/utils/file_output_manager.py +322 -0
- tree_sitter_analyzer/mcp/utils/gitignore_detector.py +358 -0
- tree_sitter_analyzer/mcp/utils/path_resolver.py +414 -0
- tree_sitter_analyzer/mcp/utils/search_cache.py +343 -0
- tree_sitter_analyzer/models.py +840 -0
- tree_sitter_analyzer/mypy_current_errors.txt +2 -0
- tree_sitter_analyzer/output_manager.py +255 -0
- tree_sitter_analyzer/platform_compat/__init__.py +3 -0
- tree_sitter_analyzer/platform_compat/adapter.py +324 -0
- tree_sitter_analyzer/platform_compat/compare.py +224 -0
- tree_sitter_analyzer/platform_compat/detector.py +67 -0
- tree_sitter_analyzer/platform_compat/fixtures.py +228 -0
- tree_sitter_analyzer/platform_compat/profiles.py +217 -0
- tree_sitter_analyzer/platform_compat/record.py +55 -0
- tree_sitter_analyzer/platform_compat/recorder.py +155 -0
- tree_sitter_analyzer/platform_compat/report.py +92 -0
- tree_sitter_analyzer/plugins/__init__.py +280 -0
- tree_sitter_analyzer/plugins/base.py +647 -0
- tree_sitter_analyzer/plugins/manager.py +384 -0
- tree_sitter_analyzer/project_detector.py +328 -0
- tree_sitter_analyzer/queries/__init__.py +27 -0
- tree_sitter_analyzer/queries/csharp.py +216 -0
- tree_sitter_analyzer/queries/css.py +615 -0
- tree_sitter_analyzer/queries/go.py +275 -0
- tree_sitter_analyzer/queries/html.py +543 -0
- tree_sitter_analyzer/queries/java.py +402 -0
- tree_sitter_analyzer/queries/javascript.py +724 -0
- tree_sitter_analyzer/queries/kotlin.py +192 -0
- tree_sitter_analyzer/queries/markdown.py +258 -0
- tree_sitter_analyzer/queries/php.py +95 -0
- tree_sitter_analyzer/queries/python.py +859 -0
- tree_sitter_analyzer/queries/ruby.py +92 -0
- tree_sitter_analyzer/queries/rust.py +223 -0
- tree_sitter_analyzer/queries/sql.py +555 -0
- tree_sitter_analyzer/queries/typescript.py +871 -0
- tree_sitter_analyzer/queries/yaml.py +236 -0
- tree_sitter_analyzer/query_loader.py +272 -0
- tree_sitter_analyzer/security/__init__.py +22 -0
- tree_sitter_analyzer/security/boundary_manager.py +277 -0
- tree_sitter_analyzer/security/regex_checker.py +297 -0
- tree_sitter_analyzer/security/validator.py +599 -0
- tree_sitter_analyzer/table_formatter.py +782 -0
- tree_sitter_analyzer/utils/__init__.py +53 -0
- tree_sitter_analyzer/utils/logging.py +433 -0
- tree_sitter_analyzer/utils/tree_sitter_compat.py +289 -0
- tree_sitter_analyzer-1.9.17.1.dist-info/METADATA +485 -0
- tree_sitter_analyzer-1.9.17.1.dist-info/RECORD +149 -0
- tree_sitter_analyzer-1.9.17.1.dist-info/WHEEL +4 -0
- tree_sitter_analyzer-1.9.17.1.dist-info/entry_points.txt +25 -0
|
@@ -0,0 +1,724 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
JavaScript Language Queries
|
|
4
|
+
|
|
5
|
+
Comprehensive Tree-sitter queries for JavaScript language constructs.
|
|
6
|
+
Covers functions, classes, variables, imports, exports, and modern JavaScript features.
|
|
7
|
+
Equivalent to Java query coverage for consistent language support.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
# JavaScript-specific query library
|
|
11
|
+
JAVASCRIPT_QUERIES: dict[str, str] = {
|
|
12
|
+
# --- Basic Structure ---
|
|
13
|
+
"function": """
|
|
14
|
+
(function_declaration) @function
|
|
15
|
+
""",
|
|
16
|
+
"function_declaration": """
|
|
17
|
+
(function_declaration
|
|
18
|
+
name: (identifier) @function_name
|
|
19
|
+
parameters: (formal_parameters) @parameters
|
|
20
|
+
body: (statement_block) @body) @function_declaration
|
|
21
|
+
""",
|
|
22
|
+
"function_expression": """
|
|
23
|
+
(function_expression
|
|
24
|
+
name: (identifier)? @function_name
|
|
25
|
+
parameters: (formal_parameters) @parameters
|
|
26
|
+
body: (statement_block) @body) @function_expression
|
|
27
|
+
""",
|
|
28
|
+
"arrow_function": """
|
|
29
|
+
(arrow_function
|
|
30
|
+
parameters: (formal_parameters) @parameters
|
|
31
|
+
body: (_) @body) @arrow_function
|
|
32
|
+
""",
|
|
33
|
+
"method_definition": """
|
|
34
|
+
(method_definition
|
|
35
|
+
name: (property_identifier) @method_name
|
|
36
|
+
parameters: (formal_parameters) @parameters
|
|
37
|
+
body: (statement_block) @body) @method_definition
|
|
38
|
+
""",
|
|
39
|
+
"async_function": """
|
|
40
|
+
(function_declaration
|
|
41
|
+
"async" @async_keyword
|
|
42
|
+
name: (identifier) @function_name
|
|
43
|
+
parameters: (formal_parameters) @parameters
|
|
44
|
+
body: (statement_block) @body) @async_function
|
|
45
|
+
""",
|
|
46
|
+
"generator_function": """
|
|
47
|
+
(generator_function_declaration
|
|
48
|
+
name: (identifier) @function_name
|
|
49
|
+
parameters: (formal_parameters) @parameters
|
|
50
|
+
body: (statement_block) @body) @generator_function
|
|
51
|
+
""",
|
|
52
|
+
# --- Classes ---
|
|
53
|
+
"class": """
|
|
54
|
+
(class_declaration) @class
|
|
55
|
+
""",
|
|
56
|
+
"class_declaration": """
|
|
57
|
+
(class_declaration
|
|
58
|
+
name: (identifier) @class_name
|
|
59
|
+
(class_heritage)? @superclass
|
|
60
|
+
body: (class_body) @body) @class_declaration
|
|
61
|
+
""",
|
|
62
|
+
"class_expression": """
|
|
63
|
+
(class_expression
|
|
64
|
+
name: (identifier)? @class_name
|
|
65
|
+
(class_heritage)? @superclass
|
|
66
|
+
body: (class_body) @body) @class_expression
|
|
67
|
+
""",
|
|
68
|
+
"class_method": """
|
|
69
|
+
(class_body
|
|
70
|
+
(method_definition
|
|
71
|
+
name: (property_identifier) @method_name
|
|
72
|
+
parameters: (formal_parameters) @parameters
|
|
73
|
+
body: (statement_block) @body)) @class_method
|
|
74
|
+
""",
|
|
75
|
+
"constructor": """
|
|
76
|
+
(method_definition
|
|
77
|
+
name: (property_identifier) @constructor_name
|
|
78
|
+
(#match? @constructor_name "constructor")
|
|
79
|
+
parameters: (formal_parameters) @parameters
|
|
80
|
+
body: (statement_block) @body) @constructor
|
|
81
|
+
""",
|
|
82
|
+
"getter": """
|
|
83
|
+
(method_definition
|
|
84
|
+
"get" @get_keyword
|
|
85
|
+
name: (property_identifier) @getter_name
|
|
86
|
+
body: (statement_block) @body) @getter
|
|
87
|
+
""",
|
|
88
|
+
"setter": """
|
|
89
|
+
(method_definition
|
|
90
|
+
"set" @set_keyword
|
|
91
|
+
name: (property_identifier) @setter_name
|
|
92
|
+
parameters: (formal_parameters) @parameters
|
|
93
|
+
body: (statement_block) @body) @setter
|
|
94
|
+
""",
|
|
95
|
+
"static_method": """
|
|
96
|
+
(method_definition
|
|
97
|
+
"static" @static_keyword
|
|
98
|
+
name: (property_identifier) @method_name
|
|
99
|
+
parameters: (formal_parameters) @parameters
|
|
100
|
+
body: (statement_block) @body) @static_method
|
|
101
|
+
""",
|
|
102
|
+
"private_method": """
|
|
103
|
+
(method_definition
|
|
104
|
+
name: (private_property_identifier) @method_name
|
|
105
|
+
parameters: (formal_parameters) @parameters
|
|
106
|
+
body: (statement_block) @body) @private_method
|
|
107
|
+
""",
|
|
108
|
+
# --- Variables ---
|
|
109
|
+
"variable": """
|
|
110
|
+
(variable_declaration) @variable
|
|
111
|
+
""",
|
|
112
|
+
"var_declaration": """
|
|
113
|
+
(variable_declaration
|
|
114
|
+
(variable_declarator
|
|
115
|
+
name: (identifier) @variable_name
|
|
116
|
+
value: (_)? @value)) @var_declaration
|
|
117
|
+
""",
|
|
118
|
+
"let_declaration": """
|
|
119
|
+
(lexical_declaration
|
|
120
|
+
"let" @let_keyword
|
|
121
|
+
(variable_declarator
|
|
122
|
+
name: (identifier) @variable_name
|
|
123
|
+
value: (_)? @value)) @let_declaration
|
|
124
|
+
""",
|
|
125
|
+
"const_declaration": """
|
|
126
|
+
(lexical_declaration
|
|
127
|
+
"const" @const_keyword
|
|
128
|
+
(variable_declarator
|
|
129
|
+
name: (identifier) @variable_name
|
|
130
|
+
value: (_) @value)) @const_declaration
|
|
131
|
+
""",
|
|
132
|
+
"destructuring_assignment": """
|
|
133
|
+
(variable_declarator
|
|
134
|
+
name: (array_pattern) @array_destructuring
|
|
135
|
+
value: (_) @value) @destructuring_assignment
|
|
136
|
+
""",
|
|
137
|
+
"object_destructuring": """
|
|
138
|
+
(variable_declarator
|
|
139
|
+
name: (object_pattern) @object_destructuring
|
|
140
|
+
value: (_) @value) @object_destructuring
|
|
141
|
+
""",
|
|
142
|
+
# --- Imports and Exports ---
|
|
143
|
+
"import": """
|
|
144
|
+
(import_statement) @import
|
|
145
|
+
""",
|
|
146
|
+
"import_statement": """
|
|
147
|
+
(import_statement
|
|
148
|
+
source: (string) @source) @import_statement
|
|
149
|
+
""",
|
|
150
|
+
"import_default": """
|
|
151
|
+
(import_statement
|
|
152
|
+
(import_clause
|
|
153
|
+
(import_default_specifier
|
|
154
|
+
(identifier) @default_name))
|
|
155
|
+
source: (string) @source) @import_default
|
|
156
|
+
""",
|
|
157
|
+
"import_named": """
|
|
158
|
+
(import_statement
|
|
159
|
+
(import_clause
|
|
160
|
+
(named_imports
|
|
161
|
+
(import_specifier
|
|
162
|
+
name: (identifier) @import_name
|
|
163
|
+
alias: (identifier)? @alias)))
|
|
164
|
+
source: (string) @source) @import_named
|
|
165
|
+
""",
|
|
166
|
+
"import_namespace": """
|
|
167
|
+
(import_statement
|
|
168
|
+
(import_clause
|
|
169
|
+
(namespace_import
|
|
170
|
+
(identifier) @namespace_name))
|
|
171
|
+
source: (string) @source) @import_namespace
|
|
172
|
+
""",
|
|
173
|
+
"dynamic_import": """
|
|
174
|
+
(call_expression
|
|
175
|
+
function: (identifier) @import_function
|
|
176
|
+
(#match? @import_function "import")
|
|
177
|
+
arguments: (arguments (string) @source)) @dynamic_import
|
|
178
|
+
""",
|
|
179
|
+
"export": """
|
|
180
|
+
(export_statement) @export
|
|
181
|
+
""",
|
|
182
|
+
"export_default": """
|
|
183
|
+
(export_statement
|
|
184
|
+
"default" @default_keyword
|
|
185
|
+
declaration: (_) @declaration) @export_default
|
|
186
|
+
""",
|
|
187
|
+
"export_named": """
|
|
188
|
+
(export_statement
|
|
189
|
+
(export_clause
|
|
190
|
+
(export_specifier
|
|
191
|
+
name: (identifier) @export_name
|
|
192
|
+
alias: (identifier)? @alias))) @export_named
|
|
193
|
+
""",
|
|
194
|
+
"export_all": """
|
|
195
|
+
(export_statement
|
|
196
|
+
"*" @star
|
|
197
|
+
source: (string) @source) @export_all
|
|
198
|
+
""",
|
|
199
|
+
# --- Objects and Properties ---
|
|
200
|
+
"object": """
|
|
201
|
+
(object) @object
|
|
202
|
+
""",
|
|
203
|
+
"object_literal": """
|
|
204
|
+
(object
|
|
205
|
+
(pair
|
|
206
|
+
key: (_) @key
|
|
207
|
+
value: (_) @value)*) @object_literal
|
|
208
|
+
""",
|
|
209
|
+
"property_definition": """
|
|
210
|
+
(property_definition
|
|
211
|
+
property: (_) @property_name
|
|
212
|
+
value: (_)? @value) @property_definition
|
|
213
|
+
""",
|
|
214
|
+
"computed_property": """
|
|
215
|
+
(pair
|
|
216
|
+
key: (computed_property_name) @computed_key
|
|
217
|
+
value: (_) @value) @computed_property
|
|
218
|
+
""",
|
|
219
|
+
"shorthand_property": """
|
|
220
|
+
(shorthand_property_identifier) @shorthand_property
|
|
221
|
+
""",
|
|
222
|
+
"method_property": """
|
|
223
|
+
(pair
|
|
224
|
+
key: (_) @method_name
|
|
225
|
+
value: (function_expression) @method_function) @method_property
|
|
226
|
+
""",
|
|
227
|
+
# --- Control Flow ---
|
|
228
|
+
"if_statement": """
|
|
229
|
+
(if_statement
|
|
230
|
+
condition: (_) @condition
|
|
231
|
+
consequence: (_) @then_branch
|
|
232
|
+
alternative: (_)? @else_branch) @if_statement
|
|
233
|
+
""",
|
|
234
|
+
"for_statement": """
|
|
235
|
+
(for_statement
|
|
236
|
+
initializer: (_)? @init
|
|
237
|
+
condition: (_)? @condition
|
|
238
|
+
increment: (_)? @update
|
|
239
|
+
body: (_) @body) @for_statement
|
|
240
|
+
""",
|
|
241
|
+
"for_in_statement": """
|
|
242
|
+
(for_in_statement
|
|
243
|
+
left: (_) @variable
|
|
244
|
+
right: (_) @object
|
|
245
|
+
body: (_) @body) @for_in_statement
|
|
246
|
+
""",
|
|
247
|
+
"for_of_statement": """
|
|
248
|
+
(for_of_statement
|
|
249
|
+
left: (_) @variable
|
|
250
|
+
right: (_) @iterable
|
|
251
|
+
body: (_) @body) @for_of_statement
|
|
252
|
+
""",
|
|
253
|
+
"while_statement": """
|
|
254
|
+
(while_statement
|
|
255
|
+
condition: (_) @condition
|
|
256
|
+
body: (_) @body) @while_statement
|
|
257
|
+
""",
|
|
258
|
+
"do_statement": """
|
|
259
|
+
(do_statement
|
|
260
|
+
body: (_) @body
|
|
261
|
+
condition: (_) @condition) @do_statement
|
|
262
|
+
""",
|
|
263
|
+
"switch_statement": """
|
|
264
|
+
(switch_statement
|
|
265
|
+
discriminant: (_) @discriminant
|
|
266
|
+
body: (switch_body) @body) @switch_statement
|
|
267
|
+
""",
|
|
268
|
+
"case_clause": """
|
|
269
|
+
(switch_case
|
|
270
|
+
value: (_) @case_value
|
|
271
|
+
body: (_)* @case_body) @case_clause
|
|
272
|
+
""",
|
|
273
|
+
"default_clause": """
|
|
274
|
+
(switch_default
|
|
275
|
+
body: (_)* @default_body) @default_clause
|
|
276
|
+
""",
|
|
277
|
+
# --- Error Handling ---
|
|
278
|
+
"try_statement": """
|
|
279
|
+
(try_statement
|
|
280
|
+
body: (statement_block) @try_body
|
|
281
|
+
handler: (catch_clause)? @catch_handler
|
|
282
|
+
finalizer: (finally_clause)? @finally_block) @try_statement
|
|
283
|
+
""",
|
|
284
|
+
"catch_clause": """
|
|
285
|
+
(catch_clause
|
|
286
|
+
parameter: (identifier)? @error_parameter
|
|
287
|
+
body: (statement_block) @catch_body) @catch_clause
|
|
288
|
+
""",
|
|
289
|
+
"finally_clause": """
|
|
290
|
+
(finally_clause
|
|
291
|
+
body: (statement_block) @finally_body) @finally_clause
|
|
292
|
+
""",
|
|
293
|
+
"throw_statement": """
|
|
294
|
+
(throw_statement
|
|
295
|
+
argument: (_) @thrown_expression) @throw_statement
|
|
296
|
+
""",
|
|
297
|
+
# --- Modern JavaScript Features ---
|
|
298
|
+
"template_literal": """
|
|
299
|
+
(template_literal) @template_literal
|
|
300
|
+
""",
|
|
301
|
+
"template_substitution": """
|
|
302
|
+
(template_substitution
|
|
303
|
+
expression: (_) @substitution_expr) @template_substitution
|
|
304
|
+
""",
|
|
305
|
+
"spread_element": """
|
|
306
|
+
(spread_element
|
|
307
|
+
argument: (_) @spread_argument) @spread_element
|
|
308
|
+
""",
|
|
309
|
+
"rest_parameter": """
|
|
310
|
+
(rest_parameter
|
|
311
|
+
pattern: (identifier) @rest_name) @rest_parameter
|
|
312
|
+
""",
|
|
313
|
+
"await_expression": """
|
|
314
|
+
(await_expression
|
|
315
|
+
argument: (_) @awaited_expression) @await_expression
|
|
316
|
+
""",
|
|
317
|
+
"yield_expression": """
|
|
318
|
+
(yield_expression
|
|
319
|
+
argument: (_)? @yielded_value) @yield_expression
|
|
320
|
+
""",
|
|
321
|
+
# --- JSX (React) ---
|
|
322
|
+
"jsx_element": """
|
|
323
|
+
(jsx_element
|
|
324
|
+
open_tag: (jsx_opening_element) @open_tag
|
|
325
|
+
close_tag: (jsx_closing_element)? @close_tag) @jsx_element
|
|
326
|
+
""",
|
|
327
|
+
"jsx_self_closing": """
|
|
328
|
+
(jsx_self_closing_element
|
|
329
|
+
name: (_) @element_name) @jsx_self_closing
|
|
330
|
+
""",
|
|
331
|
+
"jsx_attribute": """
|
|
332
|
+
(jsx_attribute
|
|
333
|
+
name: (property_identifier) @attribute_name
|
|
334
|
+
value: (_)? @attribute_value) @jsx_attribute
|
|
335
|
+
""",
|
|
336
|
+
"jsx_expression": """
|
|
337
|
+
(jsx_expression
|
|
338
|
+
expression: (_) @jsx_expression_content) @jsx_expression
|
|
339
|
+
""",
|
|
340
|
+
# --- Comments and Documentation ---
|
|
341
|
+
"comment": """
|
|
342
|
+
(comment) @comment
|
|
343
|
+
""",
|
|
344
|
+
"jsdoc_comment": """
|
|
345
|
+
(comment) @jsdoc_comment
|
|
346
|
+
(#match? @jsdoc_comment "^/\\*\\*")
|
|
347
|
+
""",
|
|
348
|
+
"line_comment": """
|
|
349
|
+
(comment) @line_comment
|
|
350
|
+
(#match? @line_comment "^//")
|
|
351
|
+
""",
|
|
352
|
+
"block_comment": """
|
|
353
|
+
(comment) @block_comment
|
|
354
|
+
(#match? @block_comment "^/\\*(?!\\*)")
|
|
355
|
+
""",
|
|
356
|
+
# --- Framework-specific Patterns ---
|
|
357
|
+
"react_component": """
|
|
358
|
+
(function_declaration
|
|
359
|
+
name: (identifier) @component_name
|
|
360
|
+
(#match? @component_name "^[A-Z]")
|
|
361
|
+
body: (statement_block
|
|
362
|
+
(return_statement
|
|
363
|
+
argument: (jsx_element)))) @react_component
|
|
364
|
+
""",
|
|
365
|
+
"react_hook": """
|
|
366
|
+
(call_expression
|
|
367
|
+
function: (identifier) @hook_name
|
|
368
|
+
(#match? @hook_name "^use[A-Z]")) @react_hook
|
|
369
|
+
""",
|
|
370
|
+
"node_require": """
|
|
371
|
+
(call_expression
|
|
372
|
+
function: (identifier) @require_function
|
|
373
|
+
(#match? @require_function "require")
|
|
374
|
+
arguments: (arguments (string) @module_path)) @node_require
|
|
375
|
+
""",
|
|
376
|
+
"module_exports": """
|
|
377
|
+
(assignment_expression
|
|
378
|
+
left: (member_expression
|
|
379
|
+
object: (identifier) @module_object
|
|
380
|
+
(#match? @module_object "module")
|
|
381
|
+
property: (property_identifier) @exports_property
|
|
382
|
+
(#match? @exports_property "exports"))
|
|
383
|
+
right: (_) @exported_value) @module_exports
|
|
384
|
+
""",
|
|
385
|
+
# --- Name-only Extraction ---
|
|
386
|
+
"function_name": """
|
|
387
|
+
(function_declaration
|
|
388
|
+
name: (identifier) @function_name)
|
|
389
|
+
""",
|
|
390
|
+
"class_name": """
|
|
391
|
+
(class_declaration
|
|
392
|
+
name: (identifier) @class_name)
|
|
393
|
+
""",
|
|
394
|
+
"variable_name": """
|
|
395
|
+
(variable_declarator
|
|
396
|
+
name: (identifier) @variable_name)
|
|
397
|
+
""",
|
|
398
|
+
# --- Advanced Patterns ---
|
|
399
|
+
"closure": """
|
|
400
|
+
(function_expression
|
|
401
|
+
body: (statement_block
|
|
402
|
+
(return_statement
|
|
403
|
+
argument: (function_expression)))) @closure
|
|
404
|
+
""",
|
|
405
|
+
"callback_function": """
|
|
406
|
+
(call_expression
|
|
407
|
+
arguments: (arguments
|
|
408
|
+
(function_expression) @callback_function)) @callback_call
|
|
409
|
+
""",
|
|
410
|
+
"promise_chain": """
|
|
411
|
+
(call_expression
|
|
412
|
+
function: (member_expression
|
|
413
|
+
object: (_) @promise_object
|
|
414
|
+
property: (property_identifier) @chain_method
|
|
415
|
+
(#match? @chain_method "^(then|catch|finally)$"))) @promise_chain
|
|
416
|
+
""",
|
|
417
|
+
"event_listener": """
|
|
418
|
+
(call_expression
|
|
419
|
+
function: (member_expression
|
|
420
|
+
property: (property_identifier) @listener_method
|
|
421
|
+
(#match? @listener_method "^(addEventListener|on)$"))
|
|
422
|
+
arguments: (arguments
|
|
423
|
+
(string) @event_type
|
|
424
|
+
(function_expression) @event_handler)) @event_listener
|
|
425
|
+
""",
|
|
426
|
+
"iife": """
|
|
427
|
+
(call_expression
|
|
428
|
+
function: (function_expression) @iife_function) @iife
|
|
429
|
+
""",
|
|
430
|
+
"module_pattern": """
|
|
431
|
+
(variable_declarator
|
|
432
|
+
name: (identifier) @module_name
|
|
433
|
+
value: (call_expression
|
|
434
|
+
function: (function_expression) @module_function)) @module_pattern
|
|
435
|
+
""",
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
# Query descriptions
|
|
439
|
+
JAVASCRIPT_QUERY_DESCRIPTIONS: dict[str, str] = {
|
|
440
|
+
"function": "Search JavaScript function declarations",
|
|
441
|
+
"function_declaration": "Search function declarations with details",
|
|
442
|
+
"function_expression": "Search function expressions",
|
|
443
|
+
"arrow_function": "Search arrow functions",
|
|
444
|
+
"method_definition": "Search method definitions",
|
|
445
|
+
"async_function": "Search async function declarations",
|
|
446
|
+
"generator_function": "Search generator functions",
|
|
447
|
+
"class": "Search JavaScript class declarations",
|
|
448
|
+
"class_declaration": "Search class declarations with details",
|
|
449
|
+
"class_expression": "Search class expressions",
|
|
450
|
+
"class_method": "Search class methods",
|
|
451
|
+
"constructor": "Search class constructors",
|
|
452
|
+
"getter": "Search getter methods",
|
|
453
|
+
"setter": "Search setter methods",
|
|
454
|
+
"static_method": "Search static methods",
|
|
455
|
+
"private_method": "Search private methods",
|
|
456
|
+
"variable": "Search variable declarations",
|
|
457
|
+
"var_declaration": "Search var declarations",
|
|
458
|
+
"let_declaration": "Search let declarations",
|
|
459
|
+
"const_declaration": "Search const declarations",
|
|
460
|
+
"destructuring_assignment": "Search destructuring assignments",
|
|
461
|
+
"object_destructuring": "Search object destructuring",
|
|
462
|
+
"import": "Search import statements",
|
|
463
|
+
"import_statement": "Search import statements with details",
|
|
464
|
+
"import_default": "Search default imports",
|
|
465
|
+
"import_named": "Search named imports",
|
|
466
|
+
"import_namespace": "Search namespace imports",
|
|
467
|
+
"dynamic_import": "Search dynamic imports",
|
|
468
|
+
"export": "Search export statements",
|
|
469
|
+
"export_default": "Search default exports",
|
|
470
|
+
"export_named": "Search named exports",
|
|
471
|
+
"export_all": "Search export all statements",
|
|
472
|
+
"object": "Search object literals",
|
|
473
|
+
"object_literal": "Search object literals with properties",
|
|
474
|
+
"property_definition": "Search property definitions",
|
|
475
|
+
"computed_property": "Search computed properties",
|
|
476
|
+
"shorthand_property": "Search shorthand properties",
|
|
477
|
+
"method_property": "Search method properties",
|
|
478
|
+
"if_statement": "Search if statements",
|
|
479
|
+
"for_statement": "Search for loops",
|
|
480
|
+
"for_in_statement": "Search for-in loops",
|
|
481
|
+
"for_of_statement": "Search for-of loops",
|
|
482
|
+
"while_statement": "Search while loops",
|
|
483
|
+
"do_statement": "Search do-while loops",
|
|
484
|
+
"switch_statement": "Search switch statements",
|
|
485
|
+
"case_clause": "Search switch case clauses",
|
|
486
|
+
"default_clause": "Search switch default clauses",
|
|
487
|
+
"try_statement": "Search try-catch statements",
|
|
488
|
+
"catch_clause": "Search catch clauses",
|
|
489
|
+
"finally_clause": "Search finally clauses",
|
|
490
|
+
"throw_statement": "Search throw statements",
|
|
491
|
+
"template_literal": "Search template literals",
|
|
492
|
+
"template_substitution": "Search template substitutions",
|
|
493
|
+
"spread_element": "Search spread elements",
|
|
494
|
+
"rest_parameter": "Search rest parameters",
|
|
495
|
+
"await_expression": "Search await expressions",
|
|
496
|
+
"yield_expression": "Search yield expressions",
|
|
497
|
+
"jsx_element": "Search JSX elements",
|
|
498
|
+
"jsx_self_closing": "Search self-closing JSX elements",
|
|
499
|
+
"jsx_attribute": "Search JSX attributes",
|
|
500
|
+
"jsx_expression": "Search JSX expressions",
|
|
501
|
+
"comment": "Search all comments",
|
|
502
|
+
"jsdoc_comment": "Search JSDoc comments",
|
|
503
|
+
"line_comment": "Search line comments",
|
|
504
|
+
"block_comment": "Search block comments",
|
|
505
|
+
"react_component": "Search React components",
|
|
506
|
+
"react_hook": "Search React hooks",
|
|
507
|
+
"node_require": "Search Node.js require statements",
|
|
508
|
+
"module_exports": "Search Node.js module exports",
|
|
509
|
+
"function_name": "Search function names only",
|
|
510
|
+
"class_name": "Search class names only",
|
|
511
|
+
"variable_name": "Search variable names only",
|
|
512
|
+
"closure": "Search closures",
|
|
513
|
+
"callback_function": "Search callback functions passed as arguments",
|
|
514
|
+
"promise_chain": "Search Promise chain patterns (.then, .catch, .finally)",
|
|
515
|
+
"event_listener": "Search event listener registrations",
|
|
516
|
+
"iife": "Search immediately invoked function expressions",
|
|
517
|
+
"module_pattern": "Search module patterns",
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
# Legacy query definitions for backward compatibility
|
|
521
|
+
FUNCTIONS = """
|
|
522
|
+
(function_declaration
|
|
523
|
+
name: (identifier) @function.name
|
|
524
|
+
parameters: (formal_parameters) @function.params
|
|
525
|
+
body: (statement_block) @function.body) @function.declaration
|
|
526
|
+
|
|
527
|
+
(function_expression
|
|
528
|
+
name: (identifier)? @function.name
|
|
529
|
+
parameters: (formal_parameters) @function.params
|
|
530
|
+
body: (statement_block) @function.body) @function.expression
|
|
531
|
+
|
|
532
|
+
(arrow_function
|
|
533
|
+
parameters: (formal_parameters) @function.params
|
|
534
|
+
body: (_) @function.body) @function.arrow
|
|
535
|
+
|
|
536
|
+
(method_definition
|
|
537
|
+
name: (property_identifier) @function.name
|
|
538
|
+
parameters: (formal_parameters) @function.params
|
|
539
|
+
body: (statement_block) @function.body) @method.definition
|
|
540
|
+
"""
|
|
541
|
+
|
|
542
|
+
CLASSES = """
|
|
543
|
+
(class_declaration
|
|
544
|
+
name: (identifier) @class.name
|
|
545
|
+
(class_heritage)? @class.superclass
|
|
546
|
+
body: (class_body) @class.body) @class.declaration
|
|
547
|
+
"""
|
|
548
|
+
|
|
549
|
+
VARIABLES = """
|
|
550
|
+
(variable_declaration
|
|
551
|
+
(variable_declarator
|
|
552
|
+
name: (identifier) @variable.name
|
|
553
|
+
value: (_)? @variable.value)) @variable.declaration
|
|
554
|
+
|
|
555
|
+
(lexical_declaration
|
|
556
|
+
(variable_declarator
|
|
557
|
+
name: (identifier) @variable.name
|
|
558
|
+
value: (_)? @variable.value)) @variable.lexical
|
|
559
|
+
"""
|
|
560
|
+
|
|
561
|
+
IMPORTS = """
|
|
562
|
+
(import_statement
|
|
563
|
+
source: (string) @import.source) @import.statement
|
|
564
|
+
|
|
565
|
+
(import_statement
|
|
566
|
+
(import_clause
|
|
567
|
+
(named_imports
|
|
568
|
+
(import_specifier
|
|
569
|
+
name: (identifier) @import.name
|
|
570
|
+
alias: (identifier)? @import.alias)))) @import.named
|
|
571
|
+
|
|
572
|
+
(import_statement
|
|
573
|
+
(import_clause
|
|
574
|
+
(import_default_specifier
|
|
575
|
+
(identifier) @import.default))) @import.default
|
|
576
|
+
|
|
577
|
+
(import_statement
|
|
578
|
+
(import_clause
|
|
579
|
+
(namespace_import
|
|
580
|
+
(identifier) @import.namespace))) @import.namespace
|
|
581
|
+
"""
|
|
582
|
+
|
|
583
|
+
EXPORTS = """
|
|
584
|
+
(export_statement
|
|
585
|
+
declaration: (_) @export.declaration) @export.statement
|
|
586
|
+
|
|
587
|
+
(export_statement
|
|
588
|
+
(export_clause
|
|
589
|
+
(export_specifier
|
|
590
|
+
name: (identifier) @export.name
|
|
591
|
+
alias: (identifier)? @export.alias))) @export.named
|
|
592
|
+
"""
|
|
593
|
+
|
|
594
|
+
OBJECTS = """
|
|
595
|
+
(object
|
|
596
|
+
(pair
|
|
597
|
+
key: (_) @property.key
|
|
598
|
+
value: (_) @property.value)) @object.literal
|
|
599
|
+
|
|
600
|
+
(property_definition
|
|
601
|
+
property: (_) @property.name
|
|
602
|
+
value: (_)? @property.value) @property.definition
|
|
603
|
+
"""
|
|
604
|
+
|
|
605
|
+
COMMENTS = """
|
|
606
|
+
(comment) @comment
|
|
607
|
+
"""
|
|
608
|
+
|
|
609
|
+
# Convert to ALL_QUERIES format for dynamic loader compatibility
|
|
610
|
+
ALL_QUERIES = {}
|
|
611
|
+
for query_name, query_string in JAVASCRIPT_QUERIES.items():
|
|
612
|
+
description = JAVASCRIPT_QUERY_DESCRIPTIONS.get(query_name, "No description")
|
|
613
|
+
ALL_QUERIES[query_name] = {"query": query_string, "description": description}
|
|
614
|
+
|
|
615
|
+
# Add legacy queries for backward compatibility
|
|
616
|
+
ALL_QUERIES["functions"] = {
|
|
617
|
+
"query": FUNCTIONS,
|
|
618
|
+
"description": "Search all function declarations, expressions, and methods",
|
|
619
|
+
}
|
|
620
|
+
ALL_QUERIES["classes"] = {
|
|
621
|
+
"query": CLASSES,
|
|
622
|
+
"description": "Search all class declarations and expressions",
|
|
623
|
+
}
|
|
624
|
+
ALL_QUERIES["variables"] = {
|
|
625
|
+
"query": VARIABLES,
|
|
626
|
+
"description": "Search all variable declarations (var, let, const)",
|
|
627
|
+
}
|
|
628
|
+
ALL_QUERIES["imports"] = {
|
|
629
|
+
"query": IMPORTS,
|
|
630
|
+
"description": "Search all import statements and clauses",
|
|
631
|
+
}
|
|
632
|
+
ALL_QUERIES["exports"] = {
|
|
633
|
+
"query": EXPORTS,
|
|
634
|
+
"description": "Search all export statements",
|
|
635
|
+
}
|
|
636
|
+
ALL_QUERIES["objects"] = {
|
|
637
|
+
"query": OBJECTS,
|
|
638
|
+
"description": "Search object literals and property definitions",
|
|
639
|
+
}
|
|
640
|
+
ALL_QUERIES["comments"] = {"query": COMMENTS, "description": "Search all comments"}
|
|
641
|
+
|
|
642
|
+
# Add missing method queries
|
|
643
|
+
ALL_QUERIES["method"] = {
|
|
644
|
+
"query": """
|
|
645
|
+
(method_definition
|
|
646
|
+
name: (property_identifier) @method_name
|
|
647
|
+
parameters: (formal_parameters) @parameters
|
|
648
|
+
body: (statement_block) @body) @method_definition
|
|
649
|
+
""",
|
|
650
|
+
"description": "Search method definitions",
|
|
651
|
+
}
|
|
652
|
+
ALL_QUERIES["methods"] = {
|
|
653
|
+
"query": """
|
|
654
|
+
(method_definition
|
|
655
|
+
name: (property_identifier) @method_name
|
|
656
|
+
parameters: (formal_parameters) @parameters
|
|
657
|
+
body: (statement_block) @body) @method_definition
|
|
658
|
+
""",
|
|
659
|
+
"description": "Search method definitions",
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
def get_javascript_query(name: str) -> str:
|
|
664
|
+
"""
|
|
665
|
+
Get the specified JavaScript query
|
|
666
|
+
|
|
667
|
+
Args:
|
|
668
|
+
name: Query name
|
|
669
|
+
|
|
670
|
+
Returns:
|
|
671
|
+
Query string
|
|
672
|
+
|
|
673
|
+
Raises:
|
|
674
|
+
ValueError: When query is not found
|
|
675
|
+
"""
|
|
676
|
+
if name not in JAVASCRIPT_QUERIES:
|
|
677
|
+
available = list(JAVASCRIPT_QUERIES.keys())
|
|
678
|
+
raise ValueError(
|
|
679
|
+
f"JavaScript query '{name}' does not exist. Available: {available}"
|
|
680
|
+
)
|
|
681
|
+
|
|
682
|
+
return JAVASCRIPT_QUERIES[name]
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
def get_javascript_query_description(name: str) -> str:
|
|
686
|
+
"""
|
|
687
|
+
Get the description of the specified JavaScript query
|
|
688
|
+
|
|
689
|
+
Args:
|
|
690
|
+
name: Query name
|
|
691
|
+
|
|
692
|
+
Returns:
|
|
693
|
+
Query description
|
|
694
|
+
"""
|
|
695
|
+
return JAVASCRIPT_QUERY_DESCRIPTIONS.get(name, "No description")
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
def get_query(name: str) -> str:
|
|
699
|
+
"""Get a specific query by name."""
|
|
700
|
+
if name in ALL_QUERIES:
|
|
701
|
+
return ALL_QUERIES[name]["query"]
|
|
702
|
+
raise ValueError(
|
|
703
|
+
f"Query '{name}' not found. Available queries: {list(ALL_QUERIES.keys())}"
|
|
704
|
+
)
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
def get_all_queries() -> dict:
|
|
708
|
+
"""Get all available queries."""
|
|
709
|
+
return ALL_QUERIES
|
|
710
|
+
|
|
711
|
+
|
|
712
|
+
def list_queries() -> list:
|
|
713
|
+
"""List all available query names."""
|
|
714
|
+
return list(ALL_QUERIES.keys())
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
def get_available_javascript_queries() -> list[str]:
|
|
718
|
+
"""
|
|
719
|
+
Get list of available JavaScript queries
|
|
720
|
+
|
|
721
|
+
Returns:
|
|
722
|
+
List of query names
|
|
723
|
+
"""
|
|
724
|
+
return list(JAVASCRIPT_QUERIES.keys())
|