@saluzi/codegraph 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. package/dist/bin/codegraph.d.ts +25 -0
  2. package/dist/bin/node-version-check.d.ts +37 -0
  3. package/dist/bin/uninstall.d.ts +14 -0
  4. package/dist/context/formatter.d.ts +33 -0
  5. package/dist/context/formatter.js +244 -0
  6. package/dist/context/index.d.ts +117 -0
  7. package/dist/context/index.js +1050 -0
  8. package/dist/db/index.d.ts +101 -0
  9. package/dist/db/index.js +250 -0
  10. package/dist/db/migrations.d.ts +47 -0
  11. package/dist/db/migrations.js +131 -0
  12. package/dist/db/queries.d.ts +291 -0
  13. package/dist/db/queries.js +1349 -0
  14. package/dist/db/schema.sql +151 -0
  15. package/dist/db/sqlite-adapter.d.ts +49 -0
  16. package/dist/db/sqlite-adapter.js +141 -0
  17. package/dist/directory.d.ts +62 -0
  18. package/dist/directory.js +264 -0
  19. package/dist/errors.d.ts +149 -0
  20. package/dist/errors.js +219 -0
  21. package/dist/extraction/dfm-extractor.d.ts +31 -0
  22. package/dist/extraction/dfm-extractor.js +151 -0
  23. package/dist/extraction/grammars.d.ts +94 -0
  24. package/dist/extraction/grammars.js +357 -0
  25. package/dist/extraction/index.d.ts +148 -0
  26. package/dist/extraction/index.js +1286 -0
  27. package/dist/extraction/languages/c-cpp.d.ts +4 -0
  28. package/dist/extraction/languages/c-cpp.js +126 -0
  29. package/dist/extraction/languages/csharp.d.ts +3 -0
  30. package/dist/extraction/languages/csharp.js +72 -0
  31. package/dist/extraction/languages/dart.d.ts +3 -0
  32. package/dist/extraction/languages/dart.js +192 -0
  33. package/dist/extraction/languages/go.d.ts +3 -0
  34. package/dist/extraction/languages/go.js +58 -0
  35. package/dist/extraction/languages/index.d.ts +10 -0
  36. package/dist/extraction/languages/index.js +49 -0
  37. package/dist/extraction/languages/java.d.ts +3 -0
  38. package/dist/extraction/languages/java.js +64 -0
  39. package/dist/extraction/languages/javascript.d.ts +3 -0
  40. package/dist/extraction/languages/javascript.js +90 -0
  41. package/dist/extraction/languages/kotlin.d.ts +3 -0
  42. package/dist/extraction/languages/kotlin.js +253 -0
  43. package/dist/extraction/languages/lua.d.ts +3 -0
  44. package/dist/extraction/languages/lua.js +150 -0
  45. package/dist/extraction/languages/luau.d.ts +3 -0
  46. package/dist/extraction/languages/luau.js +37 -0
  47. package/dist/extraction/languages/pascal.d.ts +3 -0
  48. package/dist/extraction/languages/pascal.js +66 -0
  49. package/dist/extraction/languages/php.d.ts +3 -0
  50. package/dist/extraction/languages/php.js +107 -0
  51. package/dist/extraction/languages/python.d.ts +3 -0
  52. package/dist/extraction/languages/python.js +56 -0
  53. package/dist/extraction/languages/ruby.d.ts +3 -0
  54. package/dist/extraction/languages/ruby.js +114 -0
  55. package/dist/extraction/languages/rust.d.ts +3 -0
  56. package/dist/extraction/languages/rust.js +109 -0
  57. package/dist/extraction/languages/scala.d.ts +3 -0
  58. package/dist/extraction/languages/scala.js +139 -0
  59. package/dist/extraction/languages/swift.d.ts +3 -0
  60. package/dist/extraction/languages/swift.js +91 -0
  61. package/dist/extraction/languages/typescript.d.ts +3 -0
  62. package/dist/extraction/languages/typescript.js +129 -0
  63. package/dist/extraction/liquid-extractor.d.ts +52 -0
  64. package/dist/extraction/liquid-extractor.js +313 -0
  65. package/dist/extraction/parse-worker.d.ts +8 -0
  66. package/dist/extraction/parse-worker.js +94 -0
  67. package/dist/extraction/svelte-extractor.d.ts +56 -0
  68. package/dist/extraction/svelte-extractor.js +272 -0
  69. package/dist/extraction/tree-sitter-helpers.d.ts +39 -0
  70. package/dist/extraction/tree-sitter-helpers.js +103 -0
  71. package/dist/extraction/tree-sitter-types.d.ts +191 -0
  72. package/dist/extraction/tree-sitter-types.js +10 -0
  73. package/dist/extraction/tree-sitter.d.ts +238 -0
  74. package/dist/extraction/tree-sitter.js +2430 -0
  75. package/dist/extraction/vue-extractor.d.ts +36 -0
  76. package/dist/extraction/vue-extractor.js +163 -0
  77. package/dist/extraction/wasm/tree-sitter-c.wasm +0 -0
  78. package/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
  79. package/dist/extraction/wasm/tree-sitter-cpp.wasm +0 -0
  80. package/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
  81. package/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
  82. package/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
  83. package/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
  84. package/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
  85. package/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
  86. package/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
  87. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  88. package/dist/extraction/wasm/tree-sitter-php.wasm +0 -0
  89. package/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
  90. package/dist/extraction/wasm/tree-sitter-ruby.wasm +0 -0
  91. package/dist/extraction/wasm/tree-sitter-rust.wasm +0 -0
  92. package/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
  93. package/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
  94. package/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
  95. package/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
  96. package/dist/extraction/wasm-runtime-flags.d.ts +46 -0
  97. package/dist/extraction/wasm-runtime-flags.js +105 -0
  98. package/dist/graph/index.d.ts +8 -0
  99. package/dist/graph/index.js +13 -0
  100. package/dist/graph/queries.d.ts +109 -0
  101. package/dist/graph/queries.js +366 -0
  102. package/dist/graph/traversal.d.ts +137 -0
  103. package/dist/graph/traversal.js +528 -0
  104. package/dist/index.d.ts +509 -0
  105. package/dist/index.js +800 -0
  106. package/dist/installer/claude-md-template.d.ts +19 -0
  107. package/dist/installer/config-writer.d.ts +29 -0
  108. package/dist/installer/index.d.ts +140 -0
  109. package/dist/installer/instructions-template.d.ts +30 -0
  110. package/dist/installer/targets/claude.d.ts +55 -0
  111. package/dist/installer/targets/codex.d.ts +18 -0
  112. package/dist/installer/targets/cursor.d.ts +35 -0
  113. package/dist/installer/targets/hermes.d.ts +18 -0
  114. package/dist/installer/targets/opencode.d.ts +30 -0
  115. package/dist/installer/targets/registry.d.ts +38 -0
  116. package/dist/installer/targets/shared.d.ts +92 -0
  117. package/dist/installer/targets/toml.d.ts +64 -0
  118. package/dist/installer/targets/types.d.ts +122 -0
  119. package/dist/mcp/index.d.ts +98 -0
  120. package/dist/mcp/server-instructions.d.ts +20 -0
  121. package/dist/mcp/tools.d.ts +269 -0
  122. package/dist/mcp/transport.d.ts +117 -0
  123. package/dist/resolution/frameworks/cargo-workspace.d.ts +20 -0
  124. package/dist/resolution/frameworks/cargo-workspace.js +225 -0
  125. package/dist/resolution/frameworks/csharp.d.ts +8 -0
  126. package/dist/resolution/frameworks/csharp.js +213 -0
  127. package/dist/resolution/frameworks/drupal.d.ts +51 -0
  128. package/dist/resolution/frameworks/drupal.js +335 -0
  129. package/dist/resolution/frameworks/express.d.ts +8 -0
  130. package/dist/resolution/frameworks/express.js +225 -0
  131. package/dist/resolution/frameworks/go.d.ts +8 -0
  132. package/dist/resolution/frameworks/go.js +158 -0
  133. package/dist/resolution/frameworks/index.d.ts +52 -0
  134. package/dist/resolution/frameworks/index.js +137 -0
  135. package/dist/resolution/frameworks/java.d.ts +8 -0
  136. package/dist/resolution/frameworks/java.js +177 -0
  137. package/dist/resolution/frameworks/laravel.d.ts +13 -0
  138. package/dist/resolution/frameworks/laravel.js +248 -0
  139. package/dist/resolution/frameworks/nestjs.d.ts +26 -0
  140. package/dist/resolution/frameworks/nestjs.js +374 -0
  141. package/dist/resolution/frameworks/python.d.ts +10 -0
  142. package/dist/resolution/frameworks/python.js +278 -0
  143. package/dist/resolution/frameworks/react.d.ts +8 -0
  144. package/dist/resolution/frameworks/react.js +272 -0
  145. package/dist/resolution/frameworks/ruby.d.ts +8 -0
  146. package/dist/resolution/frameworks/ruby.js +198 -0
  147. package/dist/resolution/frameworks/rust.d.ts +8 -0
  148. package/dist/resolution/frameworks/rust.js +207 -0
  149. package/dist/resolution/frameworks/svelte.d.ts +9 -0
  150. package/dist/resolution/frameworks/svelte.js +249 -0
  151. package/dist/resolution/frameworks/swift.d.ts +10 -0
  152. package/dist/resolution/frameworks/swift.js +376 -0
  153. package/dist/resolution/frameworks/vue.d.ts +9 -0
  154. package/dist/resolution/frameworks/vue.js +306 -0
  155. package/dist/resolution/import-resolver.d.ts +61 -0
  156. package/dist/resolution/import-resolver.js +663 -0
  157. package/dist/resolution/index.d.ts +118 -0
  158. package/dist/resolution/index.js +744 -0
  159. package/dist/resolution/lru-cache.d.ts +24 -0
  160. package/dist/resolution/lru-cache.js +62 -0
  161. package/dist/resolution/name-matcher.d.ts +50 -0
  162. package/dist/resolution/name-matcher.js +384 -0
  163. package/dist/resolution/path-aliases.d.ts +72 -0
  164. package/dist/resolution/path-aliases.js +238 -0
  165. package/dist/resolution/strip-comments.d.ts +40 -0
  166. package/dist/resolution/strip-comments.js +441 -0
  167. package/dist/resolution/types.d.ts +181 -0
  168. package/dist/resolution/types.js +8 -0
  169. package/dist/search/query-parser.d.ts +61 -0
  170. package/dist/search/query-parser.js +177 -0
  171. package/dist/search/query-utils.d.ts +59 -0
  172. package/dist/search/query-utils.js +383 -0
  173. package/dist/sync/git-hooks.d.ts +54 -0
  174. package/dist/sync/git-hooks.js +223 -0
  175. package/dist/sync/index.d.ts +25 -0
  176. package/dist/sync/index.js +28 -0
  177. package/dist/sync/watch-policy.d.ts +51 -0
  178. package/dist/sync/watch-policy.js +124 -0
  179. package/dist/sync/watcher.d.ts +83 -0
  180. package/dist/sync/watcher.js +192 -0
  181. package/dist/types.d.ts +433 -0
  182. package/dist/types.js +75 -0
  183. package/dist/ui/glyphs.d.ts +42 -0
  184. package/dist/ui/shimmer-progress.d.ts +11 -0
  185. package/dist/ui/shimmer-worker.d.ts +2 -0
  186. package/dist/ui/types.d.ts +20 -0
  187. package/dist/utils.d.ts +231 -0
  188. package/dist/utils.js +549 -0
  189. package/package.json +24 -0
