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

Function calculateOffsetOnce

packages/vite/src/node/ssr/ssrStacktrace.ts:7–23  ·  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 // `"use strict";` mirrors the directive prepended on its own line by
14 // `ESModulesEvaluator`
15 new Function('"use strict";\nthrow new Error(1)')()
16 } catch (e) {
17 // in Node 12, stack traces account for the function wrapper.
18 // in Node 13 and later, the function wrapper adds two lines,
19 // which must be subtracted to generate a valid mapping
20 const match = /:(\d+):\d+\)$/.exec(e.stack.split('\n')[1])
21 offset = match ? +match[1] - 1 : 0
22 }
23}
24
25export function ssrRewriteStacktrace(
26 stack: string,

Callers 1

ssrRewriteStacktraceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected