Fix ReferenceError: Cannot access 'renderObsList' before initialization by converting arrow functions to standard hoisted functions

This commit is contained in:
2026-05-28 12:03:53 +00:00
parent 66cdf62d9b
commit 4beb018680
2 changed files with 100 additions and 3 deletions
+3 -3
View File
@@ -2387,16 +2387,16 @@ const initApp = () => {
if (obsSearchCrianca) obsSearchCrianca.addEventListener('input', renderObsList); if (obsSearchCrianca) obsSearchCrianca.addEventListener('input', renderObsList);
// Preenche select de meses // Preenche select de meses
const populateMonthFilter = () => { function populateMonthFilter() {
if (!obsFilterMes) return; if (!obsFilterMes) return;
const months = [...new Set(allObservations.map(o => o.date?.slice(0, 7)))] const months = [...new Set(allObservations.map(o => o.date?.slice(0, 7)))]
.filter(Boolean).sort().reverse(); .filter(Boolean).sort().reverse();
obsFilterMes.innerHTML = '<option value="">Todos os meses</option>' + obsFilterMes.innerHTML = '<option value="">Todos os meses</option>' +
months.map(m => `<option value="${m}">${m.split('-')[1]}/${m.split('-')[0]}</option>`).join(''); months.map(m => `<option value="${m}">${m.split('-')[1]}/${m.split('-')[0]}</option>`).join('');
}; }
// Renderiza lista filtrada // Renderiza lista filtrada
const renderObsList = () => { function renderObsList() {
if (!obsList) return; if (!obsList) return;
const mes = obsFilterMes?.value || ''; const mes = obsFilterMes?.value || '';
const tag = obsFilterTag?.value || ''; const tag = obsFilterTag?.value || '';
+97
View File
@@ -0,0 +1,97 @@
const fs = require('fs');
const path = require('path');
const html = fs.readFileSync(path.join(__dirname, '../public/index.html'), 'utf8');
// Mock HTML elements from index.html
const elements = {};
const matchIds = html.match(/id="([^"]+)"/g) || [];
matchIds.forEach(idAttr => {
const id = idAttr.split('"')[1];
elements[id] = {
id,
addEventListener: (event, cb) => {},
style: {},
classList: {
add: () => {},
remove: () => {},
contains: () => false
},
querySelectorAll: () => []
};
});
global.document = {
readyState: 'complete',
documentElement: {
setAttribute: (name, val) => {},
getAttribute: (name) => 'dark'
},
getElementById: (id) => {
if (!elements[id]) {
console.warn(`[Warning] getElementById: ID "${id}" not found in index.html!`);
return null;
}
return elements[id];
},
querySelector: (selector) => {
return {
addEventListener: () => {},
style: {},
classList: { add: () => {}, remove: () => {} }
};
},
querySelectorAll: (selector) => {
return [];
},
createElement: (tag) => {
return { style: {}, classList: { add: () => {} } };
},
body: {
appendChild: () => {}
},
addEventListener: (event, cb) => {
if (event === 'DOMContentLoaded') {
cb();
}
}
};
global.window = {
location: { href: '' },
speechSynthesis: {
getVoices: () => [],
addEventListener: () => {}
},
document: global.document
};
global.localStorage = {
getItem: () => null,
setItem: () => {},
removeItem: () => {}
};
global.marked = {
Renderer: function() {},
use: () => {}
};
global.navigator = {
clipboard: {}
};
// Mock fetch to not crash Node
global.fetch = () => new Promise((resolve) => resolve({
ok: true,
json: () => Promise.resolve({ success: true, observations: [] }),
text: () => Promise.resolve('')
}));
try {
console.log("Loading public/app.js with proper mock...");
require('../public/app.js');
console.log("Successfully ran public/app.js without throwing errors!");
} catch (err) {
console.error("FATAL ERROR running app.js:", err);
}