SourceMap missing lines. Not sure if writeAndMap gives correct line and column numbers
martypdx opened this issue · comments
Motivation
Be able to pass arbitrary source nodes to state.writeAndMap
and get accurate source maps.
I'm not entirely sure how writeAndMap
is treating source nodes versus generated code
. Does the early return code for LineComments and TemplateLiterals assume the source node has a direct relationship with the generated code?
My specific issue is I have transformed JSX to AST and then use astring to generate JavaScript. The source code has no JSX, but because the JSXText spanned multiple lines astring cannot track it.
I don't think problem is specific to using JSX.
Expected behavior
Advancement of column and line position should only be done based on content of code. For source mapping, there's no guarantee source node has any type or structure relation to generated code.
Actual behavior
writeAndMap
assumes if source node is LineComment or TemplateLiteral, generated code follow same rules? Or the linebreaks in JSX don't get accounted for? Here's what I am seeing:
![image](https://private-user-images.githubusercontent.com/478864/306051027-5bbe02bd-13c9-4fd8-9fd8-a7f3eecc7aea.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA1ODgxNjksIm5iZiI6MTcyMDU4Nzg2OSwicGF0aCI6Ii80Nzg4NjQvMzA2MDUxMDI3LTViYmUwMmJkLTEzYzktNGZkOC05ZmQ4LWE3ZjNlZWNjN2FlYS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzEwJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcxMFQwNTA0MjlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1mZDVjYzA0ZGJkZjRmODQyNDVjNTBhODc5NjQwOWQ2YTllMzA5Y2Y1MzBlNDg2MTNjNTRjNDM3ZDIxZWI3OTVhJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.F5fl1_hsn3twNLzzsFXdImMduXzQJixl7kGgcZwe--Q)
I think this is a red herring. Going to close and open new issue.