Skip to content

Commit 1d4927f

Browse files
committed
1 parent 517143e commit 1d4927f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/zimscraperlib/rewriting/js.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def create_js_rules() -> list[TransformationRule]:
162162
(re.compile(r"\.postMessage\b\("), add_prefix(".__WB_pmw(self)")),
163163
# rewriting `location = ` to custom expression `(...).href =` assignement
164164
(
165-
re.compile(r"(?:^|[^$.+*/%^-])\s?\blocation\b\s*[=]\s*(?![\s\d=])"),
165+
re.compile(r"(?:^|[^$.+*/%^-])\s?\blocation\b\s*[=]\s*(?![\s\d=>])"),
166166
add_suffix_non_prop(check_loc),
167167
),
168168
# rewriting `return this`

tests/rewriting/test_js_rewriting.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ def wrap_script(text: str) -> str:
186186
"self.__WB_check_loc(location, argument"
187187
"s)) || {}).href = http://example.com/",
188188
),
189+
WrappedTestContent(
190+
input_='location => "http://example.com/"',
191+
expected='location => "http://example.com/"',
192+
),
189193
WrappedTestContent(
190194
input_=" location = http://example.com/2",
191195
expected=" location = ((self.__WB_check_loc && "
@@ -220,6 +224,24 @@ def wrap_script(text: str) -> str:
220224
expected="if (self.foo) { console.log('blah') }",
221225
),
222226
WrappedTestContent(input_="window.x = 5", expected="window.x = 5"),
227+
WrappedTestContent(
228+
input_="""
229+
class A {}
230+
const B = 5;
231+
let C = 4;
232+
var D = 3;
233+
234+
location = "http://example.com/2" """,
235+
expected="""
236+
class A {}
237+
const B = 5;
238+
let C = 4;
239+
var D = 3;
240+
241+
location = ((self.__WB_check_loc && """
242+
"self.__WB_check_loc(location, arguments)) || {}).href "
243+
"""= "http://example.com/2" """,
244+
),
223245
WrappedTestContent(input_=" var self ", expected=" let self "),
224246
]
225247
)

0 commit comments

Comments
 (0)