groupon / cson-parser

Simple & safe CSON parser
BSD 3-Clause "New" or "Revised" License
132 stars 27 forks source link

coffee-script source maps broken when using this package #53

Open vincentcr opened 8 years ago

vincentcr commented 8 years ago

coffeescript-generated source maps stop working the moment this package is required the first time.

jkrems commented 8 years ago

@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)
vincentcr commented 8 years ago

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
jkrems commented 8 years ago

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 intocson-parser` which is a fair amount of work. :(

jkrems commented 8 years ago

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?

vincentcr commented 8 years ago

yes, indeed, the same issue does happen.