davidbonnet / astring

🌳 Tiny and fast JavaScript code generator from an ESTree-compliant AST.

Home Page:https://david.bonnet.cc/astring/demo/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

I think this is a red herring. Going to close and open new issue.