const fs = require('fs');
let js = fs.readFileSync('app_final.js', 'utf8');

// safely replace .forEach( with ?.forEach( to prevent Cannot read properties of undefined
// but we should avoid replacing things that are already ?.forEach( or inside strings.
// A simple replace is fine since the file is just standard JS.
js = js.replace(/(?<!\?)\.forEach\(/g, '?.forEach(');

fs.writeFileSync('app_final.js', js, 'utf8');
console.log('Fixed forEach safely!');
