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
[babel-generator] Generated code doesn’t match with source with input source-maps #5408
Comments
Hey @alloy! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
Assuming I'm understanding fully, I think this may be the expected, if frustrating, behavior. I could see the benefit of moving this logic, so I'm happy to have this as a feature request if you'd like. Not sure it would be a high priority for the core team to implement though. |
Ah yes! This works: alloy/test-source-maps-with-typescript-through-babel@a2982c8 I was stepping through all the code looking for when the input and output maps of the generated code got merged and could only find it indeed in the transform step, glad I decided to ask. So if I understand you correctly you’re suggesting to extract |
I think it would be reasonable to move |
A similar issue was just raised in aspnet/JavaScriptServices#739 (comment). In that usecase, people are expecting the AST locations to take the original sourcemap locations into account. Given that, an alternative would be to actually delete I'm fine with that as a solution as long as there's no loss of information. |
I think I came across a similar issue while trying to write a jest preprocessor for TS -> Babel and getting code coverage right. I ended up not passing inputSourceMap into babel, and using source-map-merge to merge the source maps outputted by the TS compiler and babel respectively. Perhaps babel should use this module for merging input source maps rather than it's own merge code? From debugging the issue before I resorted to https://github.com/babel/babel/blob/master/packages/babel-core/src/transformation/file/index.js#L368 |
+1 for resolving this please. My issue is that Babel is not merging with source-maps from previous steps in my transformation chain, it appears to simply generate its own source-map from the input, which seems to be the problem everyone else is having. My workaround, for now, is to set retainLines: true, sourceMap: false and after transforming using Babel I copy the *.map files from the previous step to feed into the next step. Not ideal, but does the job. |
Any news on this? |
We're super invested in this, because it means that our bugsnags don't map back to the original TypeScript lines in our react-native source code :( |
Is there any way to solve this? A work around? |
Any update on this issue? |
I doubt there is, I've no need for Babel in my current role and won't find the time to contribute (I just got the notification because I've previously commented). If nothing much has changed in 4 years, my comment is my suggestion on fixing the issue: #5408 (comment), however I have no real idea whether or not that comment is applicable anymore. If a maintainer can comment and approve of the idea then it may be worth you implementing the fix and contributing it back? |
Hello, my employer has asked me to help solve this, if possible. We require this feature downstream in Metro (parallel issue here). Can a maintainer answer some questions?
Thank you. Hoping we can help solve this five-year-old issue! |
Yes, In addition, in theory ref: #15022 (comment) |
Thank you @liuxingbaoyu! Are you saying |
Yes, as in the OP's reproduced code. |
Input Code
I’ve put up a repo here
The relevant code is here
Expected Behavior
I would have expected the source-map from babel-generator to map from the original TypeScript source to the generated JS.
Current Behavior
The source-map doesn’t appear to have any relation to the original code.
Here are some examples of the code looked-up through the source-maps:
As you can see, the transform step does a good job of mapping to the original code, but the generate step just produces something completely different.
Context
I’m trying to use TypeScript for our React Native project and have inline source-maps propagate properly through Babel. I would prefer to not write the intermediate JS (produced by
tsc
) to disk.I’m not sure if I’m doing something wrong, if this has to do with how React Native uses transform and the generator, or if there’s a bug with
babel-generator
.Your Environment
The text was updated successfully, but these errors were encountered: