estools/estraverse

How to make an accompanying sourcemap for transform?

trusktr opened this issue · 0 comments

I posted a question on SO, but then thought I might also ask here.

Does estraverse support making a source map? Something like estraverse.replace(ast, transform, sourceMap) would be awesome. Maybe in the returned AST object the root node can have a sourceMap property? Or something along the lines of being able to supply a source map for the original AST in order to get the resulting source map. If no sourcemap is provided, then it would just return a sourcemap as if this is the first transform on the given code.

Would something like that be doable? What are the limitations? For example, I know the AST doesn't contain info about semi colons or the number and ordering of whitespace characters, so it may be difficult to map that.

Is there any existing recommended way to handle source maps with esprima+estraverse?