From 791a8d1033ce91c731eb08b5c5ad916b64aeef4c Mon Sep 17 00:00:00 2001 From: Alex Osborne Date: Wed, 10 Apr 2024 01:37:55 +0900 Subject: [PATCH] rewrite: stop prepending semicolon to `this.` special property access (#850) (#888) 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 e862eabed..bffeddded 100644 --- a/pywb/rewrite/regex_rewriters.py +++ b/pywb/rewrite/regex_rewriters.py @@ -124,9 +124,7 @@ def __init__(self): (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'