-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
missing lines in typescript source maps #249
Comments
Wow, that's so weird. Thanks for investigating this. Clearly my mental model of how that library works is wrong. I assumed that it just binary searches through the mappings in the generated file and finds the closest one that comes before the query. That even seems to be what the source-map library itself does. But if that were true, a query would never return null as long as the file starts with a mapping. So I'm not really sure what's going on now. FWIW even the source maps generated by TypeScript have dead spots that return null. You can see them by iterating the query code you have over all lines and columns in the generated file. The dead spots appear to be in indents. If I had to guess, I'd say that Mozilla's library fails to return the previous marker if it's not on the same line as the query. I guess that's just a bug in their implementation (the one you linked to)? If that's the case, an appropriate workaround to avoid these dead spots could be for esbuild to ensure every generated line starts with a mapping. It should be sufficient to just copy the last mapping for the previous line onto the new line if the new line doesn't already start with one. |
Yeah, I think that's the case. There is a bias option for columns, returning the nearest match if it can't find anything. But that doesn't work for lines. |
Ok I think I've fixed the missing lines within an input file. See the release notes for caveats. If bundling is on, some lines that don't correspond to an input file still won't have coverage. Repeating previous mappings to cover those lines seems incorrect to me because those lines aren't actually a part of that file at all, and could lead to confusing debugging situations. |
I can confirm it's working correctly now! Thanks a lot for the swift action. |
I'm using esbuild during testing to compile away typescript. I'm using istanbul to generate code coverage results, which uses https://www.npmjs.com/package/source-map to convert the instrumented code back to the original code. With TSC I get accurate code coverage results, but with esbuild I don't.
After investigation, I think it's because esbuild doesn't print some lines in the source maps while TSC does.
I'm using this source file:
This is the esbuild output:
The source maps translate to:
As you can see line 3 and 7 are missing.
This is the TSC output:
The source maps translate to:
Here line 3 and 7 are present.
You can observe the difference between esbuild and TSC in this REPL: https://repl.it/repls/TastyRareLevels
When a line is missing, the
source-map
library returns null. I found an open issue for this: mozilla/source-map#261I haven't worked with source maps before, so I'm not entirely certain what the solution here should be. Perhaps when
source-map
returns null, we should just use the position of the generated code. However this logic is buried inside other libraries I'm using.Other people might run into this issue as well, so perhaps esbuild could output more detailed source maps?
The text was updated successfully, but these errors were encountered: