tree-shaker
tree-shaker copied to clipboard
Abnormal phenomenon
Input:
function Main() {
const p = {};
p.__proto__ = p.__proto__ || {};
p.__proto__.a = 124;
const m = Math.random(10);
return m;
}
Main();
console.log(window.a);
Expected Output:
Include all statements.
Actual Output:
It seems that objects created by literals do not have a prototype chain, and references to global objects are automatically retained.
function Main() {
const __unused_4577 = Math.random(10);
return;
}
Main();
console.log(window.a);
There are two separate problems:
Math.random()not considered as pure yet. This will be solved in the future.- Prototype pollution. IMO, the expected behavior should be:
function effect1(key, value) {
({})[key]?.x = value
}
({}).__proto__.x // Preserved
effect("__proto__") // Preserved
effect("" + unknown) // Although `unknown` is possible to be "__proto__", still remove it