benjamn / recast

JavaScript syntax tree transformer, nondestructive pretty-printer, and automatic source map generator
MIT License
5.01k stars 350 forks source link

Teach recast.parse about //#sourceURL= and //#sourceMappingURL= #109

Open benjamn opened 10 years ago

benjamn commented 10 years ago

Currently, the Lines object created by recast.parse(source, options) knows the name of the source file that was parsed only if options.sourceFileName is explicitly provided.

When the parsed code contains a //#sourceURL= or //#sourceMappingURL= comment, we can use that information to inform the Lines object where it came from, even if no options.sourceFileName is provided.

When the recast.parsed AST is reprinted by recast.print, we should be able to aggregate all that source mapping information into recast.print(ast).map, even if there are fragments from multiple source files mixed together in the final AST.

If we get this right, you'll be able to mix and match ASTs to your heart's content without ever thinking about source maps.

lydell commented 9 years ago

Shameless plug: Sounds like you might be interested in source-map-url.

caridy commented 9 years ago

related to https://github.com/benjamn/recast/pull/146

benjamn commented 9 years ago

Also related: #115