From a1f7eef28ae083c9048c4f65561d9fc36ae6aec7 Mon Sep 17 00:00:00 2001 From: sravan Date: Tue, 3 Nov 2026 21:33:01 +0530 Subject: [PATCH] build: pre-deploy HTML inline-script syntax guard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A missing brace in a home.html inline (skip ones with a src= attribute — those are external files, nothing inline). +const re = /]*)>([\s\S]*?)<\/script\s*>/gi; +let errors = 0; +let blocks = 0; + +for (const f of files) { + const html = fs.readFileSync(path.join(dir, f), 'utf8'); + re.lastIndex = 0; + let m; + while ((m = re.exec(html))) { + if (/\bsrc\s*=/i.test(m[1] || '')) continue; // external script + blocks++; + const code = m[2]; + // File line where this block's body starts, so the reported line is file-relative (not block-relative). + const openTagEnd = m.index + m[0].indexOf('>') + 1; + const startLine = html.slice(0, openTagEnd).split('\n').length - 1; // 0-indexed offset + try { + new vm.Script(code, { filename: f, lineOffset: startLine }); + } catch (e) { + errors++; + const loc = (String(e.stack || '').split('\n')[0] || '').trim(); // e.g. "home.html:4398" + console.error('[check-syntax] ' + f + ' — ' + (e.message || 'syntax error') + + (loc && /:\d+$/.test(loc) ? (' @ ' + loc) : (' (inline