Skip to content

Commit b80f6c5

Browse files
committed
fixup! fixup! core: add wrapMethod/unwrapMethod util
1 parent 71a86b7 commit b80f6c5

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

packages/core/src/utils/object.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,12 @@ export function markFunctionWrapped(wrapped: WrappedFunction, original: WrappedF
9090
* in a `for(in)` loop. Neither are an acceptable performance impact for
9191
* the rare case where we might patch a non-enumerable method.
9292
*/
93-
export function wrapMethod<O extends {}, T extends string & keyof O>(obj: O, field: T, wrapped: WrappedFunction, enumerable: boolean = true): void {
93+
export function wrapMethod<O extends {}, T extends string & keyof O>(
94+
obj: O,
95+
field: T,
96+
wrapped: WrappedFunction,
97+
enumerable: boolean = true,
98+
): void {
9499
const original = obj[field];
95100
if (typeof original !== 'function') {
96101
throw new Error(`Cannot wrap method: ${field} is not a function`);
@@ -104,7 +109,7 @@ export function wrapMethod<O extends {}, T extends string & keyof O>(obj: O, fie
104109
configurable: true,
105110
enumerable,
106111
value: wrapped,
107-
})
112+
});
108113
}
109114

110115
/**

packages/core/test/lib/utils/object.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,11 @@ describe('wrapMethod', () => {
485485
it('throws if misused', () => {
486486
const wrapped = () => {};
487487
const original = () => {};
488-
const obj = { get m() { return original } };
488+
const obj = {
489+
get m() {
490+
return original;
491+
},
492+
};
489493
wrapMethod(obj, 'm', wrapped);
490494
expect(() => {
491495
//@ts-expect-error verify type checking prevents this mistake

0 commit comments

Comments
 (0)