import { traverse } from '../../core/config/index.js';
export class DedupeManager {
    relPath;
    seen = new Set();
    occurrences = [];
    constructor(relPath) {
        this.relPath = relPath;
    }
    add(ocorrencia) {
        const relPath = this.relPath || ocorrencia.relPath || '';
        const linha = ocorrencia.linha || 0;
        const key = `${ocorrencia.mensagem}|${relPath}|${linha}`;
        if (this.seen.has(key))
            return;
        this.seen.add(key);
        this.occurrences.push(ocorrencia);
    }
    getResults() {
        return this.occurrences;
    }
}
export function runUniqueVisitor(ast, relPath, visitor, initialState = {}) {
    const manager = new DedupeManager(relPath);
    const state = { ...initialState, manager, relPath };
    const nodeToTraverse = ast?.node || ast;
    if (!nodeToTraverse)
        return [];
    try {
        traverse(nodeToTraverse, visitor, undefined, state);
    }
    catch {
    }
    return manager.getResults();
}
//# sourceMappingURL=ast-visitor-utils.js.map