fix: Fallback to filename when Pascal module name is empty
Some .dpr templates use "program;" without a name, which produces an empty moduleName in the AST. Fall back to the filename (without extension) to prevent nodes with empty names that cause downstream FK constraint errors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
482cbee0d0
commit
763e280829
@@ -1850,6 +1850,16 @@ describe('Pascal / Delphi Extraction', () => {
|
|||||||
expect(moduleNode).toBeDefined();
|
expect(moduleNode).toBeDefined();
|
||||||
expect(moduleNode?.name).toBe('MyApp');
|
expect(moduleNode?.name).toBe('MyApp');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should fallback to filename when module name is empty', () => {
|
||||||
|
// Some .dpr templates use "program;" without a name
|
||||||
|
const code = `program;\nuses SysUtils;\nbegin\nend.`;
|
||||||
|
const result = extractFromSource('Console.dpr', code);
|
||||||
|
|
||||||
|
const moduleNode = result.nodes.find((n) => n.kind === 'module');
|
||||||
|
expect(moduleNode).toBeDefined();
|
||||||
|
expect(moduleNode?.name).toBe('Console');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Uses clause (imports)', () => {
|
describe('Uses clause (imports)', () => {
|
||||||
|
|||||||
@@ -2056,10 +2056,10 @@ export class TreeSitterExtractor {
|
|||||||
const moduleNameNode = node.namedChildren.find(
|
const moduleNameNode = node.namedChildren.find(
|
||||||
(c: SyntaxNode) => c.type === 'moduleName'
|
(c: SyntaxNode) => c.type === 'moduleName'
|
||||||
);
|
);
|
||||||
if (moduleNameNode) {
|
const name = moduleNameNode ? getNodeText(moduleNameNode, this.source) : '';
|
||||||
const name = getNodeText(moduleNameNode, this.source);
|
// Fallback to filename without extension if module name is empty
|
||||||
this.createNode('module', name, node);
|
const moduleName = name || path.basename(this.filePath).replace(/\.[^.]+$/, '');
|
||||||
}
|
this.createNode('module', moduleName, node);
|
||||||
// Continue visiting children (interface/implementation sections)
|
// Continue visiting children (interface/implementation sections)
|
||||||
for (let i = 0; i < node.namedChildCount; i++) {
|
for (let i = 0; i < node.namedChildCount; i++) {
|
||||||
const child = node.namedChild(i);
|
const child = node.namedChild(i);
|
||||||
|
|||||||
Reference in New Issue
Block a user