From d055816ec387215f61c6191cce9dbc75f00aab24 Mon Sep 17 00:00:00 2001 From: Alex Osborne Date: Thu, 21 Mar 2024 15:00:45 +0900 Subject: [PATCH] rewrite: stop prepending semicolon to `this.` special property access (#850) The prepended semicolon breaks code (such as jQuery) that looks like: foo = foo ? foo : this.location; I think the reason we started inserting the semicolon was because in situations like: x = 1 + 2 this.location = "foo" we used to rewrite to: x = 1 + 2 (this && this._WB_wombat_obj_proxy || this).location = "foo" which the browser would interpret as a bogus function call like `2(this && ... )`. But nowadays prepending the semicolon should be unnecessary as we currently rewrite to: x = 2 + 3 _____WB$wombat$check$this$function_____(this).location = "foo" which will trigger JavaScript's automatic semicolon insertion rules like the original code does. --- pywb/rewrite/regex_rewriters.py | 4 +--- pywb/rewrite/test/test_regex_rewriters.py | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pywb/rewrite/regex_rewriters.py b/pywb/rewrite/regex_rewriters.py index e862eabe..bffeddde 100644 --- a/pywb/rewrite/regex_rewriters.py +++ b/pywb/rewrite/regex_rewriters.py @@ -124,9 +124,7 @@ if (!self.__WB_pmw) {{ self.__WB_pmw = function(obj) {{ this.__WB_source = obj; (r'(?>> _test_js_obj_proxy('A = B\nthis.location = "foo"') -'A = B\n;_____WB$wombat$check$this$function_____(this).location = "foo"' +'A = B\n_____WB$wombat$check$this$function_____(this).location = "foo"' >>> _test_js_obj_proxy('var foo = this.location2') 'var foo = this.location2'