@aiready/core 0.24.22 → 0.24.25
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/chunk-3GCIM6XG.mjs +904 -0
- package/dist/chunk-3S5WU6KX.mjs +552 -0
- package/dist/chunk-4OMXBYX7.mjs +167 -0
- package/dist/chunk-6YWGFKZG.mjs +250 -0
- package/dist/chunk-A3BIROBZ.mjs +902 -0
- package/dist/chunk-BYMQDORS.mjs +256 -0
- package/dist/chunk-CBZNRNEF.mjs +309 -0
- package/dist/chunk-ET2WRQSM.mjs +262 -0
- package/dist/chunk-F4FTHFHK.mjs +552 -0
- package/dist/chunk-G737F72Q.mjs +256 -0
- package/dist/chunk-GVFUAIWU.mjs +864 -0
- package/dist/chunk-KSEA5XDH.mjs +894 -0
- package/dist/chunk-LMIZRJFV.mjs +256 -0
- package/dist/chunk-LRPBPWBM.mjs +170 -0
- package/dist/chunk-MOTBXU6W.mjs +902 -0
- package/dist/chunk-OAH6FVVF.mjs +919 -0
- package/dist/chunk-OCM6HLBM.mjs +262 -0
- package/dist/chunk-OFBRNGKT.mjs +893 -0
- package/dist/chunk-P3KYGPO4.mjs +262 -0
- package/dist/chunk-PNWSO6XQ.mjs +250 -0
- package/dist/chunk-SO6UKAPR.mjs +164 -0
- package/dist/chunk-T2FW6AAF.mjs +552 -0
- package/dist/chunk-TQX77RIC.mjs +250 -0
- package/dist/chunk-X64EJ3ZO.mjs +314 -0
- package/dist/client/index.d.mts +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +32 -5
- package/dist/client/index.mjs +1 -1
- package/dist/csharp-parser-3CGM6FKB.mjs +9 -0
- package/dist/csharp-parser-UWRUYHUH.mjs +9 -0
- package/dist/csharp-parser-WIAIE3DD.mjs +9 -0
- package/dist/go-parser-AH5QNS4O.mjs +9 -0
- package/dist/go-parser-CSAB23BL.mjs +9 -0
- package/dist/go-parser-Q3HI32B7.mjs +9 -0
- package/dist/index-CL_0jxiJ.d.mts +1315 -0
- package/dist/index-CL_0jxiJ.d.ts +1315 -0
- package/dist/index-ClwnZa_Y.d.mts +1333 -0
- package/dist/index-ClwnZa_Y.d.ts +1333 -0
- package/dist/index-DC0cdf0g.d.mts +1321 -0
- package/dist/index-DC0cdf0g.d.ts +1321 -0
- package/dist/index-DKqKGhcJ.d.mts +1309 -0
- package/dist/index-DKqKGhcJ.d.ts +1309 -0
- package/dist/index-DNnlhdk0.d.mts +1318 -0
- package/dist/index-DNnlhdk0.d.ts +1318 -0
- package/dist/index-De2xy_k5.d.mts +1326 -0
- package/dist/index-De2xy_k5.d.ts +1326 -0
- package/dist/index.d.mts +104 -20
- package/dist/index.d.ts +104 -20
- package/dist/index.js +581 -147
- package/dist/index.mjs +507 -134
- package/dist/java-parser-GUKWCEYS.mjs +9 -0
- package/dist/java-parser-XTWT5Y5I.mjs +9 -0
- package/dist/java-parser-YP5XWLQK.mjs +9 -0
- package/dist/python-parser-AOPXUEIV.mjs +8 -0
- package/dist/python-parser-FB55P6UA.mjs +8 -0
- package/dist/python-parser-WIJPSRKC.mjs +8 -0
- package/dist/typescript-parser-5ZWLLMWJ.mjs +7 -0
- package/dist/typescript-parser-TWPRLYK6.mjs +7 -0
- package/package.json +5 -1
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import {
|
|
2
|
+
analyzeGeneralMetadata,
|
|
3
|
+
extractParameterNames
|
|
4
|
+
} from "./chunk-3D3I5K5W.mjs";
|
|
5
|
+
import {
|
|
6
|
+
BaseLanguageParser
|
|
7
|
+
} from "./chunk-SO6UKAPR.mjs";
|
|
8
|
+
|
|
9
|
+
// src/parsers/csharp-parser.ts
|
|
10
|
+
var CSharpParser = class extends BaseLanguageParser {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this.language = "csharp" /* CSharp */;
|
|
14
|
+
this.extensions = [".cs"];
|
|
15
|
+
}
|
|
16
|
+
getParserName() {
|
|
17
|
+
return "c_sharp";
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Analyze metadata for a C# node (purity, side effects).
|
|
21
|
+
*
|
|
22
|
+
* @param node - Tree-sitter node to analyze.
|
|
23
|
+
* @param code - Source code for context.
|
|
24
|
+
* @returns Partial ExportInfo containing discovered metadata.
|
|
25
|
+
*/
|
|
26
|
+
analyzeMetadata(node, code) {
|
|
27
|
+
return analyzeGeneralMetadata(node, code, {
|
|
28
|
+
sideEffectSignatures: ["Console.Write", "File.Write", "Logging."]
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Fallback regex-based parsing when tree-sitter is unavailable.
|
|
33
|
+
*
|
|
34
|
+
* @param code - Source code content.
|
|
35
|
+
* @returns Consolidated ParseResult.
|
|
36
|
+
*/
|
|
37
|
+
parseRegex(code) {
|
|
38
|
+
const lines = code.split("\n");
|
|
39
|
+
const exports = [];
|
|
40
|
+
const imports = [];
|
|
41
|
+
const usingRegex = /^using\s+([a-zA-Z0-9_.]+);/;
|
|
42
|
+
const classRegex = /^\s*(?:public\s+)?class\s+([a-zA-Z0-9_]+)/;
|
|
43
|
+
const methodRegex = /^\s*(?:public|protected)\s+(?:static\s+)?[a-zA-Z0-9_.]+\s+([a-zA-Z0-9_]+)\s*\(/;
|
|
44
|
+
let currentClassName = "";
|
|
45
|
+
lines.forEach((line, idx) => {
|
|
46
|
+
const usingMatch = line.match(usingRegex);
|
|
47
|
+
if (usingMatch) {
|
|
48
|
+
const source = usingMatch[1];
|
|
49
|
+
imports.push({
|
|
50
|
+
source,
|
|
51
|
+
specifiers: [source.split(".").pop() || source],
|
|
52
|
+
loc: {
|
|
53
|
+
start: { line: idx + 1, column: 0 },
|
|
54
|
+
end: { line: idx + 1, column: line.length }
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const classMatch = line.match(classRegex);
|
|
59
|
+
if (classMatch) {
|
|
60
|
+
currentClassName = classMatch[1];
|
|
61
|
+
exports.push({
|
|
62
|
+
name: currentClassName,
|
|
63
|
+
type: "class",
|
|
64
|
+
visibility: "public",
|
|
65
|
+
isPure: true,
|
|
66
|
+
hasSideEffects: false,
|
|
67
|
+
loc: {
|
|
68
|
+
start: { line: idx + 1, column: 0 },
|
|
69
|
+
end: { line: idx + 1, column: line.length }
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const methodMatch = line.match(methodRegex);
|
|
74
|
+
if (methodMatch && currentClassName) {
|
|
75
|
+
const name = methodMatch[1];
|
|
76
|
+
const isImpure = name.toLowerCase().includes("impure") || line.includes("Console.WriteLine");
|
|
77
|
+
exports.push({
|
|
78
|
+
name,
|
|
79
|
+
type: "function",
|
|
80
|
+
parentClass: currentClassName,
|
|
81
|
+
visibility: "public",
|
|
82
|
+
isPure: !isImpure,
|
|
83
|
+
hasSideEffects: isImpure,
|
|
84
|
+
loc: {
|
|
85
|
+
start: { line: idx + 1, column: 0 },
|
|
86
|
+
end: { line: idx + 1, column: line.length }
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
exports,
|
|
93
|
+
imports,
|
|
94
|
+
language: "csharp" /* CSharp */,
|
|
95
|
+
warnings: ["Parser falling back to regex-based analysis"]
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Extract import information (usings) using AST walk.
|
|
100
|
+
*
|
|
101
|
+
* @param rootNode - Root node of the C# AST.
|
|
102
|
+
* @returns Array of discovered FileImport objects.
|
|
103
|
+
*/
|
|
104
|
+
extractImportsAST(rootNode) {
|
|
105
|
+
const imports = [];
|
|
106
|
+
const findUsings = (node) => {
|
|
107
|
+
if (node.type === "using_directive") {
|
|
108
|
+
const nameNode = node.childForFieldName("name") || node.children.find(
|
|
109
|
+
(c) => c.type === "qualified_name" || c.type === "identifier"
|
|
110
|
+
);
|
|
111
|
+
if (nameNode) {
|
|
112
|
+
const aliasNode = node.childForFieldName("alias");
|
|
113
|
+
imports.push({
|
|
114
|
+
source: nameNode.text,
|
|
115
|
+
specifiers: aliasNode ? [aliasNode.text] : [nameNode.text.split(".").pop() || nameNode.text],
|
|
116
|
+
loc: {
|
|
117
|
+
start: {
|
|
118
|
+
line: node.startPosition.row + 1,
|
|
119
|
+
column: node.startPosition.column
|
|
120
|
+
},
|
|
121
|
+
end: {
|
|
122
|
+
line: node.endPosition.row + 1,
|
|
123
|
+
column: node.endPosition.column
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
130
|
+
const child = node.child(i);
|
|
131
|
+
if (child) findUsings(child);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
findUsings(rootNode);
|
|
135
|
+
return imports;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Extract export information (classes, methods, properties) using AST walk.
|
|
139
|
+
* Handles nested namespaces and classes.
|
|
140
|
+
*
|
|
141
|
+
* @param rootNode - Root node of the C# AST.
|
|
142
|
+
* @param code - Source code for documentation extraction.
|
|
143
|
+
* @returns Array of discovered ExportInfo objects.
|
|
144
|
+
*/
|
|
145
|
+
extractExportsAST(rootNode, code) {
|
|
146
|
+
const exports = [];
|
|
147
|
+
const traverse = (node, currentNamespace, currentClass) => {
|
|
148
|
+
let nextNamespace = currentNamespace;
|
|
149
|
+
let nextClass = currentClass;
|
|
150
|
+
if (node.type === "namespace_declaration" || node.type === "file_scoped_namespace_declaration") {
|
|
151
|
+
const nameNode = node.childForFieldName("name") || node.children.find(
|
|
152
|
+
(c) => c.type === "identifier" || c.type === "qualified_name"
|
|
153
|
+
);
|
|
154
|
+
if (nameNode) {
|
|
155
|
+
nextNamespace = currentNamespace ? `${currentNamespace}.${nameNode.text}` : nameNode.text;
|
|
156
|
+
}
|
|
157
|
+
} else if (node.type === "class_declaration" || node.type === "interface_declaration" || node.type === "enum_declaration" || node.type === "struct_declaration" || node.type === "record_declaration") {
|
|
158
|
+
const nameNode = node.childForFieldName("name") || node.children.find((c) => c.type === "identifier");
|
|
159
|
+
if (nameNode) {
|
|
160
|
+
const modifiers = this.getModifiers(node);
|
|
161
|
+
const isPublic = modifiers.includes("public") || modifiers.includes("protected");
|
|
162
|
+
if (isPublic) {
|
|
163
|
+
const metadata = this.analyzeMetadata(node, code);
|
|
164
|
+
const nodeType = node.type.replace("_declaration", "");
|
|
165
|
+
let exportType = "class";
|
|
166
|
+
if (nodeType === "record" || nodeType === "struct" || nodeType === "enum") {
|
|
167
|
+
exportType = "class";
|
|
168
|
+
} else if (nodeType === "interface" || nodeType === "interface_declaration") {
|
|
169
|
+
exportType = "interface";
|
|
170
|
+
}
|
|
171
|
+
const fullName = nextClass ? `${nextClass}.${nameNode.text}` : nextNamespace ? `${nextNamespace}.${nameNode.text}` : nameNode.text;
|
|
172
|
+
const exportItem = {
|
|
173
|
+
name: fullName,
|
|
174
|
+
type: exportType,
|
|
175
|
+
loc: {
|
|
176
|
+
start: {
|
|
177
|
+
line: node.startPosition.row + 1,
|
|
178
|
+
column: node.startPosition.column
|
|
179
|
+
},
|
|
180
|
+
end: {
|
|
181
|
+
line: node.endPosition.row + 1,
|
|
182
|
+
column: node.endPosition.column
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
visibility: modifiers.includes("public") ? "public" : "protected",
|
|
186
|
+
...metadata
|
|
187
|
+
};
|
|
188
|
+
exports.push(exportItem);
|
|
189
|
+
nextClass = fullName;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
} else if (node.type === "method_declaration" || node.type === "property_declaration") {
|
|
193
|
+
const nameNode = node.childForFieldName("name") || node.children.find((c) => c.type === "identifier");
|
|
194
|
+
if (nameNode) {
|
|
195
|
+
const modifiers = this.getModifiers(node);
|
|
196
|
+
const isPublic = modifiers.includes("public") || modifiers.includes("protected");
|
|
197
|
+
if (isPublic) {
|
|
198
|
+
const metadata = this.analyzeMetadata(node, code);
|
|
199
|
+
const methodItem = {
|
|
200
|
+
name: nameNode.text,
|
|
201
|
+
type: node.type === "method_declaration" ? "function" : "variable",
|
|
202
|
+
parentClass: currentClass,
|
|
203
|
+
loc: {
|
|
204
|
+
start: {
|
|
205
|
+
line: node.startPosition.row + 1,
|
|
206
|
+
column: node.startPosition.column
|
|
207
|
+
},
|
|
208
|
+
end: {
|
|
209
|
+
line: node.endPosition.row + 1,
|
|
210
|
+
column: node.endPosition.column
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
visibility: modifiers.includes("public") ? "public" : "protected",
|
|
214
|
+
parameters: node.type === "method_declaration" ? this.extractParameters(node) : void 0,
|
|
215
|
+
...metadata
|
|
216
|
+
};
|
|
217
|
+
exports.push(methodItem);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
222
|
+
const child = node.child(i);
|
|
223
|
+
if (child) traverse(child, nextNamespace, nextClass);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
traverse(rootNode);
|
|
227
|
+
return exports;
|
|
228
|
+
}
|
|
229
|
+
getModifiers(node) {
|
|
230
|
+
const modifiers = [];
|
|
231
|
+
for (const child of node.children) {
|
|
232
|
+
if (child.type === "modifier") {
|
|
233
|
+
modifiers.push(child.text);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return modifiers;
|
|
237
|
+
}
|
|
238
|
+
extractParameters(node) {
|
|
239
|
+
return extractParameterNames(node);
|
|
240
|
+
}
|
|
241
|
+
getNamingConventions() {
|
|
242
|
+
return {
|
|
243
|
+
variablePattern: /^[a-z][a-zA-Z0-9]*$/,
|
|
244
|
+
functionPattern: /^[A-Z][a-zA-Z0-9]*$/,
|
|
245
|
+
classPattern: /^[A-Z][a-zA-Z0-9]*$/,
|
|
246
|
+
constantPattern: /^[A-Z][a-zA-Z0-9_]*$/
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
canHandle(filePath) {
|
|
250
|
+
return filePath.toLowerCase().endsWith(".cs");
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
export {
|
|
255
|
+
CSharpParser
|
|
256
|
+
};
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// src/utils/path-utils.ts
|
|
2
|
+
import { dirname } from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
function getDirname(importMetaUrl) {
|
|
5
|
+
if (importMetaUrl) {
|
|
6
|
+
return dirname(fileURLToPath(importMetaUrl));
|
|
7
|
+
}
|
|
8
|
+
if (typeof __dirname !== "undefined") {
|
|
9
|
+
return __dirname;
|
|
10
|
+
}
|
|
11
|
+
throw new Error("getDirname: importMetaUrl is required in ESM environments");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// src/parsers/tree-sitter-utils.ts
|
|
15
|
+
import * as Parser from "web-tree-sitter";
|
|
16
|
+
import * as path from "path";
|
|
17
|
+
import * as fs from "fs";
|
|
18
|
+
var getDirname2 = () => {
|
|
19
|
+
try {
|
|
20
|
+
return getDirname(import.meta.url);
|
|
21
|
+
} catch {
|
|
22
|
+
return process.cwd();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
var __dirname2 = getDirname2();
|
|
26
|
+
var isTreeSitterInitialized = false;
|
|
27
|
+
async function initTreeSitter() {
|
|
28
|
+
if (isTreeSitterInitialized) return;
|
|
29
|
+
try {
|
|
30
|
+
const wasmPath = getWasmPath("web-tree-sitter");
|
|
31
|
+
await Parser.Parser.init({
|
|
32
|
+
locateFile() {
|
|
33
|
+
return wasmPath || "web-tree-sitter.wasm";
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
isTreeSitterInitialized = true;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.error("Failed to initialize web-tree-sitter:", error);
|
|
39
|
+
isTreeSitterInitialized = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function findInPnpmStore(startDir, fileName, depth = 0) {
|
|
43
|
+
if (depth > 8) return null;
|
|
44
|
+
const pnpmDir = path.join(startDir, "node_modules", ".pnpm");
|
|
45
|
+
if (fs.existsSync(pnpmDir)) {
|
|
46
|
+
return findFileRecursively(pnpmDir, fileName, 0);
|
|
47
|
+
}
|
|
48
|
+
const parent = path.dirname(startDir);
|
|
49
|
+
if (parent === startDir) return null;
|
|
50
|
+
return findInPnpmStore(parent, fileName, depth + 1);
|
|
51
|
+
}
|
|
52
|
+
function findFileRecursively(dir, fileName, depth) {
|
|
53
|
+
if (depth > 6) return null;
|
|
54
|
+
try {
|
|
55
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
56
|
+
for (const entry of entries) {
|
|
57
|
+
if (entry.isFile() && entry.name === fileName) {
|
|
58
|
+
return path.join(dir, entry.name);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
for (const entry of entries) {
|
|
62
|
+
if (entry.isDirectory()) {
|
|
63
|
+
const found = findFileRecursively(
|
|
64
|
+
path.join(dir, entry.name),
|
|
65
|
+
fileName,
|
|
66
|
+
depth + 1
|
|
67
|
+
);
|
|
68
|
+
if (found) return found;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
} catch {
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
function getWasmPath(language) {
|
|
76
|
+
const wasmFileName = language === "web-tree-sitter" ? "web-tree-sitter.wasm" : `tree-sitter-${language}.wasm`;
|
|
77
|
+
const immediatePaths = [
|
|
78
|
+
path.join(process.cwd(), wasmFileName),
|
|
79
|
+
path.join(__dirname2, wasmFileName),
|
|
80
|
+
path.join(__dirname2, "assets", wasmFileName)
|
|
81
|
+
];
|
|
82
|
+
for (const p of immediatePaths) {
|
|
83
|
+
if (fs.existsSync(p)) return p;
|
|
84
|
+
}
|
|
85
|
+
const pnpmPath = findInPnpmStore(__dirname2, wasmFileName);
|
|
86
|
+
if (pnpmPath) return pnpmPath;
|
|
87
|
+
const pnpmPathCwd = findInPnpmStore(process.cwd(), wasmFileName);
|
|
88
|
+
if (pnpmPathCwd) return pnpmPathCwd;
|
|
89
|
+
console.warn(
|
|
90
|
+
`[Parser] WASM file for ${language} not found. CWD: ${process.cwd()}, DIR: ${__dirname2}`
|
|
91
|
+
);
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
async function setupParser(language) {
|
|
95
|
+
await initTreeSitter();
|
|
96
|
+
const wasmPath = getWasmPath(language);
|
|
97
|
+
if (!wasmPath) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
const parser = new Parser.Parser();
|
|
102
|
+
const Lang = await Parser.Language.load(wasmPath);
|
|
103
|
+
parser.setLanguage(Lang);
|
|
104
|
+
return parser;
|
|
105
|
+
} catch {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/parsers/base-parser.ts
|
|
111
|
+
var BaseLanguageParser = class {
|
|
112
|
+
constructor() {
|
|
113
|
+
this.parser = null;
|
|
114
|
+
this.initialized = false;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Initialize the tree-sitter parser
|
|
118
|
+
*/
|
|
119
|
+
async initialize() {
|
|
120
|
+
if (this.initialized) return;
|
|
121
|
+
try {
|
|
122
|
+
this.parser = await setupParser(this.getParserName());
|
|
123
|
+
this.initialized = true;
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.warn(`Failed to initialize ${this.language} parser:`, error);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async getAST(code, _filePath) {
|
|
129
|
+
void _filePath;
|
|
130
|
+
if (!this.initialized) await this.initialize();
|
|
131
|
+
if (!this.parser) return null;
|
|
132
|
+
return this.parser.parse(code);
|
|
133
|
+
}
|
|
134
|
+
parse(code, filePath) {
|
|
135
|
+
if (!this.initialized || !this.parser) {
|
|
136
|
+
return this.parseRegex(code, filePath);
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
const tree = this.parser.parse(code);
|
|
140
|
+
if (!tree || tree.rootNode.type === "ERROR" || tree.rootNode.hasError) {
|
|
141
|
+
return this.parseRegex(code, filePath);
|
|
142
|
+
}
|
|
143
|
+
const imports = this.extractImportsAST(tree.rootNode);
|
|
144
|
+
const exports = this.extractExportsAST(tree.rootNode, code);
|
|
145
|
+
return {
|
|
146
|
+
exports,
|
|
147
|
+
imports,
|
|
148
|
+
language: this.language,
|
|
149
|
+
warnings: []
|
|
150
|
+
};
|
|
151
|
+
} catch (error) {
|
|
152
|
+
console.warn(
|
|
153
|
+
`AST parsing failed for ${filePath}, falling back to regex: ${error.message}`
|
|
154
|
+
);
|
|
155
|
+
return this.parseRegex(code, filePath);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
canHandle(filePath) {
|
|
159
|
+
const lowerPath = filePath.toLowerCase();
|
|
160
|
+
return this.extensions.some((ext) => lowerPath.endsWith(ext));
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export {
|
|
165
|
+
getDirname,
|
|
166
|
+
initTreeSitter,
|
|
167
|
+
getWasmPath,
|
|
168
|
+
setupParser,
|
|
169
|
+
BaseLanguageParser
|
|
170
|
+
};
|