From 0d63bc405c1cb753858d8948bd7fbce34c402f0b Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Mon, 15 Mar 2021 09:11:11 +0100 Subject: [PATCH 1/3] Add sources to combined map if needed When source maps are combined and the leading map is empty, sources is not set. Add the filename to the empty array in this case. Related https://github.com/sveltejs/kit/issues/424 --- src/compiler/utils/mapped_code.ts | 5 +++++ test/sourcemaps/samples/decoded-sourcemap/_config.js | 2 +- test/sourcemaps/samples/external/_config.js | 2 +- test/sourcemaps/samples/sourcemap-basename/_config.js | 2 +- test/sourcemaps/samples/sourcemap-offsets/_config.js | 2 +- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/compiler/utils/mapped_code.ts b/src/compiler/utils/mapped_code.ts index d0cab9f49fbf..fd2124fa451e 100644 --- a/src/compiler/utils/mapped_code.ts +++ b/src/compiler/utils/mapped_code.ts @@ -251,6 +251,11 @@ export function combine_sourcemaps( if (!map.file) delete map.file; // skip optional field `file` + // When source maps are combined and the leading map is empty, sources is not set. + // Add the filename to the empty array in this case. + // Possibly a bug in the remapping library https://github.com/ampproject/remapping/issues/116 + if (!map.sources.length) map.sources = [filename]; + return map; } diff --git a/test/sourcemaps/samples/decoded-sourcemap/_config.js b/test/sourcemaps/samples/decoded-sourcemap/_config.js index dd4eee9461e0..a0b2c82692c6 100644 --- a/test/sourcemaps/samples/decoded-sourcemap/_config.js +++ b/test/sourcemaps/samples/decoded-sourcemap/_config.js @@ -3,7 +3,7 @@ import { magic_string_preprocessor_result, magic_string_replace_all } from '../. export default { - js_map_sources: [], // test component has no scripts + js_map_sources: ['input.svelte'], preprocess: { markup: ({ content, filename }) => { diff --git a/test/sourcemaps/samples/external/_config.js b/test/sourcemaps/samples/external/_config.js index 400def20ac63..07a0903482cf 100644 --- a/test/sourcemaps/samples/external/_config.js +++ b/test/sourcemaps/samples/external/_config.js @@ -10,7 +10,7 @@ export const STYLES = '.awesome { color: orange; }\n'; export default { css_map_sources: ['common.scss', 'styles.scss'], - js_map_sources: [], + js_map_sources: ['input.svelte'], preprocess: [ { style: () => { diff --git a/test/sourcemaps/samples/sourcemap-basename/_config.js b/test/sourcemaps/samples/sourcemap-basename/_config.js index 33146af7e7c6..7692b7a6d92a 100644 --- a/test/sourcemaps/samples/sourcemap-basename/_config.js +++ b/test/sourcemaps/samples/sourcemap-basename/_config.js @@ -15,7 +15,7 @@ span { export default { css_map_sources: [external_relative_filename], - js_map_sources: [], + js_map_sources: ['input.svelte'], preprocess: [ { style: ({ content, filename }) => { diff --git a/test/sourcemaps/samples/sourcemap-offsets/_config.js b/test/sourcemaps/samples/sourcemap-offsets/_config.js index 392fb68a434f..bbc24c3225e3 100644 --- a/test/sourcemaps/samples/sourcemap-offsets/_config.js +++ b/test/sourcemaps/samples/sourcemap-offsets/_config.js @@ -3,7 +3,7 @@ import { magic_string_bundle } from '../../helpers'; export const EXTERNAL = 'span { --external-var: 1px; }'; export default { - js_map_sources: [], + js_map_sources: ['input.svelte'], css_map_sources: ['input.svelte', 'external.css'], preprocess: [ { From fd74dcc03f2ea3f4dab5b6cda82f239375594b02 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Mon, 15 Mar 2021 09:23:12 +0100 Subject: [PATCH 2/3] fix test --- test/sourcemaps/samples/preprocessed-no-map/_config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sourcemaps/samples/preprocessed-no-map/_config.js b/test/sourcemaps/samples/preprocessed-no-map/_config.js index 9888b56ddf8f..78b0ee626f2a 100644 --- a/test/sourcemaps/samples/preprocessed-no-map/_config.js +++ b/test/sourcemaps/samples/preprocessed-no-map/_config.js @@ -1,5 +1,5 @@ export default { - css_map_sources: [], + css_map_sources: ['input.svelte'], preprocess: [ { style: ({ content }) => { From efdb82bfb9a41a10cd5707d767838ad763526fe7 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Fri, 23 Jul 2021 09:37:55 -0700 Subject: [PATCH 3/3] Update src/compiler/utils/mapped_code.ts --- src/compiler/utils/mapped_code.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/utils/mapped_code.ts b/src/compiler/utils/mapped_code.ts index fd2124fa451e..578c9a959426 100644 --- a/src/compiler/utils/mapped_code.ts +++ b/src/compiler/utils/mapped_code.ts @@ -253,7 +253,7 @@ export function combine_sourcemaps( // When source maps are combined and the leading map is empty, sources is not set. // Add the filename to the empty array in this case. - // Possibly a bug in the remapping library https://github.com/ampproject/remapping/issues/116 + // Further improvements to remapping may help address this as well https://github.com/ampproject/remapping/issues/116 if (!map.sources.length) map.sources = [filename]; return map;