Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It allows you to debug any language that compiles to JavaScript, with the caveat that the language's compiler must output source-map compatible code (or the source must be run through some other program that somehow does it).

It's a pretty simple but extremely useful idea. To use your example, the CoffeeScript compiler knows exactly which bits of generated JavaScript correspond to exactly what bits of CoffeeScript code, so the compiler can output a mapping that says "these lines of JavaScript are the result of this line of CoffeeScript...so when you step through this CoffeeScript line, execute these X lines of JavaScript, if an error occurs in these X lines of JavaScript show there error as occurring on line Y of the CoffeeScript code.

I haven't done much front-end lately so I'm not sure what if any the CoffeeScript compiler has in terms of generating source maps, but if browsers are supporting it I imagine it won't be long if it's not here already.



AFAIK, the CoffeeScript guys are working intensely on it. To some extent, any language which has accurate source position information in its parser/AST, and uses Closure Compiler on the backend can get source map output almost for free.


Yea I would imagine they are. I haven't been following the development like I used to, so thanks.

How accurate does the source position information have to be? I don't think the CoffeeScript lexer can output column numbers (at least it didn't last time I checked) and the re-writing stage might give them a little trouble. Should be doable though.

Guess I should head over to github and see how they're doing and start reading the SourceMap spec.


Here's a link to the CoffeeScript discussion on source maps (with a working alternate solution).

https://github.com/jashkenas/coffee-script/issues/558


IIRC, you only need line number and filename. The map is JS <startline/startcol> -> Source <line,filename>


However, you can embed extra metadata for your specific source language if you wish, via the extension mechanism. Debug tools can then read the metadata in to do extra neat kinds of mapping (such as collapsing "native" stack frames).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: