Skip to content

Commit

Permalink
refactor: use WeakSet
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Dec 8, 2022
1 parent b2e089f commit 575d142
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions packages/vite/src/node/ssr/ssrStacktrace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,15 @@ export function rebindErrorStacktrace(e: Error, stacktrace: string): void {
}
}

const rewroteStacktraceSymbol = Symbol('Vite.rewroteStacktrace')
const rewroteStacktraces = new WeakSet()

export function ssrFixStacktrace(
e: Error & { [rewroteStacktraceSymbol]?: true },
moduleGraph: ModuleGraph
): void {
export function ssrFixStacktrace(e: Error, moduleGraph: ModuleGraph): void {
if (!e.stack) return
// stacktrace shouldn't be rewritten more than once
if (e[rewroteStacktraceSymbol]) return
if (rewroteStacktraces.has(e)) return

const stacktrace = ssrRewriteStacktrace(e.stack, moduleGraph)
rebindErrorStacktrace(e, stacktrace)

e[rewroteStacktraceSymbol] = true
rewroteStacktraces.add(e)
}

0 comments on commit 575d142

Please sign in to comment.