import re with open('app.js', 'r') as f: code = f.read() # 1. _buildShell shell = """ _buildShell() { if (!this.dom.mainPanel) return; this.dom.mainPanel.innerHTML = `
`; }, """ code = code.replace('async init() {', shell + '\n async init() {') code = code.replace('this.cacheDOM();', 'this.cacheDOM();\n this._buildShell();') # 2. Rename render() to _renderAll() code = code.replace('render() {', '_renderAll() {') # 3. Targeted updates code = code.replace('this.render();', 'this._renderAll();') # 4. Results: binaryData ALWAYS nulled after blobUrl created code = re.sub(r'(resultItem\.blobUrl = res\.blobUrl;)', r'\1\n resultItem.binaryData = null;', code) # 5. saveState skip during bulk # Already in code: if (this.state.bulk && this.state.bulk.running) return; with open('app.js', 'w') as f: f.write(code) print("Rewrite done via Python")