@aiready/core 0.23.2 → 0.23.3
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/__tests__/parser-factory.test.d.ts +1 -1
- package/dist/__tests__/parser-factory.test.js +62 -50
- package/dist/__tests__/python-parser.test.d.ts +1 -1
- package/dist/__tests__/python-parser.test.js +111 -109
- package/dist/__tests__/scoring.test.d.ts +1 -1
- package/dist/__tests__/scoring.test.js +193 -176
- package/dist/chunk-3YI4IS3D.mjs +191 -173
- package/dist/chunk-5HIXDC3X.mjs +273 -251
- package/dist/chunk-5V3L53AE.mjs +805 -0
- package/dist/chunk-CKVKHN3G.mjs +228 -211
- package/dist/chunk-COHIBX3Q.mjs +213 -195
- package/dist/chunk-CWRCDSKZ.mjs +91 -82
- package/dist/chunk-D3D3NCRR.mjs +147 -129
- package/dist/chunk-HCFYP7UD.mjs +805 -0
- package/dist/chunk-HFLFBA6F.mjs +79 -72
- package/dist/chunk-HKSARRCD.mjs +66 -58
- package/dist/chunk-JJ5JL5FX.mjs +91 -82
- package/dist/chunk-KDSTXVLQ.mjs +724 -0
- package/dist/chunk-KI7XORTN.mjs +91 -82
- package/dist/chunk-LTMHFNFK.mjs +690 -0
- package/dist/chunk-LTNXTXRI.mjs +228 -211
- package/dist/chunk-M22BXHBR.mjs +805 -0
- package/dist/chunk-MH3A3LX6.mjs +200 -182
- package/dist/chunk-NGHT7JOG.mjs +697 -0
- package/dist/chunk-OQ6IGDXG.mjs +147 -129
- package/dist/chunk-QAFB3HXQ.mjs +181 -165
- package/dist/chunk-QQBKXHLU.mjs +678 -0
- package/dist/chunk-RDHYGES7.mjs +678 -0
- package/dist/chunk-SWTDBVYJ.mjs +228 -213
- package/dist/chunk-UIWL5JQB.mjs +79 -72
- package/dist/chunk-UQGI67WR.mjs +79 -72
- package/dist/chunk-UTZOO4XO.mjs +147 -131
- package/dist/chunk-X4F46I5L.mjs +213 -195
- package/dist/chunk-XKK7YHPX.mjs +204 -186
- package/dist/chunk-YCA4FTEK.mjs +190 -172
- package/dist/chunk-ZSZRRTJM.mjs +719 -0
- package/dist/client-BgmiMoil.d.mts +1344 -0
- package/dist/client-BgmiMoil.d.ts +1344 -0
- package/dist/client-BxGrPuuN.d.mts +1191 -0
- package/dist/client-BxGrPuuN.d.ts +1191 -0
- package/dist/client-D-cn9ydj.d.mts +1136 -0
- package/dist/client-D-cn9ydj.d.ts +1136 -0
- package/dist/client-D9seCH4K.d.mts +1334 -0
- package/dist/client-D9seCH4K.d.ts +1334 -0
- package/dist/client-DIXIh7rw.d.mts +1193 -0
- package/dist/client-DIXIh7rw.d.ts +1193 -0
- package/dist/client-DVHXWOHw.d.mts +1245 -0
- package/dist/client-DVHXWOHw.d.ts +1245 -0
- package/dist/client.d.mts +2 -1098
- package/dist/client.d.ts +2 -1098
- package/dist/client.js +23 -43
- package/dist/client.mjs +3 -25
- package/dist/index.d.mts +325 -103
- package/dist/index.d.ts +325 -103
- package/dist/index.js +307 -324
- package/dist/index.mjs +283 -306
- package/dist/parsers/parser-factory.d.ts +45 -45
- package/dist/parsers/parser-factory.js +86 -84
- package/dist/parsers/python-parser.d.ts +33 -28
- package/dist/parsers/python-parser.js +224 -222
- package/dist/parsers/typescript-parser.d.ts +15 -10
- package/dist/parsers/typescript-parser.js +223 -197
- package/dist/scoring.d.ts +59 -49
- package/dist/scoring.js +129 -127
- package/dist/types/language.d.ts +104 -93
- package/dist/types/language.js +23 -23
- package/dist/types.d.ts +105 -87
- package/dist/types.js +1 -1
- package/dist/utils/ast-parser.d.ts +42 -33
- package/dist/utils/ast-parser.js +159 -162
- package/dist/utils/cli-helpers.d.ts +27 -10
- package/dist/utils/cli-helpers.js +45 -43
- package/dist/utils/config.d.ts +8 -3
- package/dist/utils/config.js +67 -69
- package/dist/utils/file-scanner.d.ts +1 -1
- package/dist/utils/file-scanner.js +80 -76
- package/dist/utils/metrics.d.ts +1 -1
- package/dist/utils/metrics.js +2 -2
- package/package.json +1 -1
|
@@ -2,57 +2,69 @@
|
|
|
2
2
|
* Test multi-language parser factory
|
|
3
3
|
*/
|
|
4
4
|
import { describe, it, expect } from 'vitest';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
ParserFactory,
|
|
7
|
+
Language,
|
|
8
|
+
getParser,
|
|
9
|
+
isFileSupported,
|
|
10
|
+
getSupportedLanguages,
|
|
11
|
+
} from '../parsers/parser-factory';
|
|
6
12
|
describe('ParserFactory', () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
13
|
+
it('should return TypeScript parser for .ts files', () => {
|
|
14
|
+
const parser = getParser('test.ts');
|
|
15
|
+
expect(parser).toBeDefined();
|
|
16
|
+
expect(parser?.language).toBe(Language.TypeScript);
|
|
17
|
+
});
|
|
18
|
+
it('should return TypeScript parser for .tsx files', () => {
|
|
19
|
+
const parser = getParser('component.tsx');
|
|
20
|
+
expect(parser).toBeDefined();
|
|
21
|
+
expect(parser?.language).toBe(Language.TypeScript);
|
|
22
|
+
});
|
|
23
|
+
it('should return JavaScript parser for .js files', () => {
|
|
24
|
+
const parser = getParser('script.js');
|
|
25
|
+
expect(parser).toBeDefined();
|
|
26
|
+
expect(parser?.language).toBe(Language.TypeScript); // TS parser handles JS too
|
|
27
|
+
});
|
|
28
|
+
it('should return Python parser for .py files', () => {
|
|
29
|
+
const parser = getParser('script.py');
|
|
30
|
+
expect(parser).toBeDefined();
|
|
31
|
+
expect(parser?.language).toBe(Language.Python);
|
|
32
|
+
});
|
|
33
|
+
it('should return null for unsupported files', () => {
|
|
34
|
+
const parser = getParser('README.md');
|
|
35
|
+
expect(parser).toBeNull();
|
|
36
|
+
});
|
|
37
|
+
it('should correctly identify supported files', () => {
|
|
38
|
+
expect(isFileSupported('test.ts')).toBe(true);
|
|
39
|
+
expect(isFileSupported('test.py')).toBe(true);
|
|
40
|
+
expect(isFileSupported('test.java')).toBe(false); // Not yet implemented
|
|
41
|
+
expect(isFileSupported('README.md')).toBe(false);
|
|
42
|
+
});
|
|
43
|
+
it('should list all supported languages', () => {
|
|
44
|
+
const languages = getSupportedLanguages();
|
|
45
|
+
expect(languages).toContain(Language.TypeScript);
|
|
46
|
+
expect(languages).toContain(Language.Python);
|
|
47
|
+
expect(languages.length).toBeGreaterThanOrEqual(2);
|
|
48
|
+
});
|
|
49
|
+
it('should be case-insensitive for extensions', () => {
|
|
50
|
+
expect(getParser('Test.TS')).toBeDefined();
|
|
51
|
+
expect(getParser('Test.PY')).toBeDefined();
|
|
52
|
+
});
|
|
47
53
|
});
|
|
48
54
|
describe('Language Detection', () => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
it('should detect language from file path', () => {
|
|
56
|
+
const factory = ParserFactory.getInstance();
|
|
57
|
+
expect(factory.getLanguageForFile('src/index.ts')).toBe(
|
|
58
|
+
Language.TypeScript
|
|
59
|
+
);
|
|
60
|
+
expect(factory.getLanguageForFile('src/component.tsx')).toBe(
|
|
61
|
+
Language.TypeScript
|
|
62
|
+
);
|
|
63
|
+
expect(factory.getLanguageForFile('src/script.js')).toBe(
|
|
64
|
+
Language.JavaScript
|
|
65
|
+
);
|
|
66
|
+
expect(factory.getLanguageForFile('src/main.py')).toBe(Language.Python);
|
|
67
|
+
expect(factory.getLanguageForFile('README.md')).toBeNull();
|
|
68
|
+
});
|
|
57
69
|
});
|
|
58
|
-
//# sourceMappingURL=parser-factory.test.js.map
|
|
70
|
+
//# sourceMappingURL=parser-factory.test.js.map
|
|
@@ -5,83 +5,83 @@ import { describe, it, expect } from 'vitest';
|
|
|
5
5
|
import { PythonParser } from '../parsers/python-parser';
|
|
6
6
|
import { Language } from '../types/language';
|
|
7
7
|
describe('PythonParser', () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
8
|
+
const parser = new PythonParser();
|
|
9
|
+
it('should have correct language and extensions', () => {
|
|
10
|
+
expect(parser.language).toBe(Language.Python);
|
|
11
|
+
expect(parser.extensions).toContain('.py');
|
|
12
|
+
});
|
|
13
|
+
it('should handle .py files', () => {
|
|
14
|
+
expect(parser.canHandle('test.py')).toBe(true);
|
|
15
|
+
expect(parser.canHandle('Test.PY')).toBe(true);
|
|
16
|
+
expect(parser.canHandle('test.ts')).toBe(false);
|
|
17
|
+
});
|
|
18
|
+
it('should return PEP 8 naming conventions', () => {
|
|
19
|
+
const conventions = parser.getNamingConventions();
|
|
20
|
+
// Variables and functions should be snake_case
|
|
21
|
+
expect(conventions.variablePattern.test('my_variable')).toBe(true);
|
|
22
|
+
expect(conventions.variablePattern.test('myVariable')).toBe(false);
|
|
23
|
+
expect(conventions.functionPattern.test('my_function')).toBe(true);
|
|
24
|
+
// Classes should be PascalCase
|
|
25
|
+
expect(conventions.classPattern.test('MyClass')).toBe(true);
|
|
26
|
+
expect(conventions.classPattern.test('my_class')).toBe(false);
|
|
27
|
+
// Constants should be UPPER_CASE
|
|
28
|
+
expect(conventions.constantPattern.test('MY_CONSTANT')).toBe(true);
|
|
29
|
+
expect(conventions.constantPattern.test('myConstant')).toBe(false);
|
|
30
|
+
// Should have Python special method exceptions
|
|
31
|
+
expect(conventions.exceptions).toContain('__init__');
|
|
32
|
+
expect(conventions.exceptions).toContain('__str__');
|
|
33
|
+
});
|
|
34
|
+
describe('Import Extraction', () => {
|
|
35
|
+
it('should extract simple imports', () => {
|
|
36
|
+
const code = `
|
|
37
37
|
import os
|
|
38
38
|
import sys
|
|
39
39
|
import json
|
|
40
40
|
`;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
const result = parser.parse(code, 'test.py');
|
|
42
|
+
expect(result.imports).toHaveLength(3);
|
|
43
|
+
expect(result.imports[0].source).toBe('os');
|
|
44
|
+
expect(result.imports[1].source).toBe('sys');
|
|
45
|
+
expect(result.imports[2].source).toBe('json');
|
|
46
|
+
});
|
|
47
|
+
it('should extract from imports', () => {
|
|
48
|
+
const code = `
|
|
49
49
|
from typing import List, Dict, Optional
|
|
50
50
|
from pathlib import Path
|
|
51
51
|
`;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
});
|
|
52
|
+
const result = parser.parse(code, 'test.py');
|
|
53
|
+
expect(result.imports).toHaveLength(2);
|
|
54
|
+
const typingImport = result.imports.find((i) => i.source === 'typing');
|
|
55
|
+
expect(typingImport).toBeDefined();
|
|
56
|
+
expect(typingImport?.specifiers).toContain('List');
|
|
57
|
+
expect(typingImport?.specifiers).toContain('Dict');
|
|
58
|
+
expect(typingImport?.specifiers).toContain('Optional');
|
|
59
|
+
const pathlibImport = result.imports.find((i) => i.source === 'pathlib');
|
|
60
|
+
expect(pathlibImport?.specifiers).toContain('Path');
|
|
61
|
+
});
|
|
62
|
+
it('should handle wildcard imports', () => {
|
|
63
|
+
const code = `from os import *`;
|
|
64
|
+
const result = parser.parse(code, 'test.py');
|
|
65
|
+
expect(result.imports[0].source).toBe('os');
|
|
66
|
+
expect(result.imports[0].specifiers).toContain('*');
|
|
68
67
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
});
|
|
69
|
+
describe('Export Extraction', () => {
|
|
70
|
+
it('should extract module-level functions', () => {
|
|
71
|
+
const code = `
|
|
72
72
|
def public_function():
|
|
73
73
|
pass
|
|
74
74
|
|
|
75
75
|
def another_function(arg1, arg2):
|
|
76
76
|
return arg1 + arg2
|
|
77
77
|
`;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
const result = parser.parse(code, 'test.py');
|
|
79
|
+
const funcNames = result.exports.map((e) => e.name);
|
|
80
|
+
expect(funcNames).toContain('public_function');
|
|
81
|
+
expect(funcNames).toContain('another_function');
|
|
82
|
+
});
|
|
83
|
+
it('should extract classes', () => {
|
|
84
|
+
const code = `
|
|
85
85
|
class MyClass:
|
|
86
86
|
def __init__(self):
|
|
87
87
|
self.value = 0
|
|
@@ -92,16 +92,18 @@ class MyClass:
|
|
|
92
92
|
class AnotherClass:
|
|
93
93
|
pass
|
|
94
94
|
`;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
95
|
+
const result = parser.parse(code, 'test.py');
|
|
96
|
+
const classNames = result.exports
|
|
97
|
+
.filter((e) => e.type === 'class')
|
|
98
|
+
.map((e) => e.name);
|
|
99
|
+
expect(classNames).toContain('MyClass');
|
|
100
|
+
expect(classNames).toContain('AnotherClass');
|
|
101
|
+
// Methods should not be exported as separate entities
|
|
102
|
+
const methodNames = result.exports.map((e) => e.name);
|
|
103
|
+
expect(methodNames).not.toContain('method');
|
|
104
|
+
});
|
|
105
|
+
it('should not export private functions', () => {
|
|
106
|
+
const code = `
|
|
105
107
|
def public_function():
|
|
106
108
|
pass
|
|
107
109
|
|
|
@@ -111,14 +113,14 @@ def _private_function():
|
|
|
111
113
|
def __dunder_function__():
|
|
112
114
|
pass
|
|
113
115
|
`;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
const result = parser.parse(code, 'test.py');
|
|
117
|
+
const funcNames = result.exports.map((e) => e.name);
|
|
118
|
+
expect(funcNames).toContain('public_function');
|
|
119
|
+
expect(funcNames).toContain('__dunder_function__'); // Dunder methods are included
|
|
120
|
+
expect(funcNames).not.toContain('_private_function'); // Single underscore excluded
|
|
121
|
+
});
|
|
122
|
+
it('should extract __all__ exports', () => {
|
|
123
|
+
const code = `
|
|
122
124
|
__all__ = ['foo', 'bar', 'MyClass']
|
|
123
125
|
|
|
124
126
|
def foo():
|
|
@@ -130,22 +132,22 @@ def bar():
|
|
|
130
132
|
class MyClass:
|
|
131
133
|
pass
|
|
132
134
|
`;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
});
|
|
135
|
+
const result = parser.parse(code, 'test.py');
|
|
136
|
+
const names = result.exports.map((e) => e.name);
|
|
137
|
+
expect(names).toContain('foo');
|
|
138
|
+
expect(names).toContain('bar');
|
|
139
|
+
expect(names).toContain('MyClass');
|
|
139
140
|
});
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
141
|
+
});
|
|
142
|
+
it('should include warning about regex-based parsing', () => {
|
|
143
|
+
const code = 'import os';
|
|
144
|
+
const result = parser.parse(code, 'test.py');
|
|
145
|
+
expect(result.warnings).toBeDefined();
|
|
146
|
+
expect(result.warnings.length).toBeGreaterThan(0);
|
|
147
|
+
expect(result.warnings[0]).toContain('regex-based');
|
|
148
|
+
});
|
|
149
|
+
it('should parse real-world Python code', () => {
|
|
150
|
+
const code = `
|
|
149
151
|
"""
|
|
150
152
|
A sample Python module
|
|
151
153
|
"""
|
|
@@ -176,17 +178,17 @@ def _helper_function():
|
|
|
176
178
|
|
|
177
179
|
MY_CONSTANT = 42
|
|
178
180
|
`;
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
181
|
+
const result = parser.parse(code, 'example.py');
|
|
182
|
+
// Check imports
|
|
183
|
+
expect(result.imports.length).toBeGreaterThan(0);
|
|
184
|
+
const typingImport = result.imports.find((i) => i.source === 'typing');
|
|
185
|
+
expect(typingImport).toBeDefined();
|
|
186
|
+
// Check exports
|
|
187
|
+
const exportNames = result.exports.map((e) => e.name);
|
|
188
|
+
expect(exportNames).toContain('DataProcessor');
|
|
189
|
+
expect(exportNames).toContain('process_data');
|
|
190
|
+
expect(exportNames).not.toContain('_helper_function');
|
|
191
|
+
expect(exportNames).not.toContain('process'); // Method, not module-level
|
|
192
|
+
});
|
|
191
193
|
});
|
|
192
|
-
//# sourceMappingURL=python-parser.test.js.map
|
|
194
|
+
//# sourceMappingURL=python-parser.test.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
//# sourceMappingURL=scoring.test.d.ts.map
|
|
2
|
+
//# sourceMappingURL=scoring.test.d.ts.map
|