@@ -0,0 +1,272 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SvelteExtractor = void 0;
4
+ const tree_sitter_helpers_1 = require("./tree-sitter-helpers");
5
+ const tree_sitter_1 = require("./tree-sitter");
6
+ const grammars_1 = require("./grammars");
7
+ /** Svelte 5 rune names — compiler builtins, not real functions */
8
+ const SVELTE_RUNES = new Set([
9
+ '$props', '$state', '$derived', '$effect', '$bindable',
10
+ '$inspect', '$host', '$snippet',
11
+ ]);
12
+ /**
13
+ * SvelteExtractor - Extracts code relationships from Svelte component files
14
+ *
15
+ * Svelte files are multi-language (script + template + style). Rather than
16
+ * parsing the full Svelte grammar, we extract the <script> block content
17
+ * and delegate it to the TypeScript/JavaScript TreeSitterExtractor.
18
+ *
19
+ * Also extracts function calls from template expressions (`{fn(...)}`) so
20
+ * cross-file call edges are captured even when calls live in markup.
21
+ *
22
+ * Every .svelte file produces a component node (Svelte components are always importable).
23
+ */
24
+ class SvelteExtractor {
25
+ filePath;
26
+ source;
27
+ nodes = [];
28
+ edges = [];
29
+ unresolvedReferences = [];
30
+ errors = [];
31
+ constructor(filePath, source) {
32
+ this.filePath = filePath;
33
+ this.source = source;
34
+ }
35
+ /**
36
+ * Extract from Svelte source
37
+ */
38
+ extract() {
39
+ const startTime = Date.now();
40
+ try {
41
+ // Create component node for the .svelte file itself
42
+ const componentNode = this.createComponentNode();
43
+ // Extract and process script blocks
44
+ const scriptBlocks = this.extractScriptBlocks();
45
+ for (const block of scriptBlocks) {
46
+ this.processScriptBlock(block, componentNode.id);
47
+ }
48
+ // Extract function calls from template expressions ({fn(...)})
49
+ this.extractTemplateCalls(componentNode.id, scriptBlocks);
50
+ // Extract component usages from template (<ComponentName>)
51
+ this.extractTemplateComponents(componentNode.id);
52
+ // Filter out Svelte rune calls ($state, $props, $derived, etc.)
53
+ this.unresolvedReferences = this.unresolvedReferences.filter(ref => !SVELTE_RUNES.has(ref.referenceName));
54
+ }
55
+ catch (error) {
56
+ this.errors.push({
57
+ message: `Svelte extraction error: ${error instanceof Error ? error.message : String(error)}`,
58
+ severity: 'error',
59
+ code: 'parse_error',
60
+ });
61
+ }
62
+ return {
63
+ nodes: this.nodes,
64
+ edges: this.edges,
65
+ unresolvedReferences: this.unresolvedReferences,
66
+ errors: this.errors,
67
+ durationMs: Date.now() - startTime,
68
+ };
69
+ }
70
+ /**
71
+ * Create a component node for the .svelte file
72
+ */
73
+ createComponentNode() {
74
+ const lines = this.source.split('\n');
75
+ const fileName = this.filePath.split(/[/\\]/).pop() || this.filePath;
76
+ const componentName = fileName.replace(/\.svelte$/, '');
77
+ const id = (0, tree_sitter_helpers_1.generateNodeId)(this.filePath, 'component', componentName, 1);
78
+ const node = {
79
+ id,
80
+ kind: 'component',
81
+ name: componentName,
82
+ qualifiedName: `${this.filePath}::${componentName}`,
83
+ filePath: this.filePath,
84
+ language: 'svelte',
85
+ startLine: 1,
86
+ endLine: lines.length,
87
+ startColumn: 0,
88
+ endColumn: lines[lines.length - 1]?.length || 0,
89
+ isExported: true, // Svelte components are always importable
90
+ updatedAt: Date.now(),
91
+ };
92
+ this.nodes.push(node);
93
+ return node;
94
+ }
95
+ /**
96
+ * Extract <script> blocks from the Svelte source
97
+ */
98
+ extractScriptBlocks() {
99
+ const blocks = [];
100
+ const scriptRegex = /<script(\s[^>]*)?>(?<content>[\s\S]*?)<\/script>/g;
101
+ let match;
102
+ while ((match = scriptRegex.exec(this.source)) !== null) {
103
+ const attrs = match[1] || '';
104
+ const content = match.groups?.content || match[2] || '';
105
+ // Detect TypeScript from lang attribute
106
+ const isTypeScript = /lang\s*=\s*["'](ts|typescript)["']/.test(attrs);
107
+ // Detect module script
108
+ const isModule = /context\s*=\s*["']module["']/.test(attrs);
109
+ // Calculate start line of the script content (line after <script>)
110
+ const beforeScript = this.source.substring(0, match.index);
111
+ const scriptTagLine = (beforeScript.match(/\n/g) || []).length;
112
+ // The content starts on the line after the opening <script> tag
113
+ const openingTag = match[0].substring(0, match[0].indexOf('>') + 1);
114
+ const openingTagLines = (openingTag.match(/\n/g) || []).length;
115
+ const contentStartLine = scriptTagLine + openingTagLines + 1; // 0-indexed line
116
+ blocks.push({
117
+ content,
118
+ startLine: contentStartLine,
119
+ isModule,
120
+ isTypeScript,
121
+ });
122
+ }
123
+ return blocks;
124
+ }
125
+ /**
126
+ * Process a script block by delegating to TreeSitterExtractor
127
+ */
128
+ processScriptBlock(block, componentNodeId) {
129
+ const scriptLanguage = block.isTypeScript ? 'typescript' : 'javascript';
130
+ // Check if the script language parser is available
131
+ if (!(0, grammars_1.isLanguageSupported)(scriptLanguage)) {
132
+ this.errors.push({
133
+ message: `Parser for ${scriptLanguage} not available, cannot parse Svelte script block`,
134
+ severity: 'warning',
135
+ });
136
+ return;
137
+ }
138
+ // Delegate to TreeSitterExtractor
139
+ const extractor = new tree_sitter_1.TreeSitterExtractor(this.filePath, block.content, scriptLanguage);
140
+ const result = extractor.extract();
141
+ // Offset line numbers from script block back to .svelte file positions
142
+ for (const node of result.nodes) {
143
+ node.startLine += block.startLine;
144
+ node.endLine += block.startLine;
145
+ node.language = 'svelte'; // Mark as svelte, not TS/JS
146
+ this.nodes.push(node);
147
+ // Add containment edge from component to this node
148
+ this.edges.push({
149
+ source: componentNodeId,
150
+ target: node.id,
151
+ kind: 'contains',
152
+ });
153
+ }
154
+ // Offset edges (they reference line numbers)
155
+ for (const edge of result.edges) {
156
+ if (edge.line) {
157
+ edge.line += block.startLine;
158
+ }
159
+ this.edges.push(edge);
160
+ }
161
+ // Offset unresolved references
162
+ for (const ref of result.unresolvedReferences) {
163
+ ref.line += block.startLine;
164
+ ref.filePath = this.filePath;
165
+ ref.language = 'svelte';
166
+ this.unresolvedReferences.push(ref);
167
+ }
168
+ // Carry over errors
169
+ for (const error of result.errors) {
170
+ if (error.line) {
171
+ error.line += block.startLine;
172
+ }
173
+ this.errors.push(error);
174
+ }
175
+ }
176
+ /**
177
+ * Extract function calls from Svelte template expressions.
178
+ *
179
+ * In Svelte, many function calls happen in markup (e.g., `class={cn(...)}`),
180
+ * not inside `<script>` blocks. We scan the template portion for `{expression}`
181
+ * blocks and extract call patterns from them.
182
+ */
183
+ extractTemplateCalls(componentNodeId, _scriptBlocks) {
184
+ // Build a set of line ranges covered by <script> and <style> blocks so we skip them
185
+ const coveredRanges = [];
186
+ // Find all <script>...</script> and <style>...</style> ranges
187
+ const tagRegex = /<(script|style)(\s[^>]*)?>[\s\S]*?<\/\1>/g;
188
+ let tagMatch;
189
+ while ((tagMatch = tagRegex.exec(this.source)) !== null) {
190
+ const startLine = (this.source.substring(0, tagMatch.index).match(/\n/g) || []).length;
191
+ const endLine = startLine + (tagMatch[0].match(/\n/g) || []).length;
192
+ coveredRanges.push([startLine, endLine]);
193
+ }
194
+ // Find template expressions: {...} outside of script/style blocks
195
+ // Matches curly-brace expressions, excluding Svelte block syntax ({#if}, {:else}, {/if}, {@html}, {@render})
196
+ const lines = this.source.split('\n');
197
+ const exprRegex = /\{([^}#/:@][^}]*)\}/g;
198
+ for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
199
+ // Skip lines inside script/style blocks
200
+ if (coveredRanges.some(([start, end]) => lineIdx >= start && lineIdx <= end))
201
+ continue;
202
+ const line = lines[lineIdx];
203
+ let exprMatch;
204
+ while ((exprMatch = exprRegex.exec(line)) !== null) {
205
+ const expr = exprMatch[1];
206
+ // Extract function calls: identifiers followed by (
207
+ // Matches: cn(...), buttonVariants(...), obj.method(...)
208
+ const callRegex = /\b([a-zA-Z_$][\w$.]*)\s*\(/g;
209
+ let callMatch;
210
+ while ((callMatch = callRegex.exec(expr)) !== null) {
211
+ const calleeName = callMatch[1];
212
+ // Skip Svelte runes, control flow keywords, and common non-function patterns
213
+ if (SVELTE_RUNES.has(calleeName))
214
+ continue;
215
+ if (calleeName === 'if' || calleeName === 'else' || calleeName === 'each' || calleeName === 'await')
216
+ continue;
217
+ this.unresolvedReferences.push({
218
+ fromNodeId: componentNodeId,
219
+ referenceName: calleeName,
220
+ referenceKind: 'calls',
221
+ line: lineIdx + 1, // 1-indexed
222
+ column: exprMatch.index + callMatch.index,
223
+ filePath: this.filePath,
224
+ language: 'svelte',
225
+ });
226
+ }
227
+ }
228
+ }
229
+ }
230
+ /**
231
+ * Extract component usages from the Svelte template.
232
+ *
233
+ * PascalCase tags like <Modal>, <Button />, <DevServerPreview> represent
234
+ * component instantiations — analogous to function calls in imperative code.
235
+ * Capturing these creates graph edges from parent to child components and
236
+ * gives codegraph_explore anchor points in the template markup.
237
+ */
238
+ extractTemplateComponents(componentNodeId) {
239
+ // Build ranges covered by <script> and <style> blocks to skip them
240
+ const coveredRanges = [];
241
+ const tagRegex = /<(script|style)(\s[^>]*)?>[\s\S]*?<\/\1>/g;
242
+ let tagMatch;
243
+ while ((tagMatch = tagRegex.exec(this.source)) !== null) {
244
+ const startLine = (this.source.substring(0, tagMatch.index).match(/\n/g) || []).length;
245
+ const endLine = startLine + (tagMatch[0].match(/\n/g) || []).length;
246
+ coveredRanges.push([startLine, endLine]);
247
+ }
248
+ const lines = this.source.split('\n');
249
+ // Match PascalCase opening/self-closing tags (closing tags </Foo> start with </ so won't match)
250
+ const componentTagRegex = /<([A-Z][a-zA-Z0-9_$]*)\b/g;
251
+ for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
252
+ if (coveredRanges.some(([start, end]) => lineIdx >= start && lineIdx <= end))
253
+ continue;
254
+ const line = lines[lineIdx];
255
+ let match;
256
+ while ((match = componentTagRegex.exec(line)) !== null) {
257
+ const componentName = match[1];
258
+ this.unresolvedReferences.push({
259
+ fromNodeId: componentNodeId,
260
+ referenceName: componentName,
261
+ referenceKind: 'references',
262
+ line: lineIdx + 1, // 1-indexed
263
+ column: match.index + 1,
264
+ filePath: this.filePath,
265
+ language: 'svelte',
266
+ });
267
+ }
268
+ }
269
+ }
270
+ }
271
+ exports.SvelteExtractor = SvelteExtractor;
272
+ //# sourceMappingURL=svelte-extractor.js.map
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Tree-sitter Shared Helpers
3
+ *
4
+ * Utility functions used by the core TreeSitterExtractor and per-language extractors.
5
+ * Extracted to a leaf module to avoid circular imports between tree-sitter.ts and languages/.
6
+ */
7
+ import { Node as SyntaxNode } from 'web-tree-sitter'
8
+ import { NodeKind } from '../types'
9
+ /**
10
+ * Generate a unique node ID
11
+ *
12
+ * Uses a 32-character (128-bit) hash to avoid collisions when indexing
13
+ * large codebases with many files containing similar symbols.
14
+ */
15
+ export declare function generateNodeId(
16
+ filePath: string,
17
+ kind: NodeKind,
18
+ name: string,
19
+ line: number,
20
+ ): string
21
+ /**
22
+ * Extract text from a syntax node
23
+ */
24
+ export declare function getNodeText(node: SyntaxNode, source: string): string
25
+ /**
26
+ * Find a child node by field name
27
+ */
28
+ export declare function getChildByField(
29
+ node: SyntaxNode,
30
+ fieldName: string,
31
+ ): SyntaxNode | null
32
+ /**
33
+ * Get the docstring/comment preceding a node
34
+ */
35
+ export declare function getPrecedingDocstring(
36
+ node: SyntaxNode,
37
+ source: string,
38
+ ): string | undefined
39
+ //# sourceMappingURL=tree-sitter-helpers.d.ts.map
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ /**
3
+ * Tree-sitter Shared Helpers
4
+ *
5
+ * Utility functions used by the core TreeSitterExtractor and per-language extractors.
6
+ * Extracted to a leaf module to avoid circular imports between tree-sitter.ts and languages/.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.generateNodeId = generateNodeId;
43
+ exports.getNodeText = getNodeText;
44
+ exports.getChildByField = getChildByField;
45
+ exports.getPrecedingDocstring = getPrecedingDocstring;
46
+ const crypto = __importStar(require("crypto"));
47
+ /**
48
+ * Generate a unique node ID
49
+ *
50
+ * Uses a 32-character (128-bit) hash to avoid collisions when indexing
51
+ * large codebases with many files containing similar symbols.
52
+ */
53
+ function generateNodeId(filePath, kind, name, line) {
54
+ const hash = crypto
55
+ .createHash('sha256')
56
+ .update(`${filePath}:${kind}:${name}:${line}`)
57
+ .digest('hex')
58
+ .substring(0, 32);
59
+ return `${kind}:${hash}`;
60
+ }
61
+ /**
62
+ * Extract text from a syntax node
63
+ */
64
+ function getNodeText(node, source) {
65
+ return source.substring(node.startIndex, node.endIndex);
66
+ }
67
+ /**
68
+ * Find a child node by field name
69
+ */
70
+ function getChildByField(node, fieldName) {
71
+ return node.childForFieldName(fieldName);
72
+ }
73
+ /**
74
+ * Get the docstring/comment preceding a node
75
+ */
76
+ function getPrecedingDocstring(node, source) {
77
+ let sibling = node.previousNamedSibling;
78
+ const comments = [];
79
+ while (sibling) {
80
+ if (sibling.type === 'comment' ||
81
+ sibling.type === 'line_comment' ||
82
+ sibling.type === 'block_comment' ||
83
+ sibling.type === 'documentation_comment') {
84
+ comments.unshift(getNodeText(sibling, source));
85
+ sibling = sibling.previousNamedSibling;
86
+ }
87
+ else {
88
+ break;
89
+ }
90
+ }
91
+ if (comments.length === 0)
92
+ return undefined;
93
+ // Clean up comment markers
94
+ return comments
95
+ .map((c) => c
96
+ .replace(/^\/\*\*?|\*\/$/g, '')
97
+ .replace(/^\/\/\s?/gm, '')
98
+ .replace(/^\s*\*\s?/gm, '')
99
+ .trim())
100
+ .join('\n')
101
+ .trim();
102
+ }
103
+ //# sourceMappingURL=tree-sitter-helpers.js.map
@@ -0,0 +1,191 @@
1
+ /**
2
+ * Tree-sitter Extraction Types
3
+ *
4
+ * Defines the LanguageExtractor interface and related types used by
5
+ * the core TreeSitterExtractor and per-language extraction configs.
6
+ * Extracted to a leaf module to avoid circular imports.
7
+ */
8
+ import { Node as SyntaxNode } from 'web-tree-sitter'
9
+ import { Node, NodeKind, UnresolvedReference } from '../types'
10
+ /**
11
+ * Information returned by a language's extractImport hook.
12
+ */
13
+ export interface ImportInfo {
14
+ /** The module/package name being imported */
15
+ moduleName: string
16
+ /** Full import statement text for display */
17
+ signature: string
18
+ /** If true, the hook already created unresolved references itself */
19
+ handledRefs?: boolean
20
+ }
21
+ /**
22
+ * Information about a single variable within a declaration.
23
+ * Returned by a language's extractVariables hook.
24
+ */
25
+ export interface VariableInfo {
26
+ /** Variable name */
27
+ name: string
28
+ /** Node kind: 'variable' or 'constant' */
29
+ kind: NodeKind
30
+ /** Optional signature string */
31
+ signature?: string
32
+ /** If set, this declarator is actually a function and should be extracted as such */
33
+ delegateToFunction?: SyntaxNode
34
+ /** The AST node to use for positioning (may differ from the declaration node) */
35
+ positionNode?: SyntaxNode
36
+ }
37
+ /**
38
+ * Context object passed to language hooks that need to call back into the core extractor.
39
+ * Provides a controlled API surface — hooks can create nodes, visit children, and add
40
+ * references without accessing the full TreeSitterExtractor internals.
41
+ */
42
+ export interface ExtractorContext {
43
+ /** Create a node and add it to the extraction result */
44
+ createNode(
45
+ kind: NodeKind,
46
+ name: string,
47
+ node: SyntaxNode,
48
+ extra?: Partial<Node>,
49
+ ): Node | null
50
+ /** Visit a child node (dispatches through the standard visitNode logic) */
51
+ visitNode(node: SyntaxNode): void
52
+ /** Visit a function body to extract calls */
53
+ visitFunctionBody(body: SyntaxNode, functionId: string): void
54
+ /** Add an unresolved reference */
55
+ addUnresolvedReference(ref: UnresolvedReference): void
56
+ /** Push a node ID onto the scope stack (for containment/qualified name building) */
57
+ pushScope(nodeId: string): void
58
+ /** Pop the last node ID from the scope stack */
59
+ popScope(): void
60
+ /** Current file path */
61
+ readonly filePath: string
62
+ /** Current source text */
63
+ readonly source: string
64
+ /** Stack of parent node IDs (current scope) */
65
+ readonly nodeStack: readonly string[]
66
+ /** All nodes extracted so far */
67
+ readonly nodes: readonly Node[]
68
+ }
69
+ /**
70
+ * Language-specific extraction configuration.
71
+ *
72
+ * Each supported language provides an implementation of this interface
73
+ * that configures which AST node types to look for and how to extract
74
+ * language-specific details like signatures, visibility, and imports.
75
+ */
76
+ export interface LanguageExtractor {
77
+ /** Node types that represent functions */
78
+ functionTypes: string[]
79
+ /** Node types that represent classes */
80
+ classTypes: string[]
81
+ /** Node types that represent methods */
82
+ methodTypes: string[]
83
+ /** Node types that represent interfaces/protocols/traits */
84
+ interfaceTypes: string[]
85
+ /** Node types that represent structs */
86
+ structTypes: string[]
87
+ /** Node types that represent enums */
88
+ enumTypes: string[]
89
+ /** Node types that represent enum members/cases (e.g. Swift: 'enum_entry', Rust: 'enum_variant') */
90
+ enumMemberTypes?: string[]
91
+ /** Node types that represent type aliases (e.g. `type X = ...`) */
92
+ typeAliasTypes: string[]
93
+ /** Node types that represent imports */
94
+ importTypes: string[]
95
+ /** Node types that represent function calls */
96
+ callTypes: string[]
97
+ /** Node types that represent variable declarations (const, let, var, etc.) */
98
+ variableTypes: string[]
99
+ /** Node types that represent class fields (extracted as 'field' kind inside class bodies) */
100
+ fieldTypes?: string[]
101
+ /** Node types that represent class properties (extracted as 'property' kind inside class bodies) */
102
+ propertyTypes?: string[]
103
+ /** Field name for identifier/name */
104
+ nameField: string
105
+ /** Field name for body */
106
+ bodyField: string
107
+ /** Field name for parameters */
108
+ paramsField: string
109
+ /** Field name for return type */
110
+ returnField?: string
111
+ /** Extract signature from node */
112
+ getSignature?: (node: SyntaxNode, source: string) => string | undefined
113
+ /** Extract visibility from node */
114
+ getVisibility?: (
115
+ node: SyntaxNode,
116
+ ) => 'public' | 'private' | 'protected' | 'internal' | undefined
117
+ /** Check if node is exported */
118
+ isExported?: (node: SyntaxNode, source: string) => boolean
119
+ /** Check if node is async */
120
+ isAsync?: (node: SyntaxNode) => boolean
121
+ /** Check if node is static */
122
+ isStatic?: (node: SyntaxNode) => boolean
123
+ /** Check if variable declaration is a constant (const vs let/var) */
124
+ isConst?: (node: SyntaxNode) => boolean
125
+ /** Additional node types to treat as class declarations (e.g. Dart: 'mixin_declaration') */
126
+ extraClassNodeTypes?: string[]
127
+ /** Whether methods can be top-level without enclosing class (Go: true) */
128
+ methodsAreTopLevel?: boolean
129
+ /** NodeKind to use for interface-like declarations (Rust: 'trait'). Default: 'interface' */
130
+ interfaceKind?: NodeKind
131
+ /**
132
+ * Custom node visitor. Return true if the node was fully handled (skip default dispatch).
133
+ * Used by languages with fundamentally different AST structures (e.g. Pascal).
134
+ */
135
+ visitNode?: (node: SyntaxNode, ctx: ExtractorContext) => boolean
136
+ /**
137
+ * Classify a class_declaration node when the grammar reuses one node type
138
+ * for multiple concepts (e.g. Swift uses class_declaration for classes, structs, and enums).
139
+ */
140
+ classifyClassNode?: (
141
+ node: SyntaxNode,
142
+ ) => 'class' | 'struct' | 'enum' | 'interface' | 'trait'
143
+ /**
144
+ * Resolve the body node for a function/method/class when it's not a child field.
145
+ * (e.g. Dart puts function_body as a sibling, not a child.)
146
+ */
147
+ resolveBody?: (node: SyntaxNode, bodyField: string) => SyntaxNode | null
148
+ /**
149
+ * Extract import information from an import node.
150
+ * Return null if the node isn't a recognized import form.
151
+ */
152
+ extractImport?: (node: SyntaxNode, source: string) => ImportInfo | null
153
+ /**
154
+ * Extract variable declarations from a variable declaration node.
155
+ * Returns info about each declared variable, allowing the core to create nodes.
156
+ */
157
+ extractVariables?: (node: SyntaxNode, source: string) => VariableInfo[]
158
+ /**
159
+ * Extract receiver/owner type name from a method declaration.
160
+ * Used by Go to get the struct receiver (e.g., "scrapeLoop" from "func (sl *scrapeLoop) run()").
161
+ * When present, the receiver type is included in the qualified name for better searchability.
162
+ */
163
+ getReceiverType?: (node: SyntaxNode, source: string) => string | undefined
164
+ /**
165
+ * Resolve the actual node kind for a type alias declaration.
166
+ * Used by Go where `type_spec` is the named declaration wrapper for structs/interfaces:
167
+ * `type Foo struct { ... }` → type_spec (name: "Foo") → struct_type
168
+ * Returns 'struct', 'interface', etc. to override the default 'type_alias' kind,
169
+ * or undefined to keep it as a type alias.
170
+ */
171
+ resolveTypeAliasKind?: (
172
+ node: SyntaxNode,
173
+ source: string,
174
+ ) => NodeKind | undefined
175
+ /**
176
+ * Check if a function/method name is a misparse artifact that should be skipped.
177
+ * Used by C/C++ where macros (e.g. NLOHMANN_JSON_NAMESPACE_BEGIN) cause tree-sitter
178
+ * to misparse namespace blocks as function_definitions. When this returns true,
179
+ * the function node is NOT created, but the body is still visited for calls and
180
+ * structural nodes (classes, structs, enums).
181
+ */
182
+ isMisparsedFunction?: (name: string, node: SyntaxNode) => boolean
183
+ /**
184
+ * Detect bare method calls that don't use call expression syntax.
185
+ * Used by Ruby where `reset` (no parens, no receiver) is a method call but
186
+ * tree-sitter parses it as a plain `identifier` node instead of `call`/`method_call`.
187
+ * Returns the callee name if this node is a bare call, or undefined if not.
188
+ */
189
+ extractBareCall?: (node: SyntaxNode, source: string) => string | undefined
190
+ }
191
+ //# sourceMappingURL=tree-sitter-types.d.ts.map
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ /**
3
+ * Tree-sitter Extraction Types
4
+ *
5
+ * Defines the LanguageExtractor interface and related types used by
6
+ * the core TreeSitterExtractor and per-language extraction configs.
7
+ * Extracted to a leaf module to avoid circular imports.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ //# sourceMappingURL=tree-sitter-types.js.map