-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Fix some issues with preprocess source maps #5754
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
100eba3
Fix some issues with preprocess source maps
dmitrage 5441835
Add more tests
dmitrage 7ac102a
Remove source guessing workaround
dmitrage d540800
Update test todo note
dmitrage c842d16
Cleanup tests
dmitrage 1c241dd
Add test for sourcemap offset
dmitrage 3830216
Tests and chores
dmitrage 20499ee
Add test for basename
dmitrage 35d7628
Fix and cover case when preprocessor returns no source map
dmitrage e8a2c28
Treat returned content without map as not changed
dmitrage b5ffaf3
Rename test for consistency
dmitrage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { magic_string_bundle } from '../../helpers'; | ||
|
||
export const COMMON = ':global(html) { height: 100%; }\n'; | ||
|
||
// TODO: removing '\n' breaks test | ||
// - _actual.svelte.map looks correct | ||
// - _actual.css.map adds reference to </style> on input.svelte | ||
// - Most probably caused by bug in current magic-string version (fixed in 0.25.7) | ||
export const STYLES = '.awesome { color: orange; }\n'; | ||
|
||
export default { | ||
css_map_sources: ['common.scss', 'styles.scss'], | ||
js_map_sources: [], | ||
preprocess: [ | ||
{ | ||
style: () => { | ||
return magic_string_bundle([ | ||
{ filename: 'common.scss', code: COMMON }, | ||
{ filename: 'styles.scss', code: STYLES } | ||
]); | ||
} | ||
} | ||
] | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<style lang="scss" src="./styles.scss"></style> | ||
|
||
<div class="awesome">Divs ftw!</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { assert_mapped } from '../../helpers'; | ||
import { COMMON, STYLES } from './_config'; | ||
|
||
export function test({ input, preprocessed }) { | ||
// Transformed script, main file | ||
assert_mapped({ | ||
filename: 'input.svelte', | ||
code: 'Divs ftw!', | ||
input: input.locate, | ||
preprocessed | ||
}); | ||
|
||
// External files | ||
assert_mapped({ | ||
filename: 'common.scss', | ||
code: 'height: 100%;', | ||
input: COMMON, | ||
preprocessed | ||
}); | ||
assert_mapped({ | ||
filename: 'styles.scss', | ||
code: 'color: orange;', | ||
input: STYLES, | ||
preprocessed | ||
}); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import MagicString from 'magic-string'; | ||
import { magic_string_preprocessor_result } from '../../helpers'; | ||
|
||
export default { | ||
js_map_sources: [ | ||
'input.svelte' | ||
], | ||
preprocess: [ | ||
{ | ||
script: ({ content, filename }) => { | ||
const s = new MagicString(content); | ||
s.prepend('// This script code is approved\n'); | ||
return magic_string_preprocessor_result(filename, s); | ||
}, | ||
style: ({ content, filename }) => { | ||
const s = new MagicString(content); | ||
s.prepend('/* This style code is approved */\n'); | ||
return magic_string_preprocessor_result(filename, s); | ||
} | ||
} | ||
] | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<script> | ||
import { onMount } from 'svelte'; | ||
|
||
let count = 0; | ||
|
||
onMount(() => { | ||
const id = setInterval(() => count++, 1000); | ||
return () => clearInterval(id); | ||
}); | ||
</script> | ||
|
||
<style> | ||
h1 { | ||
color: orange; | ||
} | ||
</style> | ||
|
||
<h1>Hello world!</h1> | ||
<div>Counter value: {count}</div> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.