mirror of
https://github.com/swc-project/swc.git
synced 2024-11-27 04:47:03 +03:00
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:
parent
f681924023
commit
02729f24d8
@ -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())?;
|
||||
|
40
crates/swc_ecma_minifier/tests/fixture/next/46887-2/input.js
Normal file
40
crates/swc_ecma_minifier/tests/fixture/next/46887-2/input.js
Normal 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)
|
||||
}))
|
||||
})
|
@ -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);
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user