play nicely with coffeescript source maps
Closed this issue · 4 comments
CoffeeScript supports source maps - and correct line number mapping with errors.
http://jashkenas.github.com/coffee-script/documentation/docs/coffee-script.html
However, when longjohn
is require'd, it messes with the line mapping -- probably something to do with the override of Error.prepareStackTrace
. It would be great if longjohn could be fixed to show coffeescript source line numbers, when a coffeescript source map is available.
$ npm install longjohn source-map-support coffee-script
$ node_modules/coffee-script/bin/coffee --map --compile demo.coffee
$ cat demo.cofee
source_map = require('source-map-support')
source_map.install()
longjohn = require('longjohn');
longjohn.format_stack_frame = (frame) ->
return longjohn.empty_frame if frame.getFileName() is longjohn.empty_frame
return ' at ' + source_map.wrapCallSite(frame);
foo = ->
bar = -> throw new Error 'this is a demo'
bar()
setTimeout(
lol = ->
foo()
, 1000)
$ node demo.js
/home/s.volkov/Proj/longjohn/dist/demo.coffee:8
bar = -> throw new Error 'this is a demo'
^
Error: this is a demo
at bar (/home/s.volkov/Proj/longjohn/dist/demo.coffee:8:22)
at foo (/home/s.volkov/Proj/longjohn/dist/demo.coffee:9:3)
at [object Object].lol (/home/s.volkov/Proj/longjohn/dist/demo.coffee:12:5)
at Timer.listOnTimeout [as ontimeout] (timers.js:121:15)
---------------------------------------------
at Object.<anonymous> (/home/s.volkov/Proj/longjohn/dist/demo.coffee:10:1)
at Object.<anonymous> (/home/s.volkov/Proj/longjohn/dist/demo.coffee:1:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:935:3
Thanks @drauggres!!!
I've changed the code and pushed it back up to support source maps through the method that @drauggres outlines above. You wouldn't need to install source-map-support, just compile your scripts with --map turned on and then run like normal.
Could someone pull the latest changes and try it out locally before I release a new version?
Thanks!
Published to npm as version 0.2.9.