Skip to content

Commit 9ee2bf1

Browse files
committed
refactor: inline cloneFunction
1 parent b542f00 commit 9ee2bf1

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

packages/core/src/compiler.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ export default class Compiler {
317317
const cfo = typeof cf === 'function' ? { formatter: cf } : cf;
318318

319319
this.runtime[key] = Object.assign(
320-
cloneFunction(cfo.formatter),
320+
cfo.formatter.bind({}),
321+
{ ...cfo.formatter.prototype, toString: () => String(cfo.formatter) },
321322
{ type: 'formatter' } as const,
322323
'module' in cf && cf.module && cf.id
323324
? {
@@ -331,7 +332,7 @@ export default class Compiler {
331332
);
332333
} else if (isFormatterKey(key)) {
333334
this.runtime[key] = Object.assign(
334-
cloneFunction(Formatters[key]),
335+
Formatters[key],
335336
{ type: 'formatter' } as const,
336337
{ id: key, module: FORMATTER_MODULE }
337338
);
@@ -445,11 +446,3 @@ export default class Compiler {
445446
function isFormatterKey(key: string): key is keyof typeof Formatters {
446447
return key in Formatters;
447448
}
448-
449-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
450-
function cloneFunction<T extends (...args: any[]) => any>(fn: T): T {
451-
return Object.assign(fn.bind({}), {
452-
...fn.prototype,
453-
toString: () => String(fn)
454-
});
455-
}

0 commit comments

Comments
 (0)