import { wrapMinimal } from '../utils.js';
export function parseComShell(codigo) {
    const functions = Array.from(codigo.matchAll(/^\s*(function\s+)?([A-Za-z0-9_]+)\s*\(\)\s*\{/gm)).map(m => m[2]);
    const exports = Array.from(codigo.matchAll(/\bexport\s+([A-Za-z0-9_]+)=/g)).map(m => m[1]);
    const variables = Array.from(codigo.matchAll(/^([A-Za-z_][A-Za-z0-9_]*)\s*=(?!=)/gm)).map(m => m[1]);
    const aliases = Array.from(codigo.matchAll(/^\s*alias\s+([A-Za-z0-9_-]+)=/gm)).map(m => m[1]);
    const traps = Array.from(codigo.matchAll(/^\s*trap\s+(.+)/gm)).map(m => m[1].trim());
    const sources = Array.from(codigo.matchAll(/^\s*(?:source|\.)\s+([^\s]+)/gm)).map(m => m[1]);
    const shebang = codigo.startsWith('#!') ? codigo.split('\n')[0].trim() : null;
    const hasIf = (codigo.match(/\bif\s+\[/g) || []).length;
    const hasFor = (codigo.match(/\bfor\s+/g) || []).length;
    const hasWhile = (codigo.match(/\bwhile\s+/g) || []).length;
    const hasCase = (codigo.match(/\bcase\s+/g) || []).length;
    const comments = (codigo.match(/^\s*#/gm) || []).length;
    const nonEmptyLines = codigo.split('\n').filter(l => l.trim()).length;
    const environmentVars = Array.from(codigo.matchAll(/\$\{?([A-Z_][A-Z0-9_]+)\}?/g)).map(m => m[1]);
    const uniqueEnvVars = [...new Set(environmentVars)];
    return wrapMinimal('shell', {
        functions,
        exported: exports,
        variables,
        aliases,
        traps,
        sources,
        shebang,
        hasIf,
        hasFor,
        hasWhile,
        hasCase,
        comments,
        nonEmptyLines,
        environmentVars: uniqueEnvVars,
        functionCount: functions.length
    });
}
//# sourceMappingURL=shell.js.map