From f3a8ecbfbd0195cc4acf3b33a854c4cbe5a7f909 Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Mon, 9 Jun 2025 23:28:25 +0700 Subject: [PATCH] fix(lib/patcher): do truthiness checks instead of undefined checks --- lib/patcher/src/_internal.ts | 2 +- lib/patcher/src/hooks/after.ts | 4 ++-- lib/patcher/src/hooks/before.ts | 4 ++-- lib/patcher/src/hooks/instead.ts | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/patcher/src/_internal.ts b/lib/patcher/src/_internal.ts index 5692448..f9fcd76 100644 --- a/lib/patcher/src/_internal.ts +++ b/lib/patcher/src/_internal.ts @@ -46,7 +46,7 @@ export interface InsteadHookNode /** @throws {TypeError} When `hookNode` is defined, its hook and that of all other hook nodes in its list must also be defined. */ function applyHooks(hookNode: HookNode<(arg: T) => T> | undefined, arg: T) { - while (hookNode !== undefined) { + while (hookNode) { // Save a reference to the next hook node in case the current hook calls unpatch. const { next, hook } = hookNode // Indirectly call the hook so as to not give it access to its hook node. diff --git a/lib/patcher/src/hooks/after.ts b/lib/patcher/src/hooks/after.ts index b935535..ce9b7e9 100644 --- a/lib/patcher/src/hooks/after.ts +++ b/lib/patcher/src/hooks/after.ts @@ -49,7 +49,7 @@ export function after( let state = patchedFunctionProxyStates.get(target) let hookNode: HookNode - if (state !== undefined && state.parent === parent && state.key === key) { + if (state?.parent === parent && state.key === key) { const head = state.after hookNode = { hook, @@ -57,7 +57,7 @@ export function after( prev: undefined, unpatched: false, } - if (head !== undefined) head.prev = hookNode + if (head) head.prev = hookNode state.after = hookNode } else { hookNode = { diff --git a/lib/patcher/src/hooks/before.ts b/lib/patcher/src/hooks/before.ts index d144ea2..944de9e 100644 --- a/lib/patcher/src/hooks/before.ts +++ b/lib/patcher/src/hooks/before.ts @@ -49,7 +49,7 @@ export function before( let state = patchedFunctionProxyStates.get(target) let hookNode: HookNode - if (state !== undefined && state.parent === parent && state.key === key) { + if (state?.parent === parent && state.key === key) { const head = state.before hookNode = { hook, @@ -57,7 +57,7 @@ export function before( prev: undefined, unpatched: false, } - if (head !== undefined) head.prev = hookNode + if (head) head.prev = hookNode state.before = hookNode } else { hookNode = { diff --git a/lib/patcher/src/hooks/instead.ts b/lib/patcher/src/hooks/instead.ts index 417be7f..1e2ec11 100644 --- a/lib/patcher/src/hooks/instead.ts +++ b/lib/patcher/src/hooks/instead.ts @@ -96,10 +96,10 @@ export function instead( hookNode.hook = hook hookNode.prev = undefined - if (state !== undefined && state.parent === parent && state.key === key) { + if (state?.parent === parent && state.key === key) { const head = state.instead hookNode.next = head - if (head !== undefined) head.prev = hookNode + if (head) head.prev = hookNode state.instead = hookNode } else { hookNode.next = undefined