const fs = require('fs');
const content = fs.readFileSync('dist/assets/index-D9sWWWv_.js', 'utf8');

let idx = 990820;
// Search backwards from idx for "Re" assignment
let sub = content.substring(idx - 10000, idx);
let pos = sub.lastIndexOf('const Re');
if (pos !== -1) {
  console.log('Found "const Re" backwards at relative position', pos);
  console.log(sub.substring(pos, pos + 1000));
} else {
  // Let's find any assignment to Re in a wider range
  let pos2 = sub.lastIndexOf('Re=');
  if (pos2 !== -1) {
    console.log('Found "Re=" backwards at relative position', pos2);
    console.log(sub.substring(pos2 - 100, pos2 + 500));
  } else {
    console.log('Not found in immediate backwards 10KB. Let\'s search from start for "const Re" or "let Re"');
    let regex = /\b(const|let|var)\s+Re\b/g;
    let match;
    while ((match = regex.exec(content)) !== null) {
      console.log(`Found Re declaration at index ${match.index}:`);
      console.log(content.substring(match.index - 50, match.index + 200));
    }
  }
}
