From b8453076989aac5175f7322f468338b60293eaeb Mon Sep 17 00:00:00 2001 From: Bjorn Lu <34116392+bluwy@users.noreply.github.com> Date: Thu, 23 Sep 2021 01:21:40 +0800 Subject: [PATCH] [fix] handle preprocess with empty sourcemaps (#6757) --- src/compiler/preprocess/index.ts | 11 +++++++---- test/preprocess/samples/empty-sourcemap/_config.js | 7 +++++++ test/preprocess/samples/empty-sourcemap/input.svelte | 7 +++++++ test/preprocess/samples/empty-sourcemap/output.svelte | 7 +++++++ 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 test/preprocess/samples/empty-sourcemap/_config.js create mode 100644 test/preprocess/samples/empty-sourcemap/input.svelte create mode 100644 test/preprocess/samples/empty-sourcemap/output.svelte diff --git a/src/compiler/preprocess/index.ts b/src/compiler/preprocess/index.ts index 10771603d7..c2a8e3b7d2 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 0000000000..941661ce01 --- /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 0000000000..d2380c00cb --- /dev/null +++ b/test/preprocess/samples/empty-sourcemap/input.svelte @@ -0,0 +1,7 @@ +
bar
+ + \ No newline at end of file diff --git a/test/preprocess/samples/empty-sourcemap/output.svelte b/test/preprocess/samples/empty-sourcemap/output.svelte new file mode 100644 index 0000000000..d2380c00cb --- /dev/null +++ b/test/preprocess/samples/empty-sourcemap/output.svelte @@ -0,0 +1,7 @@ +
bar
+ + \ No newline at end of file