Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions packages/vite/src/module-runner/sourcemap/interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,19 @@ function wrapCallSite(frame: CallSite, state: State) {
const line = frame.getLineNumber() ?? 0
const column = (frame.getColumnNumber() ?? 1) - 1

const position = mapSourcePosition({
name: null,
source,
line,
column,
})
const unmapped = { name: null, source, line, column }
const position = mapSourcePosition(unmapped)
state.curPosition = position
// Most frames have no source map, and cloning one per frame dominates the cost of
// building the stack. Skip it when the clone would print the same thing anyway.
if (
position === unmapped &&
!state.nextPosition?.name &&
frame.getColumnNumber() != null &&
frame.getScriptNameOrSourceURL() === source
) {
return frame
}
frame = cloneCallSite(frame)
const originalFunctionName = frame.getFunctionName
frame.getFunctionName = function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ describe('module runner initialization', async () => {
])
})

it('prints the file name of a frame without a source map', async () => {
// when a script's sourceURL differs from its file name, the file name is what gets printed
const error = await getError(() =>
runInThisContext(
'(function inVm() { throw new Error("vm") })()\n//# sourceURL=renamed.js',
{ filename: 'original.js', displayErrors: false },
),
)
expect(error.stack!.split('\n')[1]).toBe(' at inVm (original.js:1:26)')
})

it('call site of an imported binding matches Node column', async ({
runner,
server,
Expand Down
Loading