Skip to content

Commit

Permalink
[fix] handle preprocess with empty sourcemaps (#6757)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Sep 22, 2021
1 parent dad0284 commit b845307
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/compiler/preprocess/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions test/preprocess/samples/empty-sourcemap/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
preprocess: {
style: ({ content }) => {
return { code: content, map: { mappings: '' } };
}
}
};
7 changes: 7 additions & 0 deletions test/preprocess/samples/empty-sourcemap/input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="foo">bar</div>

<style>
.foo {
color: red;
}
</style>
7 changes: 7 additions & 0 deletions test/preprocess/samples/empty-sourcemap/output.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="foo">bar</div>

<style>
.foo {
color: red;
}
</style>

0 comments on commit b845307

Please sign in to comment.