coffee-script source maps broken when using this package
coffeescript-generated source maps stop working the moment this package is required the first time.
@vincentcr Thanks for the report! Can you provide some more details about how to reproduce the issue? I'm assuming you're talking about the stack patching coffee-script does.
I gave it a quick try and it seems to work when only cson-parser and coffee-script are involved:
2) CSON.parse reviver functions works just like JSON.parse:
Error: This should have a coffee stack
at Object.reviver (test/parse.test.coffee:191:19)
at Object.parse (native)
at Context.<anonymous> (test/parse.test.coffee:214:24)
I am speaking of a .coffee file compiled to .js with the -m option:
demo.coffee:
require('source-map-support').install()
fs = require('fs')
foo = ->
bar = -> throw new Error 'this is a demo'
bar()
try
foo( )
catch err
console.log('err before cson', err.stack)
## the above log will print the correct stack
require('cson-parser').parse(fs.readFileSync('./config/defaults.cson', 'UTF-8'))
foo() ## will not print the correct stack
run like so:
$ coffee -c -m demo.coffee
$ node demo.js
Ah, so it's about coffee-script and source-map-support not playing nice. I'm not sure there's much cson-parser itself can do about this. Will leave this issue open in case someone comes up with a good solution.* But for now your best bet might be to open an issue in coffee-script or source-map-support. :)
(*) There are at least two potential solutions. But the first involves reaching into coffee-script/lib/* which is fragile and the second involves porting the coffee-script parser into cson-parser which is a fair amount of work. :(
For reference, I'm assuming the more minimal repro is the following:
require('source-map-support').install()
fs = require('fs')
foo = ->
bar = -> throw new Error 'this is a demo'
bar()
try
foo( )
catch err
console.log('err before coffee-script', err.stack)
## the above log will print the correct stack
require 'coffee-script'
foo() ## will not print the correct stack
Can you confirm?
yes, indeed, the same issue does happen.