(frame: CallSite, state: State)
| 345 | } |
| 346 | |
| 347 | function wrapCallSite(frame: CallSite, state: State) { |
| 348 | // provides interface backward compatibility |
| 349 | if (state === undefined) state = { nextPosition: null, curPosition: null } |
| 350 | |
| 351 | if (frame.isNative()) { |
| 352 | state.curPosition = null |
| 353 | return frame |
| 354 | } |
| 355 | |
| 356 | // Most call sites will return the source file from getFileName(), but code |
| 357 | // passed to eval() ending in "//# sourceURL=..." will return the source file |
| 358 | // from getScriptNameOrSourceURL() instead |
| 359 | const source = frame.getFileName() || frame.getScriptNameOrSourceURL() |
| 360 | if (source) { |
| 361 | const line = frame.getLineNumber() ?? 0 |
| 362 | const column = (frame.getColumnNumber() ?? 1) - 1 |
| 363 | |
| 364 | const position = mapSourcePosition({ |
| 365 | name: null, |
| 366 | source, |
| 367 | line, |
| 368 | column, |
| 369 | }) |
| 370 | state.curPosition = position |
| 371 | frame = cloneCallSite(frame) |
| 372 | const originalFunctionName = frame.getFunctionName |
| 373 | frame.getFunctionName = function () { |
| 374 | const name = (() => { |
| 375 | if (state.nextPosition == null) return originalFunctionName() |
| 376 | |
| 377 | return state.nextPosition.name || originalFunctionName() |
| 378 | })() |
| 379 | return name === 'eval' && '_vite' in position ? null : name |
| 380 | } |
| 381 | frame.getFileName = function () { |
| 382 | return position.source ?? null |
| 383 | } |
| 384 | frame.getLineNumber = function () { |
| 385 | return position.line |
| 386 | } |
| 387 | frame.getColumnNumber = function () { |
| 388 | return position.column + 1 |
| 389 | } |
| 390 | frame.getScriptNameOrSourceURL = function () { |
| 391 | return position.source! |
| 392 | } |
| 393 | return frame |
| 394 | } |
| 395 | |
| 396 | // Code called using eval() needs special handling |
| 397 | let origin = frame.isEval() && frame.getEvalOrigin() |
| 398 | if (origin) { |
| 399 | origin = mapEvalOrigin(origin) |
| 400 | frame = cloneCallSite(frame) |
| 401 | frame.getEvalOrigin = function () { |
| 402 | return origin || undefined |
| 403 | } |
| 404 | return frame |
no test coverage detected