Skip to content

Commit 7e2167d

Browse files
committed
fix: handle sourcemap with empty script code
ref vitejs/vite-plugin-vue@7f73970
1 parent 0500fba commit 7e2167d

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/core/main.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,23 @@ export async function transformMain(
193193

194194
let resolvedMap: RawSourceMap | undefined = undefined
195195
if (options.sourceMap) {
196-
if (scriptMap && templateMap) {
197-
// if the template is inlined into the main module (indicated by the presence
198-
// of templateMap), we need to concatenate the two source maps.
199-
196+
// the mappings of the source map for the inlined template should be moved
197+
// because the position does not include the script tag part.
198+
// we also concatenate the two source maps while doing that.
199+
if (templateMap) {
200+
const from = scriptMap ?? {
201+
file: filename,
202+
sourceRoot: '',
203+
version: 3,
204+
sources: [],
205+
sourcesContent: [],
206+
names: [],
207+
mappings: '',
208+
}
200209
const gen = fromMap(
201210
// version property of result.map is declared as string
202211
// but actually it is `3`
203-
scriptMap as Omit<RawSourceMap, 'version'> as TraceEncodedSourceMap,
212+
from as Omit<RawSourceMap, 'version'> as TraceEncodedSourceMap,
204213
)
205214
const tracer = new TraceMap(
206215
// same above
@@ -228,8 +237,7 @@ export async function transformMain(
228237
// of the main module compile result, which has outdated sourcesContent.
229238
resolvedMap.sourcesContent = templateMap.sourcesContent
230239
} else {
231-
// if one of `scriptMap` and `templateMap` is empty, use the other one
232-
resolvedMap = scriptMap ?? templateMap
240+
resolvedMap = scriptMap
233241
}
234242
}
235243

0 commit comments

Comments
 (0)