gkz / LiveScript

LiveScript is a language which compiles to JavaScript. It has a straightforward mapping to JavaScript and allows you to write expressive code devoid of repetitive boilerplate. While LiveScript adds many features to assist in functional style programming, it also has many improvements for object oriented and imperative programming.
http://livescript.net
MIT License
2.32k stars 155 forks source link

How do we add sourcemaps into dynamically evaluated code? #1077

Closed ceremcem closed 5 years ago

ceremcem commented 5 years ago

In my app, dynamically generated code is run (just like in livescript.net) in browser. How can we add sourcemaps for those dynamically generated scripts?

rhendric commented 5 years ago

You can add a key called map to the options object passed to compile. The valid values are the same as for the --map option on the command line. compile will return an object instead of a string, with code and map fields. If you're passing the code on to something that understands //# sourceMappingURL directives, then using the 'embedded' option will stuff the source map into code, so at that point you're done. If not, you'll want to use 'linked-src', and process the map yourself; I think it's an instance of SourceMapGenerator.

You may also want to add a filename key to your compile options, since otherwise your source map will reference unnamed-xxxxxxxx.js.

ceremcem commented 5 years ago

Thanks for your help. It turns out that this (my) problem was containing multiple issues: Explanation

TL;DR;

Executing a dynamically created code while keeping your current app working involves using try/catch block, which prevents debugger (Chromium's at least) from hit to the correct exception point.

Both including the sourcemaps (embedded option worked for me) and enabling Pause on exceptions in debugger window (see this) makes the debugger hit the exact exception line.