From 74f36a093b2605f017e0b7db2d38a7347a4c8767 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Thu, 23 May 2024 23:14:00 -0300 Subject: [PATCH] Preserve ProxyDummy function name after minification --- src/utils/lazy.ts | 10 +++++++++- src/utils/proxyInner.ts | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/utils/lazy.ts b/src/utils/lazy.ts index 439ec1bef..c3cb0f794 100644 --- a/src/utils/lazy.ts +++ b/src/utils/lazy.ts @@ -77,7 +77,13 @@ export function proxyLazy(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(factory: () => T, attempts = 5, isChild [proxyLazyCache]: void 0 as T | undefined }); + delete dummyObj.ProxyDummy; + const proxy = new Proxy(proxyDummy, { ...handler, get(target, p) { diff --git a/src/utils/proxyInner.ts b/src/utils/proxyInner.ts index 51d62bdc4..4f6c67991 100644 --- a/src/utils/proxyInner.ts +++ b/src/utils/proxyInner.ts @@ -58,7 +58,13 @@ export function proxyInner( 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( [proxyInnerValue]: void 0 as T | undefined }); + delete dummyObj.ProxyDummy; + const proxy = new Proxy(proxyDummy, { ...handler, get(target, p) {