-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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: account for sourcemap in meta info #8778
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c917eb1
fix: account for sourcemap in meta info
dummdidumm 903ba2e
changeset
dummdidumm 10aadf4
Apply suggestions from code review
dummdidumm 61ff4ea
doc here, too
dummdidumm a6ddb2d
lazy init for a tiny speed boost on prod builds
dummdidumm f4108c0
add comment about limitation
dummdidumm db686cf
test
dummdidumm a03ec02
package.json spaces
dummdidumm f0ff443
fix comment
dummdidumm 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 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,5 @@ | ||
--- | ||
'svelte': patch | ||
--- | ||
|
||
fix: account for preprocessor source maps when calculating meta info |
This file contains 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 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 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 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 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
33 changes: 33 additions & 0 deletions
33
packages/svelte/test/runtime/samples/element-source-location-preprocessed/_config.js
This file contains 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,33 @@ | ||
import MagicString from 'magic-string'; | ||
import * as path from 'node:path'; | ||
|
||
// fake preprocessor by doing transforms on the source | ||
const str = new MagicString( | ||
`<script> | ||
type Foo = 'foo'; | ||
let foo = 'foo'; | ||
</script> | ||
|
||
<h1>{foo}</h1> | ||
`.replace(/\r\n/g, '\n') | ||
); | ||
str.remove(8, 26); // remove line type Foo = ... | ||
str.remove(55, 56); // remove whitespace before <h1> | ||
|
||
export default { | ||
compileOptions: { | ||
dev: true, | ||
sourcemap: str.generateMap({ hires: true }) | ||
}, | ||
|
||
test({ assert, target }) { | ||
const h1 = target.querySelector('h1'); | ||
|
||
assert.deepEqual(h1.__svelte_meta.loc, { | ||
file: path.relative(process.cwd(), path.resolve(__dirname, 'main.svelte')), | ||
line: 5, // line 4 in main.svelte, but that's the preprocessed code, the original code is above in the fake preprocessor | ||
column: 1, // line 0 in main.svelte, but that's the preprocessed code, the original code is above in the fake preprocessor | ||
char: 38 // TODO this is wrong but we can't backtrace it due to limitations, see add_location function usage comment for more info | ||
}); | ||
} | ||
}; |
5 changes: 5 additions & 0 deletions
5
packages/svelte/test/runtime/samples/element-source-location-preprocessed/main.svelte
This file contains 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,5 @@ | ||
<script> | ||
let foo = 'foo'; | ||
</script> | ||
|
||
<h1>{foo}</h1> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
it's confusing to me that we used a 1-based locator for
meta_locate
and then subtract 1. if we just used the default sourcemap offset we wouldn't have to deal with thatwe could make
meta_locate
use a separate 0-based locator. would that be more expensive though?or we could make
locate
be 0-based and then just add 1 when we're printing it out. I think that'd be clearer because sourcemaps are 0-based and then we can just treat everything in the codebase as being 0-based. islocate
exposed externally though and would that be a breaking change that results in a more difficult API for people needing to print stack traces?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.
This won't change much as the source mapping function works on 1-based lines so we have back and forth either way. I think the way it's now is the most consistent (both locate and meta_locate are 1-based) and you do whatever you need to do on the consumer side (and 1-based is needed more often)