Skip to content

Commit

Permalink
Avoid cast
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Aug 25, 2022
1 parent ce9f2d2 commit df5ef02
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions packages/babel-core/src/errors/rewrite-stack-trace.ts
Expand Up @@ -94,26 +94,30 @@ export function expectedError(error: Error) {
return error;
}

export function beginHiddenCallStack<Fn extends Function>(fn: Fn): Fn {
export function beginHiddenCallStack<T, A extends unknown[], R>(
fn: (this: T, ...args: A) => R,
) {
if (!SUPPORTED) return fn;

return Object.defineProperty(
function (this: any) {
function (this: T, ...args: A) {
setupPrepareStackTrace();
return fn.apply(this, arguments);
} as any as Fn,
return fn.apply(this, args);
},
"name",
{ value: STOP_HIDNG },
);
}

export function endHiddenCallStack<Fn extends Function>(fn: Fn): Fn {
export function endHiddenCallStack<T, A extends unknown[], R>(
fn: (this: T, ...args: A) => R,
) {
if (!SUPPORTED) return fn;

return Object.defineProperty(
function (this: any) {
return fn.apply(this, arguments);
} as any as Fn,
function (this: T, ...args: A) {
return fn.apply(this, args);
},
"name",
{ value: START_HIDNG },
);
Expand Down

0 comments on commit df5ef02

Please sign in to comment.