Preserve ProxyDummy function name after minification

This commit is contained in:
Nuckyz 2024-05-23 23:14:00 -03:00
parent c01a8c2f78
commit 74f36a093b
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
2 changed files with 18 additions and 2 deletions

View file

@ -77,7 +77,13 @@ export function proxyLazy<T = AnyObject>(factory: () => T, attempts = 5, isChild
let isSameTick = true;
if (!isChild) setTimeout(() => isSameTick = false, 0);
const proxyDummy = Object.assign(function ProxyDummy() { }, {
// Define the function in an object to preserve the name after minification
const dummyObj = {
ProxyDummy() { }
} as { ProxyDummy: any; };
const proxyDummy = dummyObj.ProxyDummy;
Object.assign(proxyDummy, {
[proxyLazyGet]() {
if (!proxyDummy[proxyLazyCache]) {
// @ts-ignore
@ -99,6 +105,8 @@ export function proxyLazy<T = AnyObject>(factory: () => T, attempts = 5, isChild
[proxyLazyCache]: void 0 as T | undefined
});
delete dummyObj.ProxyDummy;
const proxy = new Proxy(proxyDummy, {
...handler,
get(target, p) {

View file

@ -58,7 +58,13 @@ export function proxyInner<T = AnyObject>(
let isSameTick = true;
if (!isChild) setTimeout(() => isSameTick = false, 0);
const proxyDummy = Object.assign(function ProxyDummy() { }, {
// Define the function in an object to preserve the name after minification
const dummyObj = {
ProxyDummy() { }
} as { ProxyDummy: any; };
const proxyDummy = dummyObj.ProxyDummy;
Object.assign(proxyDummy, {
[proxyInnerGet]: function () {
if (proxyDummy[proxyInnerValue] == null) {
throw new Error(errMsg);
@ -69,6 +75,8 @@ export function proxyInner<T = AnyObject>(
[proxyInnerValue]: void 0 as T | undefined
});
delete dummyObj.ProxyDummy;
const proxy = new Proxy(proxyDummy, {
...handler,
get(target, p) {