From d681785b428b7958e7652dc3a7c709ad85b298f9 Mon Sep 17 00:00:00 2001 From: Luke Page Date: Fri, 29 Dec 2023 13:25:23 +0100 Subject: [PATCH] fix(es/minifier): Add WeakRef as a safe global reference (#8458) **Description:** I was trying to remove references to Weak Ref from minified code and despite the expression not being used, it was still included. E.g. ``` var x = WeakRef; ``` with ``` { "minify": true, "jsc": { "minify": { "compress": { "pure_getters": true, "unused": true }, "mangle": true } } } ``` outputs ``` WeakRef; ``` but when I use something on this list e.g. parseFloat, it gets cleaned up and outputs empty string. btw - I tried different options for pure_getters that I assumed would allow me to say WeakRef as a getter was pure, but it had no effect. WeakRef getter is as safe to remove as the other items on this list and has no effect in accessing it. --- crates/swc_ecma_usage_analyzer/src/util.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/swc_ecma_usage_analyzer/src/util.rs b/crates/swc_ecma_usage_analyzer/src/util.rs index 1f8e0758b2c..fc02f1041ad 100644 --- a/crates/swc_ecma_usage_analyzer/src/util.rs +++ b/crates/swc_ecma_usage_analyzer/src/util.rs @@ -39,6 +39,7 @@ pub fn is_global_var_with_pure_property_access(s: &str) -> bool { | "NaN" | "Symbol" | "Promise" + | "WeakRef" ) }