// Shipped JavaScript must not use a name that nothing defines. // // A merge that drops a function leaves its callers behind, and nothing fails until a user taps the button // ("_appMenuHasMore is not defined"). This finds those at commit time: every identifier read that no script of the // same page declares, assigns, or sets on window, and that the browser does not provide. // // Pages, as the scripts really load together: // - Zimi's own page: every zimi/static/*.js (lazily loaded ones share the one global scope) plus the inline scripts of // zimi/templates/index.html and zimi/static/*.html. // - Each page under zimi/builtin//: the scripts its own ').map((a) => { return a; })); continue; } if (/^(https?:)?\/\//.test(s.src)) continue; const clean = s.src.split('?')[0]; const file = clean.startsWith('/static/') ? path.join(STATIC, clean.slice(8)) : path.resolve(path.dirname(page), clean); if (fs.existsSync(file)) scripts.push(loadCached(path.relative(ROOT, file), file)); } if (!scripts.length) continue; problems.push.apply(problems, check(rel, scripts, app.name === 'almanac' ? zimi : [])); } } } let failed = false; if (parseErrors.length) { failed = true; console.log('Could not parse:\n ' + parseErrors.join('\n ')); } const unique = [...new Set(problems)]; if (unique.length) { failed = true; console.log('Names used and defined nowhere on their page (' + unique.length + '):\n ' + unique.join('\n ')); } if (failed) process.exit(1); console.log('ok: no undefined names across ' + Object.keys(cache).length + ' builtin scripts and ' + zimi.length + ' Zimi scripts');