Skip to content

Commit 891d97c

Browse files
committed
fix(vite-node): ensure source maps for first line
1 parent ea906c0 commit 891d97c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

packages/vite-node/src/source-map.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ export function withInlineSourcemap(result: TransformResult, options: {
4848
while (OTHER_SOURCE_MAP_REGEXP.test(code))
4949
code = code.replace(OTHER_SOURCE_MAP_REGEXP, '')
5050

51+
// If the first line is not present on source maps, add simple 1:1 mapping ([0,0,0,0], [1,0,0,0])
52+
// so that debuggers can be set to break on first line
53+
if (map.mappings.startsWith(';'))
54+
map.mappings = `AAAA,CAAA${map.mappings}`
55+
5156
const sourceMap = Buffer.from(JSON.stringify(map), 'utf-8').toString('base64')
5257
result.code = `${code.trimEnd()}\n\n${VITE_NODE_SOURCEMAPPING_SOURCE}\n//# ${VITE_NODE_SOURCEMAPPING_URL};base64,${sourceMap}\n`
5358

0 commit comments

Comments
 (0)