@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-4OMXBYX7.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,309 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ParseError
|
|
3
|
+
} from "./chunk-YQATXOKD.mjs";
|
|
4
|
+
|
|
5
|
+
// src/parsers/typescript-parser.ts
|
|
6
|
+
import { parse } from "@typescript-eslint/typescript-estree";
|
|
7
|
+
var TypeScriptParser = class {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.language = "typescript" /* TypeScript */;
|
|
10
|
+
this.extensions = [".ts", ".tsx", ".js", ".jsx"];
|
|
11
|
+
}
|
|
12
|
+
async initialize() {
|
|
13
|
+
}
|
|
14
|
+
canHandle(filePath) {
|
|
15
|
+
return this.extensions.some((ext) => filePath.endsWith(ext));
|
|
16
|
+
}
|
|
17
|
+
async getAST(code, filePath) {
|
|
18
|
+
try {
|
|
19
|
+
return parse(code, {
|
|
20
|
+
filePath,
|
|
21
|
+
loc: true,
|
|
22
|
+
range: true,
|
|
23
|
+
tokens: true,
|
|
24
|
+
comment: true,
|
|
25
|
+
jsx: filePath.endsWith("x"),
|
|
26
|
+
ecmaVersion: "latest"
|
|
27
|
+
});
|
|
28
|
+
} catch (error) {
|
|
29
|
+
const err = error;
|
|
30
|
+
throw new ParseError(err.message || "Unknown error", filePath, {
|
|
31
|
+
line: err.lineNumber || 1,
|
|
32
|
+
column: err.column || 0
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
parse(code, filePath) {
|
|
37
|
+
try {
|
|
38
|
+
const ast = parse(code, {
|
|
39
|
+
filePath,
|
|
40
|
+
loc: true,
|
|
41
|
+
range: true,
|
|
42
|
+
tokens: true,
|
|
43
|
+
comment: true,
|
|
44
|
+
jsx: filePath.endsWith("x"),
|
|
45
|
+
ecmaVersion: "latest"
|
|
46
|
+
});
|
|
47
|
+
const imports = this.extractImports(ast);
|
|
48
|
+
const exports = this.extractExports(ast, code, filePath);
|
|
49
|
+
return {
|
|
50
|
+
exports,
|
|
51
|
+
imports,
|
|
52
|
+
language: this.language
|
|
53
|
+
};
|
|
54
|
+
} catch (error) {
|
|
55
|
+
throw new ParseError(error.message, filePath, {
|
|
56
|
+
line: error.lineNumber || 1,
|
|
57
|
+
column: error.column || 0
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
getNamingConventions() {
|
|
62
|
+
return {
|
|
63
|
+
variablePattern: /^[a-z][a-zA-Z0-9]*$/,
|
|
64
|
+
functionPattern: /^[a-z][a-zA-Z0-9]*$/,
|
|
65
|
+
classPattern: /^[A-Z][a-zA-Z0-9]*$/,
|
|
66
|
+
constantPattern: /^[A-Z][A-Z0-9_]*$/,
|
|
67
|
+
typePattern: /^[A-Z][a-zA-Z0-9]*$/,
|
|
68
|
+
interfacePattern: /^I?[A-Z][a-zA-Z0-9]*$/
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
analyzeMetadata(node, code) {
|
|
72
|
+
if (!code) return {};
|
|
73
|
+
return {
|
|
74
|
+
isPure: this.isLikelyPure(node),
|
|
75
|
+
hasSideEffects: !this.isLikelyPure(node)
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
extractImports(ast) {
|
|
79
|
+
const imports = [];
|
|
80
|
+
for (const node of ast.body) {
|
|
81
|
+
if (node.type === "ImportDeclaration") {
|
|
82
|
+
const specifiers = [];
|
|
83
|
+
let isTypeOnly = false;
|
|
84
|
+
if (node.importKind === "type") {
|
|
85
|
+
isTypeOnly = true;
|
|
86
|
+
}
|
|
87
|
+
for (const spec of node.specifiers) {
|
|
88
|
+
if (spec.type === "ImportSpecifier") {
|
|
89
|
+
const imported = spec.imported;
|
|
90
|
+
const name = imported.type === "Identifier" ? imported.name : imported.value;
|
|
91
|
+
specifiers.push(name);
|
|
92
|
+
} else if (spec.type === "ImportDefaultSpecifier") {
|
|
93
|
+
specifiers.push("default");
|
|
94
|
+
} else if (spec.type === "ImportNamespaceSpecifier") {
|
|
95
|
+
specifiers.push("*");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
imports.push({
|
|
99
|
+
source: node.source.value,
|
|
100
|
+
specifiers,
|
|
101
|
+
isTypeOnly,
|
|
102
|
+
loc: node.loc ? {
|
|
103
|
+
start: {
|
|
104
|
+
line: node.loc.start.line,
|
|
105
|
+
column: node.loc.start.column
|
|
106
|
+
},
|
|
107
|
+
end: { line: node.loc.end.line, column: node.loc.end.column }
|
|
108
|
+
} : void 0
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return imports;
|
|
113
|
+
}
|
|
114
|
+
extractExports(ast, code, filePath) {
|
|
115
|
+
const exports = [];
|
|
116
|
+
for (const node of ast.body) {
|
|
117
|
+
if (node.type === "ExportNamedDeclaration") {
|
|
118
|
+
if (node.declaration) {
|
|
119
|
+
const declaration = node.declaration;
|
|
120
|
+
if ((declaration.type === "FunctionDeclaration" || declaration.type === "TSDeclareFunction") && declaration.id) {
|
|
121
|
+
exports.push(
|
|
122
|
+
this.createExport(
|
|
123
|
+
declaration.id.name,
|
|
124
|
+
"function",
|
|
125
|
+
node,
|
|
126
|
+
// Pass the outer ExportNamedDeclaration
|
|
127
|
+
code,
|
|
128
|
+
filePath
|
|
129
|
+
)
|
|
130
|
+
);
|
|
131
|
+
} else if (declaration.type === "ClassDeclaration" && declaration.id) {
|
|
132
|
+
exports.push(
|
|
133
|
+
this.createExport(
|
|
134
|
+
declaration.id.name,
|
|
135
|
+
"class",
|
|
136
|
+
node,
|
|
137
|
+
// Pass the outer ExportNamedDeclaration
|
|
138
|
+
code,
|
|
139
|
+
filePath
|
|
140
|
+
)
|
|
141
|
+
);
|
|
142
|
+
} else if (declaration.type === "TSTypeAliasDeclaration") {
|
|
143
|
+
exports.push(
|
|
144
|
+
this.createExport(
|
|
145
|
+
declaration.id.name,
|
|
146
|
+
"type",
|
|
147
|
+
node,
|
|
148
|
+
// Pass the outer ExportNamedDeclaration
|
|
149
|
+
code,
|
|
150
|
+
filePath
|
|
151
|
+
)
|
|
152
|
+
);
|
|
153
|
+
} else if (declaration.type === "TSInterfaceDeclaration") {
|
|
154
|
+
exports.push(
|
|
155
|
+
this.createExport(
|
|
156
|
+
declaration.id.name,
|
|
157
|
+
"interface",
|
|
158
|
+
node,
|
|
159
|
+
// Pass the outer ExportNamedDeclaration
|
|
160
|
+
code,
|
|
161
|
+
filePath
|
|
162
|
+
)
|
|
163
|
+
);
|
|
164
|
+
} else if (declaration.type === "VariableDeclaration") {
|
|
165
|
+
for (const decl of declaration.declarations) {
|
|
166
|
+
if (decl.id.type === "Identifier") {
|
|
167
|
+
exports.push(
|
|
168
|
+
this.createExport(
|
|
169
|
+
decl.id.name,
|
|
170
|
+
"const",
|
|
171
|
+
node,
|
|
172
|
+
code,
|
|
173
|
+
filePath,
|
|
174
|
+
decl.init
|
|
175
|
+
)
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
} else if (node.type === "ExportDefaultDeclaration") {
|
|
182
|
+
exports.push(
|
|
183
|
+
this.createExport("default", "default", node, code, filePath)
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return exports;
|
|
188
|
+
}
|
|
189
|
+
createExport(name, type, node, code, filePath, initializer) {
|
|
190
|
+
const documentation = this.extractDocumentation(node, code);
|
|
191
|
+
let methodCount;
|
|
192
|
+
let propertyCount;
|
|
193
|
+
let parameters;
|
|
194
|
+
let isPrimitive = false;
|
|
195
|
+
let isTyped = false;
|
|
196
|
+
if (initializer) {
|
|
197
|
+
if (initializer.type === "Literal" || initializer.type === "BigIntLiteral" || initializer.type === "TemplateLiteral" && initializer.expressions.length === 0) {
|
|
198
|
+
isPrimitive = true;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
let structNode = node.type === "ExportNamedDeclaration" && node.declaration ? node.declaration : node.type === "ExportDefaultDeclaration" ? node.declaration : node;
|
|
202
|
+
if (!structNode) structNode = node;
|
|
203
|
+
if (filePath.endsWith(".ts") || filePath.endsWith(".tsx")) {
|
|
204
|
+
if (structNode.type === "TSTypeAliasDeclaration" || structNode.type === "TSInterfaceDeclaration" || structNode.type === "TSEnumDeclaration") {
|
|
205
|
+
isTyped = true;
|
|
206
|
+
} else if (structNode.type === "FunctionDeclaration" || structNode.type === "TSDeclareFunction") {
|
|
207
|
+
const func = structNode;
|
|
208
|
+
const hasReturnType = !!func.returnType;
|
|
209
|
+
const allParamsTyped = func.params.length === 0 || func.params.every((p) => !!p.typeAnnotation);
|
|
210
|
+
isTyped = hasReturnType && allParamsTyped;
|
|
211
|
+
} else if (structNode.type === "VariableDeclaration") {
|
|
212
|
+
const variable = structNode;
|
|
213
|
+
isTyped = variable.declarations.every(
|
|
214
|
+
(d) => !!d.id.typeAnnotation || !!d.init
|
|
215
|
+
);
|
|
216
|
+
} else if (structNode.type === "ClassDeclaration") {
|
|
217
|
+
isTyped = true;
|
|
218
|
+
}
|
|
219
|
+
} else if (filePath.endsWith(".js") || filePath.endsWith(".jsx")) {
|
|
220
|
+
isTyped = false;
|
|
221
|
+
}
|
|
222
|
+
if (structNode.type === "ClassDeclaration" || structNode.type === "TSInterfaceDeclaration") {
|
|
223
|
+
const body = structNode.type === "ClassDeclaration" ? structNode.body.body : structNode.body.body;
|
|
224
|
+
methodCount = body.filter(
|
|
225
|
+
(m) => m.type === "MethodDefinition" || m.type === "TSMethodSignature"
|
|
226
|
+
).length;
|
|
227
|
+
propertyCount = body.filter(
|
|
228
|
+
(m) => m.type === "PropertyDefinition" || m.type === "TSPropertySignature"
|
|
229
|
+
).length;
|
|
230
|
+
if (structNode.type === "ClassDeclaration") {
|
|
231
|
+
const constructor = body.find(
|
|
232
|
+
(m) => m.type === "MethodDefinition" && m.kind === "constructor"
|
|
233
|
+
);
|
|
234
|
+
if (constructor && constructor.value && constructor.value.params) {
|
|
235
|
+
parameters = constructor.value.params.map((p) => {
|
|
236
|
+
if (p.type === "Identifier") return p.name;
|
|
237
|
+
if (p.type === "TSParameterProperty" && p.parameter.type === "Identifier") {
|
|
238
|
+
return p.parameter.name;
|
|
239
|
+
}
|
|
240
|
+
return void 0;
|
|
241
|
+
}).filter((p) => !!p);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (!parameters && (structNode.type === "FunctionDeclaration" || structNode.type === "TSDeclareFunction" || structNode.type === "MethodDefinition")) {
|
|
246
|
+
const funcNode = structNode.type === "MethodDefinition" ? structNode.value : structNode;
|
|
247
|
+
if (funcNode && funcNode.params) {
|
|
248
|
+
parameters = funcNode.params.map((p) => {
|
|
249
|
+
if (p.type === "Identifier") return p.name;
|
|
250
|
+
return void 0;
|
|
251
|
+
}).filter((p) => !!p);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return {
|
|
255
|
+
name,
|
|
256
|
+
type,
|
|
257
|
+
isPrimitive,
|
|
258
|
+
loc: node.loc ? {
|
|
259
|
+
start: { line: node.loc.start.line, column: node.loc.start.column },
|
|
260
|
+
end: { line: node.loc.end.line, column: node.loc.end.column }
|
|
261
|
+
} : void 0,
|
|
262
|
+
documentation,
|
|
263
|
+
methodCount,
|
|
264
|
+
propertyCount,
|
|
265
|
+
parameters,
|
|
266
|
+
isPure: this.isLikelyPure(node),
|
|
267
|
+
hasSideEffects: !this.isLikelyPure(node),
|
|
268
|
+
isTyped
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
extractDocumentation(node, code) {
|
|
272
|
+
if (node.range) {
|
|
273
|
+
const start = node.range[0];
|
|
274
|
+
const precedingCode = code.substring(0, start);
|
|
275
|
+
const jsdocMatch = precedingCode.match(/\/\*\*([\s\S]*?)\*\/\s*$/);
|
|
276
|
+
if (jsdocMatch) {
|
|
277
|
+
return {
|
|
278
|
+
content: jsdocMatch[1].trim(),
|
|
279
|
+
type: "jsdoc"
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return void 0;
|
|
284
|
+
}
|
|
285
|
+
isLikelyPure(node) {
|
|
286
|
+
const sn = node.type === "ExportNamedDeclaration" && node.declaration ? node.declaration : node.type === "ExportDefaultDeclaration" ? node.declaration : node;
|
|
287
|
+
if (!sn) return false;
|
|
288
|
+
if (sn.type === "VariableDeclaration" && sn.kind === "const") return true;
|
|
289
|
+
if (sn.type === "FunctionDeclaration" || sn.type === "TSDeclareFunction" || sn.type === "MethodDefinition") {
|
|
290
|
+
const body = sn.type === "MethodDefinition" ? sn.value.body : sn.body;
|
|
291
|
+
if (body && body.type === "BlockStatement") {
|
|
292
|
+
const bodyContent = JSON.stringify(
|
|
293
|
+
body,
|
|
294
|
+
(_, v) => typeof v === "bigint" ? v.toString() : v
|
|
295
|
+
);
|
|
296
|
+
if (bodyContent.includes('"name":"console"') || bodyContent.includes('"name":"process"') || bodyContent.includes('"name":"fs"') || bodyContent.includes('"name":"global"') || bodyContent.includes('"name":"window"') || bodyContent.includes('"name":"fetch"') || bodyContent.includes('"name":"axios"')) {
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
return true;
|
|
300
|
+
}
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
export {
|
|
308
|
+
TypeScriptParser
|
|
309
|
+
};
|