From 4beb0186802645d81abfa611a27e4bbbdb43305f Mon Sep 17 00:00:00 2001 From: admtracksteel Date: Thu, 28 May 2026 12:03:53 +0000 Subject: [PATCH] Fix ReferenceError: Cannot access 'renderObsList' before initialization by converting arrow functions to standard hoisted functions --- public/app.js | 6 +-- scratch/debug_app.js | 97 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 scratch/debug_app.js diff --git a/public/app.js b/public/app.js index 77ac27c..81a68ee 100644 --- a/public/app.js +++ b/public/app.js @@ -2387,16 +2387,16 @@ const initApp = () => { if (obsSearchCrianca) obsSearchCrianca.addEventListener('input', renderObsList); // Preenche select de meses - const populateMonthFilter = () => { + function populateMonthFilter() { if (!obsFilterMes) return; const months = [...new Set(allObservations.map(o => o.date?.slice(0, 7)))] .filter(Boolean).sort().reverse(); obsFilterMes.innerHTML = '' + months.map(m => ``).join(''); - }; + } // Renderiza lista filtrada - const renderObsList = () => { + function renderObsList() { if (!obsList) return; const mes = obsFilterMes?.value || ''; const tag = obsFilterTag?.value || ''; diff --git a/scratch/debug_app.js b/scratch/debug_app.js new file mode 100644 index 0000000..43fd797 --- /dev/null +++ b/scratch/debug_app.js @@ -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); +}