Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] handle preprocess with empty sourcemaps #6757

Merged
merged 1 commit into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>