-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Conversation
We need to use a different method for getting the meta info because `locate` is used to help construct the source map that references the preprocessed Svelte file. If we would now add source maps to that `locate` function it would go the the original source directly which means skipping potentially intermediate source maps which we would need in other situations. fixes #8360 closes #8362
const tracer = compile_options.sourcemap ? new TraceMap(compile_options.sourcemap) : undefined; | ||
this.meta_locate = (c) => { | ||
/** @type {{ line: number, column: number }} */ | ||
let location = this.locate(c); |
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 that
we 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. is locate
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)
It looks like |
Ah nice 👍 |
Nice, I think this solves my concern about internal state in the locator as well. I don't really like having both 0 and 1 index things going on but it is what it is. |
Also, |
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
We need to use a different method for getting the meta info because
locate
is used to help construct the source map that references the preprocessed Svelte file. If we would now add source maps to thatlocate
function it would go the the original source directly which means skipping potentially intermediate source maps which we would need in other situations.Also adds a new dependency, cc @benmccann that might affect the blog post
fixes #8360
closes #8362
TODO:
Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint