From 289b0197e7809892a02e83760ad8fb9ecbb81b32 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 8 May 2026 06:21:55 +0200 Subject: [PATCH] remove redundant app wrappers --- public/js/app.js | 54 ++++++++++++++++----------------- test/module-entrypoints.test.js | 7 ++++- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index 58369b4..7086b11 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -3,25 +3,25 @@ // ============================================================ // ── Client-side error logging ────────────────────────────── -(function() { - function sendError(data) { - try { - navigator.sendBeacon('/api/logs/client-error', new Blob( - [JSON.stringify(data)], { type: 'application/json' } - )); - } catch(e) {} - } - window.onerror = function(msg, src, line, col, err) { - // Ignore errors from browser extensions - if (src && src.indexOf('moz-extension') !== -1) return; - if (src && src.indexOf('chrome-extension') !== -1) return; - sendError({ type: 'uncaught', message: String(msg), source: src, line: line, col: col, stack: err && err.stack }); - }; - window.addEventListener('unhandledrejection', function(e) { - var msg = e.reason ? (e.reason.message || String(e.reason)) : 'Unhandled promise rejection'; - sendError({ type: 'unhandledrejection', message: msg, stack: e.reason && e.reason.stack }); - }); -})(); +function sendError(data) { + try { + navigator.sendBeacon('/api/logs/client-error', new Blob( + [JSON.stringify(data)], { type: 'application/json' } + )); + } catch(e) {} +} + +window.onerror = function(msg, src, line, col, err) { + // Ignore errors from browser extensions + if (src && src.indexOf('moz-extension') !== -1) return; + if (src && src.indexOf('chrome-extension') !== -1) return; + sendError({ type: 'uncaught', message: String(msg), source: src, line: line, col: col, stack: err && err.stack }); +}; + +window.addEventListener('unhandledrejection', function(e) { + var msg = e.reason ? (e.reason.message || String(e.reason)) : 'Unhandled promise rejection'; + sendError({ type: 'unhandledrejection', message: msg, stack: e.reason && e.reason.stack }); +}); document.addEventListener('DOMContentLoaded', function() { @@ -410,15 +410,13 @@ function loadAnnouncement() { } // Close button — dismiss for this page view only (reappears on refresh/re-login) -(function() { - var closeBtn = document.getElementById('announcement-close'); - if (closeBtn) { - closeBtn.addEventListener('click', function() { - var banner = document.getElementById('announcement-banner'); - if (banner) banner.classList.add('hidden'); - }); - } -})(); +var closeBtn = document.getElementById('announcement-close'); +if (closeBtn) { + closeBtn.addEventListener('click', function() { + var banner = document.getElementById('announcement-banner'); + if (banner) banner.classList.add('hidden'); + }); +} function getSelectedModel() { // Prefer the active tab's own model selector if present diff --git a/test/module-entrypoints.test.js b/test/module-entrypoints.test.js index 44be63b..88e64bc 100644 --- a/test/module-entrypoints.test.js +++ b/test/module-entrypoints.test.js @@ -11,6 +11,11 @@ const moduleEntrypoints = [ 'public/js/wellVisit.js' ]; +const iifeFreeEntrypoints = [ + ...moduleEntrypoints, + 'public/js/app.js' +]; + function readProjectFile(relativePath) { return fs.readFileSync(path.join(__dirname, '..', relativePath), 'utf8'); } @@ -25,7 +30,7 @@ test('refactored frontend entrypoints are loaded as modules', () => { }); test('refactored module entrypoints do not use redundant IIFE wrappers', () => { - moduleEntrypoints.forEach((entrypoint) => { + iifeFreeEntrypoints.forEach((entrypoint) => { const source = readProjectFile(entrypoint); assert.doesNotMatch(source, /^\s*\(function\s*\(/m, `${entrypoint} should not open an IIFE wrapper`); assert.doesNotMatch(source, /^\s*\}\)\(\);\s*$/m, `${entrypoint} should not close an IIFE wrapper`);