From:  Nick Fitzgerald <>
Date:  04 Feb 2015 01:07:27 Hong Kong Time

Re: Source Maps, Debuggers, and Generated Code


On Mon, Feb 2, 2015 at 2:16 PM, Brian Slesinsky  wrote:

> On Mon, Feb 2, 2015 at 1:14 PM, Nick Fitzgerald 
> wrote:
>> ​I think there are two cases here:
>> 1. When the compiler needs to embed a runtime with various helper
>> functions
>> in the generated JS code. In this case, I think it makes sense to add an
>> entry to the sources list and map the appropriate code to this runtime
>> source.
>> 2. When a single statement in the source language results in many
>> statements in the JS code. In this case, I believe that all the generated
>> statements in the JS code should map back to the same location in the
>> source language.
> One problem is that JavaScript code may be reused (for example, it could
> be a generic helper function called from many places). But a sourcemap can
> only map it to one source location. You could get around this by generating
> the code N times for N locations, but this creates code bloat similar to
> inlining.

​It sounds​ to me like this is case (1) then, rather than case (2). If you
want the debugger to stop at this generic helper function, create a
"source" for your runtime. If you want it to be stepped through, use null

I guess you could even have a debug mode that generates the code bloat, if
you want, but I'd think either embedding a source for the runtime in the
sourcemap or using null mappings should handle whatever behavior you want.