From 7d1b74eec0a4f5bf0586c51ebcb5e857e98e9b86 Mon Sep 17 00:00:00 2001 From: bluwy Date: Thu, 23 Sep 2021 00:29:25 +0800 Subject: [PATCH] [fix] handle preprocess with empty sourcemaps --- 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 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 @@ +
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 000000000000..d2380c00cb57 --- /dev/null +++ b/test/preprocess/samples/empty-sourcemap/output.svelte @@ -0,0 +1,7 @@ +
bar
+ + \ No newline at end of file