Skip to content

Commit

Permalink
types
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Feb 17, 2024
1 parent c1b0140 commit 38e063f
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions packages/babel-core/src/errors/rewrite-stack-trace.ts
Expand Up @@ -94,28 +94,24 @@ export function beginHiddenCallStack<A extends unknown[], R>(
if (!SUPPORTED) return fn;

return Object.defineProperty(
function (...args: A): R {
function (...args: A) {
setupPrepareStackTrace();
let isAsync = false;
try {
const ret = fn(...args);
// @ts-expect-error check if it's a promise
if (typeof ret?.then !== "function") return ret;
if (typeof (ret as any)?.then !== "function") return ret;

isAsync = true;
return (
ret
// @ts-expect-error checked above
.catch(function (err) {
err.stack;
resetPrepareStackTrace();
throw err;
})
.then(function (val: unknown) {
resetPrepareStackTrace();
return val;
})
);
return (ret as Promise<unknown>)
.catch(function (err) {
err.stack;
resetPrepareStackTrace();
throw err;
})
.then(function (val: unknown) {
resetPrepareStackTrace();
return val;
}) as R;
} catch (err) {
err.stack;
throw err;
Expand Down

0 comments on commit 38e063f

Please sign in to comment.