MCPcopy
hub / github.com/vitejs/vite / calculateOffsetOnce

Function calculateOffsetOnce

packages/vite/src/node/ssr/ssrStacktrace.ts:7–21  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5let offset: number
6
7function calculateOffsetOnce() {
8 if (offset !== undefined) {
9 return
10 }
11
12 try {
13 new Function('throw new Error(1)')()
14 } catch (e) {
15 // in Node 12, stack traces account for the function wrapper.
16 // in Node 13 and later, the function wrapper adds two lines,
17 // which must be subtracted to generate a valid mapping
18 const match = /:(\d+):\d+\)$/.exec(e.stack.split('\n')[1])
19 offset = match ? +match[1] - 1 : 0
20 }
21}
22
23export function ssrRewriteStacktrace(
24 stack: string,

Callers 1

ssrRewriteStacktraceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected