Remove redundant code and deduplicate indexFile
- Remove extractFunctionVariable() and its dispatch (already handled by extractVariable) - Remove dead getGrammar() export (zero callers) - Deduplicate indexFile by delegating to indexFileWithContent - Remove redundant arrow function variable extraction tests (covered by existing suite)
This commit is contained in:
@@ -156,14 +156,6 @@ function loadGrammar(language: Language): unknown | null {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a grammar by language, loading it lazily if needed.
|
||||
* Exported for direct grammar access without parser initialization.
|
||||
*/
|
||||
export function getGrammar(language: string): unknown | null {
|
||||
return loadGrammar(language as Language);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a parser for the specified language
|
||||
*/
|
||||
|
||||
+2
-38
@@ -487,7 +487,7 @@ export class ExtractionOrchestrator {
|
||||
};
|
||||
}
|
||||
|
||||
// Check file exists and is readable
|
||||
// Read file content and stats
|
||||
let content: string;
|
||||
let stats: fs.Stats;
|
||||
try {
|
||||
@@ -509,43 +509,7 @@ export class ExtractionOrchestrator {
|
||||
};
|
||||
}
|
||||
|
||||
// Check file size
|
||||
if (stats.size > this.config.maxFileSize) {
|
||||
return {
|
||||
nodes: [],
|
||||
edges: [],
|
||||
unresolvedReferences: [],
|
||||
errors: [
|
||||
{
|
||||
message: `File exceeds max size (${stats.size} > ${this.config.maxFileSize})`,
|
||||
severity: 'warning',
|
||||
},
|
||||
],
|
||||
durationMs: 0,
|
||||
};
|
||||
}
|
||||
|
||||
// Detect language
|
||||
const language = detectLanguage(relativePath);
|
||||
if (!isLanguageSupported(language)) {
|
||||
return {
|
||||
nodes: [],
|
||||
edges: [],
|
||||
unresolvedReferences: [],
|
||||
errors: [],
|
||||
durationMs: 0,
|
||||
};
|
||||
}
|
||||
|
||||
// Extract from source
|
||||
const result = extractFromSource(relativePath, content, language);
|
||||
|
||||
// Store in database
|
||||
if (result.nodes.length > 0 || result.errors.length === 0) {
|
||||
this.storeExtractionResult(relativePath, content, language, stats, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
return this.indexFileWithContent(relativePath, content, stats);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -978,14 +978,6 @@ export class TreeSitterExtractor {
|
||||
else if (this.extractor.typeAliasTypes.includes(nodeType)) {
|
||||
this.extractTypeAlias(node);
|
||||
}
|
||||
// Check for arrow functions / function expressions assigned to variables (JS/TS)
|
||||
else if (nodeType === 'variable_declarator') {
|
||||
const valueNode = getChildByField(node, 'value');
|
||||
if (valueNode && (valueNode.type === 'arrow_function' || valueNode.type === 'function_expression')) {
|
||||
this.extractFunctionVariable(node);
|
||||
skipChildren = true;
|
||||
}
|
||||
}
|
||||
// Check for variable declarations (const, let, var, etc.)
|
||||
// Only extract top-level variables (not inside functions/methods)
|
||||
else if (this.extractor.variableTypes.includes(nodeType) && !this.isInsideClassLikeNode()) {
|
||||
@@ -1109,62 +1101,6 @@ export class TreeSitterExtractor {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract an arrow function or function expression assigned to a variable.
|
||||
* Handles patterns like: const foo = () => {} or const bar = function() {}
|
||||
*/
|
||||
private extractFunctionVariable(node: SyntaxNode): void {
|
||||
if (!this.extractor) return;
|
||||
|
||||
// Only handle variable_declarator where value is arrow_function or function_expression
|
||||
if (node.type !== 'variable_declarator') return;
|
||||
|
||||
const nameNode = getChildByField(node, 'name');
|
||||
const valueNode = getChildByField(node, 'value');
|
||||
|
||||
if (!nameNode || !valueNode) return;
|
||||
if (valueNode.type !== 'arrow_function' && valueNode.type !== 'function_expression') return;
|
||||
|
||||
const name = getNodeText(nameNode, this.source);
|
||||
if (!name) return;
|
||||
|
||||
// Check if exported by walking parents
|
||||
let isExported = false;
|
||||
let current = node.parent;
|
||||
while (current) {
|
||||
if (current.type === 'export_statement') {
|
||||
isExported = true;
|
||||
break;
|
||||
}
|
||||
if (current.type === 'program' || current.type === 'module') break;
|
||||
current = current.parent;
|
||||
}
|
||||
|
||||
// Build signature from the arrow function parameters
|
||||
let signature: string | undefined;
|
||||
const params = getChildByField(valueNode, 'parameters');
|
||||
if (params) {
|
||||
signature = `${name}${getNodeText(params, this.source)}`;
|
||||
}
|
||||
|
||||
// Check if async
|
||||
const isAsync = this.extractor.isAsync?.(valueNode);
|
||||
|
||||
const funcNode = this.createNode('function', name, node, {
|
||||
isExported,
|
||||
signature: signature || undefined,
|
||||
isAsync,
|
||||
});
|
||||
|
||||
// Push to stack and visit body for call extraction
|
||||
this.nodeStack.push(funcNode.id);
|
||||
const body = getChildByField(valueNode, this.extractor.bodyField);
|
||||
if (body) {
|
||||
this.visitFunctionBody(body, funcNode.id);
|
||||
}
|
||||
this.nodeStack.pop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract a function
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user