From 8aab96b6d1f14ca1df588676ca136c2cf0259c2e Mon Sep 17 00:00:00 2001 From: benoit74 Date: Thu, 29 Oct 2026 09:32:10 +0000 Subject: [PATCH 1/3] Hoist top-level function declarations out of the wombat block Backport of webrecorder/wabac.js#380 (fixes webrecorder/wabac.js#379): - carry top-level function declarations across the block, re-declared as var as they are on the global scope - re-declare classes as let instead of const, their binding can be reassigned - rename the carrier from self.___WB_const_x to self.___WB_hoist_x --- CHANGELOG.md | 2 +- src/zimscraperlib/rewriting/js.py | 40 ++++++---- src/zimscraperlib/rewriting/js_ast.py | 25 ++++--- tests/rewriting/test_js_globals.py | 104 +++++++++++++++++++------- tests/rewriting/test_js_rewriting.py | 17 +++-- 5 files changed, 129 insertions(+), 59 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 075b83e..a273802 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Rewrite `save_large_file` to stream and resume the download itself instead of running `wget` once, whose `-t` counter is a budget for the whole download: a flaky connection now keeps resuming and the retry budget only counts attempts that make no progress, so long downloads are no longer abandoned mid-way (#348) -- Carry a script's top-level `const`, `let` and `class` declarations across the wombat block, so other scripts on the page can still see them (#329) +- Carry a script's top-level `const`, `let`, `class` and `function` declarations across the wombat block, so other scripts on the page can still see them, re-declaring classes with `let` so they can be reassigned (#329, webrecorder/wabac.js#380) - Keep a rewritten `