@liendev/parser 0.39.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.
- package/dist/ast/chunker.d.ts +30 -0
- package/dist/ast/chunker.d.ts.map +1 -0
- package/dist/ast/chunker.js +310 -0
- package/dist/ast/chunker.js.map +1 -0
- package/dist/ast/complexity/cognitive.d.ts +16 -0
- package/dist/ast/complexity/cognitive.d.ts.map +1 -0
- package/dist/ast/complexity/cognitive.js +137 -0
- package/dist/ast/complexity/cognitive.js.map +1 -0
- package/dist/ast/complexity/cyclomatic.d.ts +12 -0
- package/dist/ast/complexity/cyclomatic.d.ts.map +1 -0
- package/dist/ast/complexity/cyclomatic.js +54 -0
- package/dist/ast/complexity/cyclomatic.js.map +1 -0
- package/dist/ast/complexity/halstead.d.ts +56 -0
- package/dist/ast/complexity/halstead.d.ts.map +1 -0
- package/dist/ast/complexity/halstead.js +196 -0
- package/dist/ast/complexity/halstead.js.map +1 -0
- package/dist/ast/complexity/index.d.ts +13 -0
- package/dist/ast/complexity/index.d.ts.map +1 -0
- package/dist/ast/complexity/index.js +12 -0
- package/dist/ast/complexity/index.js.map +1 -0
- package/dist/ast/extractors/index.d.ts +35 -0
- package/dist/ast/extractors/index.d.ts.map +1 -0
- package/dist/ast/extractors/index.js +41 -0
- package/dist/ast/extractors/index.js.map +1 -0
- package/dist/ast/extractors/symbol-helpers.d.ts +20 -0
- package/dist/ast/extractors/symbol-helpers.d.ts.map +1 -0
- package/dist/ast/extractors/symbol-helpers.js +58 -0
- package/dist/ast/extractors/symbol-helpers.js.map +1 -0
- package/dist/ast/extractors/types.d.ts +108 -0
- package/dist/ast/extractors/types.d.ts.map +1 -0
- package/dist/ast/extractors/types.js +2 -0
- package/dist/ast/extractors/types.js.map +1 -0
- package/dist/ast/languages/javascript.d.ts +134 -0
- package/dist/ast/languages/javascript.d.ts.map +1 -0
- package/dist/ast/languages/javascript.js +787 -0
- package/dist/ast/languages/javascript.js.map +1 -0
- package/dist/ast/languages/php.d.ts +84 -0
- package/dist/ast/languages/php.d.ts.map +1 -0
- package/dist/ast/languages/php.js +452 -0
- package/dist/ast/languages/php.js.map +1 -0
- package/dist/ast/languages/python.d.ts +96 -0
- package/dist/ast/languages/python.d.ts.map +1 -0
- package/dist/ast/languages/python.js +448 -0
- package/dist/ast/languages/python.js.map +1 -0
- package/dist/ast/languages/registry.d.ts +30 -0
- package/dist/ast/languages/registry.d.ts.map +1 -0
- package/dist/ast/languages/registry.js +95 -0
- package/dist/ast/languages/registry.js.map +1 -0
- package/dist/ast/languages/rust.d.ts +113 -0
- package/dist/ast/languages/rust.d.ts.map +1 -0
- package/dist/ast/languages/rust.js +614 -0
- package/dist/ast/languages/rust.js.map +1 -0
- package/dist/ast/languages/types.d.ts +52 -0
- package/dist/ast/languages/types.d.ts.map +1 -0
- package/dist/ast/languages/types.js +2 -0
- package/dist/ast/languages/types.js.map +1 -0
- package/dist/ast/languages/typescript.d.ts +3 -0
- package/dist/ast/languages/typescript.d.ts.map +1 -0
- package/dist/ast/languages/typescript.js +134 -0
- package/dist/ast/languages/typescript.js.map +1 -0
- package/dist/ast/parser.d.ts +29 -0
- package/dist/ast/parser.d.ts.map +1 -0
- package/dist/ast/parser.js +67 -0
- package/dist/ast/parser.js.map +1 -0
- package/dist/ast/symbols.d.ts +74 -0
- package/dist/ast/symbols.d.ts.map +1 -0
- package/dist/ast/symbols.js +171 -0
- package/dist/ast/symbols.js.map +1 -0
- package/dist/ast/traversers/index.d.ts +19 -0
- package/dist/ast/traversers/index.d.ts.map +1 -0
- package/dist/ast/traversers/index.js +21 -0
- package/dist/ast/traversers/index.js.map +1 -0
- package/dist/ast/traversers/types.d.ts +98 -0
- package/dist/ast/traversers/types.d.ts.map +1 -0
- package/dist/ast/traversers/types.js +2 -0
- package/dist/ast/traversers/types.js.map +1 -0
- package/dist/ast/types.d.ts +54 -0
- package/dist/ast/types.d.ts.map +1 -0
- package/dist/ast/types.js +2 -0
- package/dist/ast/types.js.map +1 -0
- package/dist/chunk-only-index.d.ts +25 -0
- package/dist/chunk-only-index.d.ts.map +1 -0
- package/dist/chunk-only-index.js +107 -0
- package/dist/chunk-only-index.js.map +1 -0
- package/dist/chunker.d.ts +12 -0
- package/dist/chunker.d.ts.map +1 -0
- package/dist/chunker.js +98 -0
- package/dist/chunker.js.map +1 -0
- package/dist/constants.d.ts +8 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +11 -0
- package/dist/constants.js.map +1 -0
- package/dist/content-hash.d.ts +20 -0
- package/dist/content-hash.d.ts.map +1 -0
- package/dist/content-hash.js +91 -0
- package/dist/content-hash.js.map +1 -0
- package/dist/dependency-analyzer.d.ts +79 -0
- package/dist/dependency-analyzer.d.ts.map +1 -0
- package/dist/dependency-analyzer.js +408 -0
- package/dist/dependency-analyzer.js.map +1 -0
- package/dist/ecosystem-presets.d.ts +32 -0
- package/dist/ecosystem-presets.d.ts.map +1 -0
- package/dist/ecosystem-presets.js +325 -0
- package/dist/ecosystem-presets.js.map +1 -0
- package/dist/gitignore.d.ts +22 -0
- package/dist/gitignore.d.ts.map +1 -0
- package/dist/gitignore.js +128 -0
- package/dist/gitignore.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +68 -0
- package/dist/index.js.map +1 -0
- package/dist/insights/chunk-complexity.d.ts +89 -0
- package/dist/insights/chunk-complexity.d.ts.map +1 -0
- package/dist/insights/chunk-complexity.js +332 -0
- package/dist/insights/chunk-complexity.js.map +1 -0
- package/dist/insights/types.d.ts +73 -0
- package/dist/insights/types.d.ts.map +1 -0
- package/dist/insights/types.js +9 -0
- package/dist/insights/types.js.map +1 -0
- package/dist/json-template-chunker.d.ts +12 -0
- package/dist/json-template-chunker.d.ts.map +1 -0
- package/dist/json-template-chunker.js +87 -0
- package/dist/json-template-chunker.js.map +1 -0
- package/dist/liquid-chunker.d.ts +16 -0
- package/dist/liquid-chunker.d.ts.map +1 -0
- package/dist/liquid-chunker.js +274 -0
- package/dist/liquid-chunker.js.map +1 -0
- package/dist/scanner.d.ts +16 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +95 -0
- package/dist/scanner.js.map +1 -0
- package/dist/symbol-extractor.d.ts +18 -0
- package/dist/symbol-extractor.d.ts.map +1 -0
- package/dist/symbol-extractor.js +343 -0
- package/dist/symbol-extractor.js.map +1 -0
- package/dist/test-associations.d.ts +16 -0
- package/dist/test-associations.d.ts.map +1 -0
- package/dist/test-associations.js +43 -0
- package/dist/test-associations.js.map +1 -0
- package/dist/types.d.ts +75 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/path-matching.d.ts +71 -0
- package/dist/utils/path-matching.d.ts.map +1 -0
- package/dist/utils/path-matching.js +258 -0
- package/dist/utils/path-matching.js.map +1 -0
- package/dist/utils/repo-id.d.ts +6 -0
- package/dist/utils/repo-id.d.ts.map +1 -0
- package/dist/utils/repo-id.js +12 -0
- package/dist/utils/repo-id.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"halstead.d.ts","sourceRoot":"","sources":["../../../src/ast/complexity/halstead.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAQlE,mCAAmC;AACnC,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAED,kCAAkC;AAClC,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AA6HD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,CAAC,UAAU,EACvB,QAAQ,EAAE,iBAAiB,GAC1B,cAAc,CAkChB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,cAAc,GAAG,eAAe,CAsBhF;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,CAAC,UAAU,EACvB,QAAQ,EAAE,iBAAiB,GAC1B,eAAe,CAGjB"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { getLanguage } from '../languages/registry.js';
|
|
2
|
+
/**
|
|
3
|
+
* AST node types that represent operators (language-agnostic).
|
|
4
|
+
* These are the tree-sitter node types, not the text content.
|
|
5
|
+
*/
|
|
6
|
+
const OPERATOR_NODE_TYPES = new Set([
|
|
7
|
+
// Expression operators
|
|
8
|
+
'binary_expression',
|
|
9
|
+
'unary_expression',
|
|
10
|
+
'update_expression',
|
|
11
|
+
'assignment_expression',
|
|
12
|
+
'augmented_assignment_expression',
|
|
13
|
+
'ternary_expression',
|
|
14
|
+
'conditional_expression',
|
|
15
|
+
// Call/access operators
|
|
16
|
+
'call_expression',
|
|
17
|
+
'method_call',
|
|
18
|
+
'member_expression',
|
|
19
|
+
'subscript_expression',
|
|
20
|
+
'attribute',
|
|
21
|
+
// Object/array literals ([] and {} are operators)
|
|
22
|
+
'array',
|
|
23
|
+
'object',
|
|
24
|
+
'dictionary',
|
|
25
|
+
'list',
|
|
26
|
+
]);
|
|
27
|
+
/**
|
|
28
|
+
* AST node types that represent operands.
|
|
29
|
+
*/
|
|
30
|
+
const OPERAND_NODE_TYPES = new Set([
|
|
31
|
+
// Identifiers
|
|
32
|
+
'identifier',
|
|
33
|
+
'property_identifier',
|
|
34
|
+
'shorthand_property_identifier',
|
|
35
|
+
'variable_name',
|
|
36
|
+
'name',
|
|
37
|
+
// Literals
|
|
38
|
+
'number',
|
|
39
|
+
'integer',
|
|
40
|
+
'float',
|
|
41
|
+
'string',
|
|
42
|
+
'string_fragment',
|
|
43
|
+
'template_string',
|
|
44
|
+
'true',
|
|
45
|
+
'false',
|
|
46
|
+
'null',
|
|
47
|
+
'undefined',
|
|
48
|
+
'none',
|
|
49
|
+
// Special
|
|
50
|
+
'this',
|
|
51
|
+
'self',
|
|
52
|
+
'super',
|
|
53
|
+
]);
|
|
54
|
+
/**
|
|
55
|
+
* Resolve operator sets for a language once, to avoid repeated lookups.
|
|
56
|
+
*/
|
|
57
|
+
function resolveOperators(language) {
|
|
58
|
+
const def = getLanguage(language);
|
|
59
|
+
return { symbols: def.complexity.operatorSymbols, keywords: def.complexity.operatorKeywords };
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Check if a node represents an operator
|
|
63
|
+
*/
|
|
64
|
+
function isOperator(node, ops) {
|
|
65
|
+
const nodeType = node.type;
|
|
66
|
+
const nodeText = node.text;
|
|
67
|
+
// Check if it's an operator node type
|
|
68
|
+
if (OPERATOR_NODE_TYPES.has(nodeType)) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
// Check if it's an operator symbol or keyword
|
|
72
|
+
return ops.symbols.has(nodeText) || ops.keywords.has(nodeText);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Check if a node represents an operand
|
|
76
|
+
*/
|
|
77
|
+
function isOperand(node) {
|
|
78
|
+
return OPERAND_NODE_TYPES.has(node.type);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get the canonical key for an operator (for counting distinct operators)
|
|
82
|
+
*/
|
|
83
|
+
function getOperatorKey(node) {
|
|
84
|
+
// For complex expressions, use the operator type
|
|
85
|
+
if (OPERATOR_NODE_TYPES.has(node.type)) {
|
|
86
|
+
// For binary/unary expressions, extract the actual operator
|
|
87
|
+
const operator = node.childForFieldName('operator');
|
|
88
|
+
if (operator) {
|
|
89
|
+
return operator.text;
|
|
90
|
+
}
|
|
91
|
+
return node.type;
|
|
92
|
+
}
|
|
93
|
+
return node.text;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get the canonical key for an operand (for counting distinct operands)
|
|
97
|
+
*/
|
|
98
|
+
function getOperandKey(node) {
|
|
99
|
+
return node.text;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Sum all values in a map
|
|
103
|
+
*/
|
|
104
|
+
function sumValues(map) {
|
|
105
|
+
let sum = 0;
|
|
106
|
+
for (const count of map.values()) {
|
|
107
|
+
sum += count;
|
|
108
|
+
}
|
|
109
|
+
return sum;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Count operators and operands in an AST node
|
|
113
|
+
*
|
|
114
|
+
* @param node - AST node to analyze (typically a function/method)
|
|
115
|
+
* @param language - Programming language for language-specific handling
|
|
116
|
+
* @returns HalsteadCounts with raw operator/operand counts
|
|
117
|
+
*/
|
|
118
|
+
export function countHalstead(node, language) {
|
|
119
|
+
const operators = new Map();
|
|
120
|
+
const operands = new Map();
|
|
121
|
+
const ops = resolveOperators(language);
|
|
122
|
+
function traverse(n) {
|
|
123
|
+
// Check if this is an operator
|
|
124
|
+
if (isOperator(n, ops)) {
|
|
125
|
+
const key = getOperatorKey(n);
|
|
126
|
+
operators.set(key, (operators.get(key) || 0) + 1);
|
|
127
|
+
}
|
|
128
|
+
// Check if this is an operand
|
|
129
|
+
if (isOperand(n)) {
|
|
130
|
+
const key = getOperandKey(n);
|
|
131
|
+
operands.set(key, (operands.get(key) || 0) + 1);
|
|
132
|
+
}
|
|
133
|
+
// Recurse into children
|
|
134
|
+
for (const child of n.children) {
|
|
135
|
+
traverse(child);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
traverse(node);
|
|
139
|
+
return {
|
|
140
|
+
n1: operators.size,
|
|
141
|
+
n2: operands.size,
|
|
142
|
+
N1: sumValues(operators),
|
|
143
|
+
N2: sumValues(operands),
|
|
144
|
+
operators,
|
|
145
|
+
operands,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Calculate derived Halstead metrics from raw counts
|
|
150
|
+
*
|
|
151
|
+
* Formulas based on Maurice Halstead's "Elements of Software Science" (1977):
|
|
152
|
+
* - Vocabulary (n) = n1 + n2
|
|
153
|
+
* - Length (N) = N1 + N2
|
|
154
|
+
* - Volume (V) = N × log₂(n) - size of implementation
|
|
155
|
+
* - Difficulty (D) = (n1/2) × (N2/n2) - error-proneness
|
|
156
|
+
* - Effort (E) = D × V - mental effort required
|
|
157
|
+
* - Time (T) = E / 18 - seconds to understand (Stroud number)
|
|
158
|
+
* - Bugs (B) = E^(2/3) / 3000 - estimated delivered bugs (effort-based variant)
|
|
159
|
+
*
|
|
160
|
+
* @param counts - Raw Halstead counts from countHalstead()
|
|
161
|
+
* @returns Calculated HalsteadMetrics
|
|
162
|
+
*/
|
|
163
|
+
export function calculateHalsteadMetrics(counts) {
|
|
164
|
+
const { n1, n2, N1, N2 } = counts;
|
|
165
|
+
const vocabulary = n1 + n2;
|
|
166
|
+
const length = N1 + N2;
|
|
167
|
+
// Avoid log(0) and division by zero
|
|
168
|
+
const volume = vocabulary > 0 ? length * Math.log2(vocabulary) : 0;
|
|
169
|
+
const difficulty = n2 > 0 ? (n1 / 2) * (N2 / n2) : 0;
|
|
170
|
+
const effort = difficulty * volume;
|
|
171
|
+
const time = effort / 18; // Stroud number (18 mental discriminations per second)
|
|
172
|
+
const bugs = Math.pow(effort, 2 / 3) / 3000;
|
|
173
|
+
return {
|
|
174
|
+
vocabulary: Math.round(vocabulary),
|
|
175
|
+
length: Math.round(length),
|
|
176
|
+
volume: Math.round(volume * 100) / 100,
|
|
177
|
+
difficulty: Math.round(difficulty * 100) / 100,
|
|
178
|
+
effort: Math.round(effort),
|
|
179
|
+
time: Math.round(time),
|
|
180
|
+
bugs: Math.round(bugs * 1000) / 1000,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Calculate Halstead metrics for an AST node in one call
|
|
185
|
+
*
|
|
186
|
+
* Convenience function that combines countHalstead and calculateHalsteadMetrics.
|
|
187
|
+
*
|
|
188
|
+
* @param node - AST node to analyze
|
|
189
|
+
* @param language - Programming language
|
|
190
|
+
* @returns Calculated HalsteadMetrics
|
|
191
|
+
*/
|
|
192
|
+
export function calculateHalstead(node, language) {
|
|
193
|
+
const counts = countHalstead(node, language);
|
|
194
|
+
return calculateHalsteadMetrics(counts);
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=halstead.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"halstead.js","sourceRoot":"","sources":["../../../src/ast/complexity/halstead.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AA8BvD;;;GAGG;AACH,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC;IAClC,uBAAuB;IACvB,mBAAmB;IACnB,kBAAkB;IAClB,mBAAmB;IACnB,uBAAuB;IACvB,iCAAiC;IACjC,oBAAoB;IACpB,wBAAwB;IAExB,wBAAwB;IACxB,iBAAiB;IACjB,aAAa;IACb,mBAAmB;IACnB,sBAAsB;IACtB,WAAW;IAEX,kDAAkD;IAClD,OAAO;IACP,QAAQ;IACR,YAAY;IACZ,MAAM;CACP,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IACjC,cAAc;IACd,YAAY;IACZ,qBAAqB;IACrB,+BAA+B;IAC/B,eAAe;IACf,MAAM;IAEN,WAAW;IACX,QAAQ;IACR,SAAS;IACT,OAAO;IACP,QAAQ;IACR,iBAAiB;IAC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AAE,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG,CAAC,GAAG,GAAG;QACtC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,GAAG,CAAC,GAAG,GAAG;QAC9C,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;QAC1B,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;QACtB,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,IAAI;KACrC,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAC/B,IAAuB,EACvB,QAA2B;IAE3B,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC7C,OAAO,wBAAwB,CAAC,MAAM,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Complexity metrics module
|
|
3
|
+
*
|
|
4
|
+
* This module provides various code complexity metrics:
|
|
5
|
+
* - Cyclomatic complexity: Counts decision points (branches) in code
|
|
6
|
+
* - Cognitive complexity: Measures mental effort to understand code (SonarSource spec)
|
|
7
|
+
* - Halstead metrics: Measures complexity based on operators/operands
|
|
8
|
+
*/
|
|
9
|
+
export { calculateComplexity } from './cyclomatic.js';
|
|
10
|
+
export { calculateCognitiveComplexity } from './cognitive.js';
|
|
11
|
+
export { countHalstead, calculateHalsteadMetrics, calculateHalstead } from './halstead.js';
|
|
12
|
+
export type { HalsteadCounts, HalsteadMetrics } from './halstead.js';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ast/complexity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC3F,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Complexity metrics module
|
|
3
|
+
*
|
|
4
|
+
* This module provides various code complexity metrics:
|
|
5
|
+
* - Cyclomatic complexity: Counts decision points (branches) in code
|
|
6
|
+
* - Cognitive complexity: Measures mental effort to understand code (SonarSource spec)
|
|
7
|
+
* - Halstead metrics: Measures complexity based on operators/operands
|
|
8
|
+
*/
|
|
9
|
+
export { calculateComplexity } from './cyclomatic.js';
|
|
10
|
+
export { calculateCognitiveComplexity } from './cognitive.js';
|
|
11
|
+
export { countHalstead, calculateHalsteadMetrics, calculateHalstead } from './halstead.js';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ast/complexity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { SupportedLanguage } from '../types.js';
|
|
2
|
+
import type { LanguageExportExtractor, LanguageImportExtractor, LanguageSymbolExtractor } from './types.js';
|
|
3
|
+
export type { LanguageExportExtractor, LanguageImportExtractor, LanguageSymbolExtractor, } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Get the export extractor for a specific language.
|
|
6
|
+
* Delegates to the language registry.
|
|
7
|
+
*
|
|
8
|
+
* @param language - Programming language
|
|
9
|
+
* @returns Language-specific export extractor
|
|
10
|
+
*/
|
|
11
|
+
export declare function getExtractor(language: SupportedLanguage): LanguageExportExtractor;
|
|
12
|
+
/**
|
|
13
|
+
* Get the import extractor for a specific language.
|
|
14
|
+
* Delegates to the language registry.
|
|
15
|
+
*
|
|
16
|
+
* @param language - Programming language
|
|
17
|
+
* @returns Language-specific import extractor, or undefined if not implemented
|
|
18
|
+
*/
|
|
19
|
+
export declare function getImportExtractor(language: SupportedLanguage): LanguageImportExtractor | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Get the symbol extractor for a specific language.
|
|
22
|
+
* Delegates to the language registry.
|
|
23
|
+
*
|
|
24
|
+
* @param language - Programming language
|
|
25
|
+
* @returns Language-specific symbol extractor, or undefined if not implemented
|
|
26
|
+
*/
|
|
27
|
+
export declare function getSymbolExtractor(language: SupportedLanguage): LanguageSymbolExtractor | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Check if a language has an export extractor implementation
|
|
30
|
+
*
|
|
31
|
+
* @param language - Programming language
|
|
32
|
+
* @returns True if extractor exists
|
|
33
|
+
*/
|
|
34
|
+
export declare function hasExtractor(language: string): boolean;
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ast/extractors/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAGpB,YAAY,EACV,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,YAAY,CAAC;AAEpB;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,iBAAiB,GAAG,uBAAuB,CAEjF;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,iBAAiB,GAC1B,uBAAuB,GAAG,SAAS,CAErC;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,iBAAiB,GAC1B,uBAAuB,GAAG,SAAS,CAErC;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEtD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getLanguage, languageExists } from '../languages/registry.js';
|
|
2
|
+
/**
|
|
3
|
+
* Get the export extractor for a specific language.
|
|
4
|
+
* Delegates to the language registry.
|
|
5
|
+
*
|
|
6
|
+
* @param language - Programming language
|
|
7
|
+
* @returns Language-specific export extractor
|
|
8
|
+
*/
|
|
9
|
+
export function getExtractor(language) {
|
|
10
|
+
return getLanguage(language).exportExtractor;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Get the import extractor for a specific language.
|
|
14
|
+
* Delegates to the language registry.
|
|
15
|
+
*
|
|
16
|
+
* @param language - Programming language
|
|
17
|
+
* @returns Language-specific import extractor, or undefined if not implemented
|
|
18
|
+
*/
|
|
19
|
+
export function getImportExtractor(language) {
|
|
20
|
+
return getLanguage(language).importExtractor;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get the symbol extractor for a specific language.
|
|
24
|
+
* Delegates to the language registry.
|
|
25
|
+
*
|
|
26
|
+
* @param language - Programming language
|
|
27
|
+
* @returns Language-specific symbol extractor, or undefined if not implemented
|
|
28
|
+
*/
|
|
29
|
+
export function getSymbolExtractor(language) {
|
|
30
|
+
return getLanguage(language).symbolExtractor;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Check if a language has an export extractor implementation
|
|
34
|
+
*
|
|
35
|
+
* @param language - Programming language
|
|
36
|
+
* @returns True if extractor exists
|
|
37
|
+
*/
|
|
38
|
+
export function hasExtractor(language) {
|
|
39
|
+
return languageExists(language);
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ast/extractors/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAQvE;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,QAA2B;IACtD,OAAO,WAAW,CAAC,QAAQ,CAAC,CAAC,eAAe,CAAC;AAC/C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAA2B;IAE3B,OAAO,WAAW,CAAC,QAAQ,CAAC,CAAC,eAAe,CAAC;AAC/C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAA2B;IAE3B,OAAO,WAAW,CAAC,QAAQ,CAAC,CAAC,eAAe,CAAC;AAC/C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,QAAgB;IAC3C,OAAO,cAAc,CAAC,QAAQ,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type Parser from 'tree-sitter';
|
|
2
|
+
/**
|
|
3
|
+
* Extract function/method signature
|
|
4
|
+
*/
|
|
5
|
+
export declare function extractSignature(node: Parser.SyntaxNode, content: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Extract parameter list from function node
|
|
8
|
+
*
|
|
9
|
+
* Note: The `_content` parameter is unused in this function, but is kept for API consistency
|
|
10
|
+
* with other extract functions (e.g., extractSignature).
|
|
11
|
+
*/
|
|
12
|
+
export declare function extractParameters(node: Parser.SyntaxNode, _content: string): string[];
|
|
13
|
+
/**
|
|
14
|
+
* Extract return type from function node (TypeScript)
|
|
15
|
+
*
|
|
16
|
+
* Note: The `_content` parameter is unused in this function, but is kept for API consistency
|
|
17
|
+
* with other extract functions (e.g., extractSignature).
|
|
18
|
+
*/
|
|
19
|
+
export declare function extractReturnType(node: Parser.SyntaxNode, _content: string): string | undefined;
|
|
20
|
+
//# sourceMappingURL=symbol-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"symbol-helpers.d.ts","sourceRoot":"","sources":["../../../src/ast/extractors/symbol-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CA0BjF;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAgBrF;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAK/F"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract function/method signature
|
|
3
|
+
*/
|
|
4
|
+
export function extractSignature(node, content) {
|
|
5
|
+
// Get the first line of the function (up to opening brace or arrow)
|
|
6
|
+
const startLine = node.startPosition.row;
|
|
7
|
+
const lines = content.split('\n');
|
|
8
|
+
let signature = lines[startLine] || '';
|
|
9
|
+
// If signature spans multiple lines, try to get up to the opening brace
|
|
10
|
+
let currentLine = startLine;
|
|
11
|
+
while (currentLine < node.endPosition.row &&
|
|
12
|
+
!signature.includes('{') &&
|
|
13
|
+
!signature.includes('=>')) {
|
|
14
|
+
currentLine++;
|
|
15
|
+
signature += ' ' + (lines[currentLine] || '');
|
|
16
|
+
}
|
|
17
|
+
// Clean up signature
|
|
18
|
+
signature = signature.split('{')[0].split('=>')[0].trim();
|
|
19
|
+
// Limit length
|
|
20
|
+
if (signature.length > 200) {
|
|
21
|
+
signature = signature.substring(0, 197) + '...';
|
|
22
|
+
}
|
|
23
|
+
return signature;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Extract parameter list from function node
|
|
27
|
+
*
|
|
28
|
+
* Note: The `_content` parameter is unused in this function, but is kept for API consistency
|
|
29
|
+
* with other extract functions (e.g., extractSignature).
|
|
30
|
+
*/
|
|
31
|
+
export function extractParameters(node, _content) {
|
|
32
|
+
const parameters = [];
|
|
33
|
+
// Find parameters node
|
|
34
|
+
const paramsNode = node.childForFieldName('parameters');
|
|
35
|
+
if (!paramsNode)
|
|
36
|
+
return parameters;
|
|
37
|
+
// Traverse parameter nodes
|
|
38
|
+
for (let i = 0; i < paramsNode.namedChildCount; i++) {
|
|
39
|
+
const param = paramsNode.namedChild(i);
|
|
40
|
+
if (param && param.text.trim()) {
|
|
41
|
+
parameters.push(param.text);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return parameters;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Extract return type from function node (TypeScript)
|
|
48
|
+
*
|
|
49
|
+
* Note: The `_content` parameter is unused in this function, but is kept for API consistency
|
|
50
|
+
* with other extract functions (e.g., extractSignature).
|
|
51
|
+
*/
|
|
52
|
+
export function extractReturnType(node, _content) {
|
|
53
|
+
const returnTypeNode = node.childForFieldName('return_type');
|
|
54
|
+
if (!returnTypeNode)
|
|
55
|
+
return undefined;
|
|
56
|
+
return returnTypeNode.text;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=symbol-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"symbol-helpers.js","sourceRoot":"","sources":["../../../src/ast/extractors/symbol-helpers.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAuB,EAAE,OAAe;IACvE,oEAAoE;IACpE,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC;IACzC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI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,CAAC;YAC/B,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAuB,EAAE,QAAgB;IACzE,MAAM,cAAc,GAAG,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;IAC7D,IAAI,CAAC,cAAc;QAAE,OAAO,SAAS,CAAC;IAEtC,OAAO,cAAc,CAAC,IAAI,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type Parser from 'tree-sitter';
|
|
2
|
+
import type { SymbolInfo } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Language-specific symbol extraction strategy
|
|
5
|
+
*
|
|
6
|
+
* Each language has different AST node types for functions, classes, and methods.
|
|
7
|
+
* This interface allows language-specific symbol extraction while keeping the
|
|
8
|
+
* core chunking logic language-agnostic.
|
|
9
|
+
*/
|
|
10
|
+
export interface LanguageSymbolExtractor {
|
|
11
|
+
/** AST node types this extractor can handle for symbol extraction */
|
|
12
|
+
readonly symbolNodeTypes: string[];
|
|
13
|
+
/** Extract symbol info (name, type, signature, etc.) from an AST node */
|
|
14
|
+
extractSymbol(node: Parser.SyntaxNode, content: string, parentClass?: string): SymbolInfo | null;
|
|
15
|
+
/** Extract symbol name and line from a call expression node */
|
|
16
|
+
extractCallSite(node: Parser.SyntaxNode): {
|
|
17
|
+
symbol: string;
|
|
18
|
+
line: number;
|
|
19
|
+
key: string;
|
|
20
|
+
} | null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Language-specific export extraction strategy
|
|
24
|
+
*
|
|
25
|
+
* Each language has different export semantics:
|
|
26
|
+
* - JavaScript/TypeScript: Explicit export statements
|
|
27
|
+
* - PHP: All top-level declarations are implicitly exported
|
|
28
|
+
* - Python: All module-level declarations are implicitly exported
|
|
29
|
+
*
|
|
30
|
+
* This interface allows us to implement language-specific export extraction
|
|
31
|
+
* while keeping the core symbol extraction logic language-agnostic.
|
|
32
|
+
*
|
|
33
|
+
* @example JavaScript/TypeScript
|
|
34
|
+
* ```typescript
|
|
35
|
+
* export function validateEmail() {} // Explicit export
|
|
36
|
+
* export { foo, bar } // Named exports
|
|
37
|
+
* export default App // Default export
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example PHP
|
|
41
|
+
* ```php
|
|
42
|
+
* class User {} // Implicitly exported
|
|
43
|
+
* function helper() {} // Implicitly exported
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @example Python
|
|
47
|
+
* ```python
|
|
48
|
+
* class User: # Implicitly exported
|
|
49
|
+
* pass
|
|
50
|
+
* def helper(): # Implicitly exported
|
|
51
|
+
* pass
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export interface LanguageExportExtractor {
|
|
55
|
+
/**
|
|
56
|
+
* Extract exported symbol names from an AST root node
|
|
57
|
+
*
|
|
58
|
+
* For JavaScript/TypeScript: Processes explicit export statements
|
|
59
|
+
* For PHP/Python: Processes top-level declarations (implicitly exported)
|
|
60
|
+
*
|
|
61
|
+
* @param rootNode - AST root node (typically 'program' or similar)
|
|
62
|
+
* @returns Array of exported symbol names (deduplicated)
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* // For: export { foo, bar }; export default App;
|
|
67
|
+
* extractExports(rootNode) // => ['foo', 'bar', 'default']
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
extractExports(rootNode: Parser.SyntaxNode): string[];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Language-specific import extraction strategy
|
|
74
|
+
*
|
|
75
|
+
* Each language has different import semantics:
|
|
76
|
+
* - JavaScript/TypeScript: import/export statements with source paths
|
|
77
|
+
* - PHP: namespace use declarations
|
|
78
|
+
* - Python: import/from...import statements with dotted paths
|
|
79
|
+
* - Rust: use declarations with crate/self/super paths
|
|
80
|
+
*
|
|
81
|
+
* This interface allows language-specific import extraction while
|
|
82
|
+
* keeping the core symbol extraction logic language-agnostic.
|
|
83
|
+
*/
|
|
84
|
+
export interface LanguageImportExtractor {
|
|
85
|
+
/**
|
|
86
|
+
* AST node types that represent import statements in this language.
|
|
87
|
+
* Used to identify which top-level nodes to process.
|
|
88
|
+
*/
|
|
89
|
+
readonly importNodeTypes: string[];
|
|
90
|
+
/**
|
|
91
|
+
* Extract the import path from an import node for the imports list.
|
|
92
|
+
*
|
|
93
|
+
* @param node - AST node matching one of importNodeTypes
|
|
94
|
+
* @returns The import path string, or null to skip
|
|
95
|
+
*/
|
|
96
|
+
extractImportPath(node: Parser.SyntaxNode): string | null;
|
|
97
|
+
/**
|
|
98
|
+
* Extract imported symbols mapped to their source path.
|
|
99
|
+
*
|
|
100
|
+
* @param node - AST node matching one of importNodeTypes
|
|
101
|
+
* @returns Object with importPath and symbols, or null to skip
|
|
102
|
+
*/
|
|
103
|
+
processImportSymbols(node: Parser.SyntaxNode): {
|
|
104
|
+
importPath: string;
|
|
105
|
+
symbols: string[];
|
|
106
|
+
} | null;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/ast/extractors/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,WAAW,uBAAuB;IACtC,qEAAqE;IACrE,QAAQ,CAAC,eAAe,EAAE,MAAM,EAAE,CAAC;IAEnC,yEAAyE;IACzE,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,I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