UNPKG

agentsqripts

Version:

Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems

67 lines (60 loc) 1.75 kB
/** * @file Existing exports extraction * @description Extracts existing exports from file content */ // Import patterns from atomic module const { PATTERNS } = require('./patterns'); /** * Extract existing exports from file content * @param {string} content - File content * @returns {Array} Array of export objects */ function extractExistingExports(content) { const lines = content.split('\n'); const exports = []; for (let index = 0; index < lines.length; index++) { const line = lines[index]; // Named exports if (PATTERNS.export.test(line)) { const match = line.match(/export\s+(?:const|function|class|let|var)\s+([a-zA-Z0-9_$]+)/); if (match) { exports.push({ type: 'named', name: match[1], line: index + 1, content: line.trim() }); } } // Default exports if (PATTERNS.exportDefault.test(line)) { exports.push({ type: 'default', name: 'default', line: index + 1, content: line.trim() }); } // Re-exports - process without nested iteration if (PATTERNS.exportNamed.test(line)) { const match = line.match(/export\s+\{([^}]+)\}/); if (match) { const namesList = match[1].split(','); // Process names without any nested operations for (let i = 0; i < namesList.length; i++) { const name = namesList[i].trim(); exports.push({ type: 'reexport', name: name.replace(/\s+as\s+.*/, ''), // Remove 'as alias' part line: index + 1, content: line.trim() }); } } } } return exports; } module.exports = { extractExistingExports };