import TreesitterSemanticChunker from './lib/treesitter-semantic-chunker.js';
const chunker = new TreesitterSemanticChunker({
namingStrategy: 'domain-based'
});
console.log('š TREESITTER SEMANTIC CHUNKING TEST');
console.log('====================================\n');
console.log('š Testing treesitter-based analysis...\n');
try {
const result = await chunker.analyzeProject('.', ['web/src/**/*.{js,jsx,ts,tsx}']);
// Project Overview
console.log('š PROJECT OVERVIEW');
console.log(`š Files analyzed: ${result.summary.totalFiles}`);
console.log(`š¦ Semantic chunks created: ${result.summary.totalChunks}`);
console.log(`š¾ Total code size: ${Math.round(result.summary.totalSize / 1024)}KB`);
console.log(`š Total lines of code: ${result.summary.totalLines.toLocaleString()}`);
// Semantic Types
console.log('\nšÆ SEMANTIC TYPES');
Object.entries(result.summary.semanticTypes).forEach(([type, count]) => {
console.log(` ${type}: ${count} files`);
});
// Business Domains
console.log('\nš¢ BUSINESS DOMAINS');
Object.entries(result.summary.businessDomains).forEach(([domain, count]) => {
console.log(` ${domain}: ${count} occurrences`);
});
// Technical Patterns
console.log('\nāļø TECHNICAL PATTERNS');
Object.entries(result.summary.technicalPatterns).forEach(([pattern, count]) => {
console.log(` ${pattern}: ${count} files`);
});
// Smart Chunks
console.log('\nš§© SMART SEMANTIC CHUNKS');
console.log('==========================');
result.chunks.forEach((chunk, i) => {
console.log(`\n${i + 1}. š¦ ${chunk.name.toUpperCase()}`);
console.log(` š ${chunk.files.length} files | ${Math.round(chunk.size / 1024)}KB | ${chunk.purpose}`);
console.log(` šÆ Cohesion: ${chunk.cohesion.toFixed(2)} | Complexity: ${chunk.complexity.level}`);
console.log(` š¢ Domains: ${chunk.businessDomains.join(', ') || 'none'}`);
console.log(` āļø Patterns: ${chunk.technicalPatterns.join(', ') || 'none'}`);
console.log(` š Files: ${chunk.files.slice(0, 3).map(f => f.split('/').pop()).join(', ')}${chunk.files.length > 3 ? `... +${chunk.files.length - 3} more` : ''}`);
if (chunk.recommendations.length > 0) {
console.log(` š” ${chunk.recommendations[0].message}`);
}
});
console.log('\n⨠TREESITTER ANALYSIS COMPLETE!');
console.log('=================================');
console.log('š Treesitter provides deeper semantic understanding');
console.log('š§ Smart clustering based on AST analysis');
console.log('šÆ Business domain extraction from code structure');
console.log('š Technical pattern recognition');
console.log('š Dependency relationship mapping');
} catch (error) {
console.error('ā Treesitter analysis failed:', error.message);
console.error(error.stack);
}