Description
When property_write_side_effects is false, the minifier removes unused property writes like obj.a = 1 if all references to obj are member write targets. However, if __proto__ is assigned after the property write (e.g., via a hoisted function), the setter installed by __proto__ isn't detected, and the property write is incorrectly removed.
Reproduction
const obj = {}
f()
obj.a = 1
function f() {
obj.__proto__ = { set a(v) { console.log("hello") } }
}
Currently obj.a = 1 may be removed, but at runtime f() installs a setter on obj via __proto__, so obj.a = 1 triggers console.log("hello") and must be preserved.
Root Cause
The current implementation tracks __proto__ writes as it encounters them during traversal. Since AST traversal is top-down, a __proto__ write inside a hoisted function that appears later in the source isn't recorded when the earlier obj.a = 1 is visited.
Possible Fix
Pre-scan all member write references to detect __proto__ writes before the removal pass, so that the tracking is complete regardless of source order.
Related
Description
When
property_write_side_effectsisfalse, the minifier removes unused property writes likeobj.a = 1if all references toobjare member write targets. However, if__proto__is assigned after the property write (e.g., via a hoisted function), the setter installed by__proto__isn't detected, and the property write is incorrectly removed.Reproduction
Currently
obj.a = 1may be removed, but at runtimef()installs a setter onobjvia__proto__, soobj.a = 1triggersconsole.log("hello")and must be preserved.Root Cause
The current implementation tracks
__proto__writes as it encounters them during traversal. Since AST traversal is top-down, a__proto__write inside a hoisted function that appears later in the source isn't recorded when the earlierobj.a = 1is visited.Possible Fix
Pre-scan all member write references to detect
__proto__writes before the removal pass, so that the tracking is complete regardless of source order.Related
property_write_side_effectsoption to drop unused property assignments #20773 — originalproperty_write_side_effectsimplementation