-
-
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 2 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,23 @@ | ||
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 | ||
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,27 @@ | ||
import { getLocator } from 'locate-character'; | ||
import { COMMON, STYLES } from './_config'; | ||
|
||
export function test({ assert, input, preprocessed }) { | ||
|
||
const assertMapped = (locateInput, code, filename) => { | ||
dummdidumm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const sourceLoc = locateInput(code); | ||
const transformedLoc = preprocessed.locate_1(code); | ||
assert.deepEqual( | ||
preprocessed.mapConsumer.originalPositionFor(transformedLoc), | ||
{ | ||
source: filename, | ||
name: null, | ||
line: sourceLoc.line + 1, | ||
column: sourceLoc.column | ||
}, | ||
`failed to locate "${code}"` | ||
); | ||
}; | ||
|
||
// Transformed script, main file | ||
assertMapped(input.locate, 'Divs ftw!', 'input.svelte'); | ||
|
||
// External files | ||
assertMapped(getLocator(COMMON), 'height: 100%;', 'common.scss'); | ||
assertMapped(getLocator(STYLES), 'color: orange;', 'styles.scss'); | ||
} |
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 @@ | ||
import { magic_string_bundle } from '../../helpers'; | ||
|
||
export const PREPEND = 'console.log("COUNTER_START")'; | ||
export const APPEND = 'console.log("COUNTER_END")'; | ||
|
||
export default { | ||
js_map_sources: ['input.svelte', 'src/prepend.js', 'src/append.js'], | ||
preprocess: [ | ||
{ | ||
script: ({ content }) => { | ||
return magic_string_bundle([ | ||
{ filename: 'src/prepend.js', code: PREPEND }, | ||
{ filename: 'src/input.svelte', code: content }, | ||
{ filename: 'src/append.js', code: APPEND } | ||
]); | ||
} | ||
} | ||
] | ||
}; |
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,6 @@ | ||
<script lang="ts"> | ||
let count = 3; | ||
</script> | ||
|
||
<h1>Hello world!</h1> | ||
<div>Counter value: {count}</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,30 @@ | ||
import { getLocator } from 'locate-character'; | ||
import { APPEND, PREPEND } from './_config'; | ||
|
||
export function test({ assert, input, preprocessed }) { | ||
|
||
const assertMapped = (locateInput, code, filename) => { | ||
const sourceLoc = locateInput(code); | ||
const transformedLoc = preprocessed.locate_1(code); | ||
assert.deepEqual( | ||
preprocessed.mapConsumer.originalPositionFor(transformedLoc), | ||
{ | ||
source: filename, | ||
name: null, | ||
line: sourceLoc.line + 1, | ||
column: sourceLoc.column | ||
}, | ||
`failed to locate "${code}"` | ||
); | ||
}; | ||
|
||
// Transformed script, main file | ||
assertMapped(input.locate, 'let count = 3;', 'input.svelte'); | ||
|
||
// Untouched markup, main file | ||
assertMapped(input.locate, '<h1>Hello world!</h1>', 'input.svelte'); | ||
|
||
// External files | ||
assertMapped(getLocator(PREPEND), '"COUNTER_START"', 'src/prepend.js'); | ||
assertMapped(getLocator(APPEND), '"COUNTER_END"', 'src/append.js'); | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a test for these different cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
guess-source
. I'm not sure if this is the right approach though... While it may workaround some cases, maybe it would be better to require correct maps from preprocessors?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think it would be a good idea to have preprocessors producing more consistent sourcemaps either way even if we didn't require them here. Requiring them sounds like a reasonable idea though. Do you know which ones are producing these different paths and what the preferred version is? It could be helpful to file an issue against https://github.com/sveltejs/svelte-preprocess with these details
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had issue with postcss transformer. The first thing that comes to mind - it should pass "to" parameter to postcss (equal to "from"). Will check and report later.