fix(es/minifier): Abort property hoisting on eval (#8957)

**Description:**

 - Repro: https://github.com/kdy1/repro-next-46887-2


**Related issue:**

- https://github.com/vercel/next.js/issues/46887#issuecomment-2113264586
This commit is contained in:
Donny/강동윤 2024-05-16 11:35:45 +09:00 committed by GitHub
parent f681924023
commit 02729f24d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 79 additions and 0 deletions

View File

@ -44,6 +44,10 @@ impl Optimizer<'_> {
return None;
}
if !self.may_add_ident() {
return None;
}
// If a variable is initialized multiple time, we currently don't do anything
// smart.
let usage = self.data.vars.get(&name.to_id())?;

View File

@ -0,0 +1,40 @@
var Za = {
set: Qi,
get: Qg,
enforce: function (e1) {
return Ri(e1) ? Qg(e1) : Qi(e1, {});
},
getterFor: function (e1) {
return function (t) {
var n;
if (!ha(t) || (n = Qg(t)).type !== e1) throw TypeError("Incompatible receiver, " + e1 + " required");
return n;
};
}
}
export function exposed() {
try {
var a = eval("quire".replace(/^/, "re"))(c);
if (a && (a.length || Object.keys(a).length)) return a;
} catch (e1) { }
return null;
}
export default (function (e) {
var t = Za.get,
n = Za.enforce,
r = String(String).split("String");
(e.exports = function (e, t, i, o) {
var a = !!o && !!o.unsafe,
s = !!o && !!o.enumerable;
if (o = !!o && !!o.noTargetGet, "function" == typeof i) {
"string" != typeof t || Q(i, "name") || Na(i, "name", t);
var u = n(i);
u.source || (u.source = r.join("string" == typeof t ? t : ""))
}
e === y ? s ? e[t] = i : Oi(t, i) : (a ? !o && e[t] && (s = !0) : delete e[t], s ? e[t] = i : Na(e, t, i))
})(Function.prototype, "toString", (function () {
return "function" == typeof this && t(this).source || Pi(this)
}))
})

View File

@ -0,0 +1,35 @@
var Za = {
set: Qi,
get: Qg,
enforce: function(e1) {
return Ri(e1) ? Qg(e1) : Qi(e1, {});
},
getterFor: function(e1) {
return function(t) {
var n;
if (!ha(t) || (n = Qg(t)).type !== e1) throw TypeError("Incompatible receiver, " + e1 + " required");
return n;
};
}
};
export function exposed() {
try {
var a = eval("quire".replace(/^/, "re"))(c);
if (a && (a.length || Object.keys(a).length)) return a;
} catch (e1) {}
return null;
}
export default function(e) {
var t = Za.get, n = Za.enforce, r = String(String).split("String");
(e.exports = function(e, t, i, o) {
var a = !!o && !!o.unsafe, s = !!o && !!o.enumerable;
if (o = !!o && !!o.noTargetGet, "function" == typeof i) {
"string" != typeof t || Q(i, "name") || Na(i, "name", t);
var u = n(i);
u.source || (u.source = r.join("string" == typeof t ? t : ""));
}
e === y ? s ? e[t] = i : Oi(t, i) : (a ? !o && e[t] && (s = !0) : delete e[t], s ? e[t] = i : Na(e, t, i));
})(Function.prototype, "toString", function() {
return "function" == typeof this && t(this).source || Pi(this);
});
}