fix(lib/patcher): do truthiness checks instead of undefined checks

This commit is contained in:
PalmDevs 2025-06-09 23:28:25 +07:00
parent fc8067d599
commit f3a8ecbfbd
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA
4 changed files with 7 additions and 7 deletions

View file

@ -46,7 +46,7 @@ export interface InsteadHookNode<T extends UnknownFunction = UnknownFunction>
/** @throws {TypeError} When `hookNode` is defined, its hook and that of all other hook nodes in its list must also be defined. */
function applyHooks<T>(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.

View file

@ -49,7 +49,7 @@ export function after<Key extends PropertyKey, Value extends UnknownFunction>(
let state = patchedFunctionProxyStates.get(target)
let hookNode: HookNode<typeof hook>
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<Key extends PropertyKey, Value extends UnknownFunction>(
prev: undefined,
unpatched: false,
}
if (head !== undefined) head.prev = hookNode
if (head) head.prev = hookNode
state.after = hookNode
} else {
hookNode = {

View file

@ -49,7 +49,7 @@ export function before<Key extends PropertyKey, Value extends UnknownFunction>(
let state = patchedFunctionProxyStates.get(target)
let hookNode: HookNode<typeof hook>
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<Key extends PropertyKey, Value extends UnknownFunction>(
prev: undefined,
unpatched: false,
}
if (head !== undefined) head.prev = hookNode
if (head) head.prev = hookNode
state.before = hookNode
} else {
hookNode = {

View file

@ -96,10 +96,10 @@ export function instead<Key extends PropertyKey, Value extends UnknownFunction>(
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