diff --git a/src/compiler/preprocess/index.ts b/src/compiler/preprocess/index.ts index 10771603d76e..c2a8e3b7d217 100644 --- a/src/compiler/preprocess/index.ts +++ b/src/compiler/preprocess/index.ts @@ -79,10 +79,13 @@ function processed_content_to_code(processed: Processed, location: SourceLocatio if (processed.map) { decoded_map = decode_map(processed); - // offset only segments pointing at original component source - const source_index = decoded_map.sources.indexOf(file_basename); - if (source_index !== -1) { - sourcemap_add_offset(decoded_map, location, source_index); + // decoded map may not have sources for empty maps like `{ mappings: '' }` + if (decoded_map.sources) { + // offset only segments pointing at original component source + const source_index = decoded_map.sources.indexOf(file_basename); + if (source_index !== -1) { + sourcemap_add_offset(decoded_map, location, source_index); + } } } diff --git a/test/preprocess/samples/empty-sourcemap/_config.js b/test/preprocess/samples/empty-sourcemap/_config.js new file mode 100644 index 000000000000..941661ce01e2 --- /dev/null +++ b/test/preprocess/samples/empty-sourcemap/_config.js @@ -0,0 +1,7 @@ +export default { + preprocess: { + style: ({ content }) => { + return { code: content, map: { mappings: '' } }; + } + } +}; diff --git a/test/preprocess/samples/empty-sourcemap/input.svelte b/test/preprocess/samples/empty-sourcemap/input.svelte new file mode 100644 index 000000000000..d2380c00cb57 --- /dev/null +++ b/test/preprocess/samples/empty-sourcemap/input.svelte @@ -0,0 +1,7 @@ +