From 73a1bc94d1aca3fbae6efe3af9f1200af317d26e Mon Sep 17 00:00:00 2001 From: Diamond <33725716+DiamondMiner88@users.noreply.github.com> Date: Sat, 8 Oct 2022 10:23:05 -0700 Subject: fix(lazyWebpack): implement more proxy traps (#65) --- src/utils/misc.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/utils') diff --git a/src/utils/misc.tsx b/src/utils/misc.tsx index 4159906..989a54a 100644 --- a/src/utils/misc.tsx +++ b/src/utils/misc.tsx @@ -14,15 +14,20 @@ export function lazy(factory: () => T): () => T { /** * Do a lazy webpack search. Searches the module on first property access * @param filter Filter function - * @returns Proxy. Note that only get and set are implemented, all other operations will have unexpected - * results. + * @returns A proxy to the webpack module. Not all traps are implemented, may produce unexpected results. */ export function lazyWebpack(filter: FilterFn): T { const getMod = lazy(() => find(filter)); - return new Proxy({}, { + return new Proxy(() => null, { get: (_, prop) => getMod()[prop], - set: (_, prop, v) => getMod()[prop] = v + set: (_, prop, value) => getMod()[prop] = value, + has: (_, prop) => prop in getMod(), + apply: (_, $this, args) => (getMod() as Function).apply($this, args), + ownKeys: () => Reflect.ownKeys(getMod()), + construct: (_, args, newTarget) => new newTarget(...args), + deleteProperty: (_, prop) => delete getMod()[prop], + defineProperty: (_, property, attributes) => !!Object.defineProperty(getMod(), property, attributes) }) as T; } -- cgit