fix(lib/patcher): do truthiness checks instead of undefined checks
This commit is contained in:
parent
fc8067d599
commit
f3a8ecbfbd
4 changed files with 7 additions and 7 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue