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

// We know the mess starts around line 2865
let pre = js.substring(0, js.indexOf('window.openClientAbstractModal'));
let post = js.substring(js.indexOf('window.openClientAbstractModal'));

// Fix literal \`, \${, \\n
post = post.replace(/\\`/g, '`');
post = post.replace(/\\\$\\{/g, '${');
post = post.replace(/\\n/g, '\n');

// Wait! If I replace all \n with actual newlines, any genuine \n in a string literal becomes a newline. Is that bad?
// Yes. Instead, let's just use regex for the known broken ones.

fs.writeFileSync('app_final.js', pre + post, 'utf8');
console.log('Fixed rest of syntax!');
