Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vincentcr opened this issue Feb 9, 2016 · 5 comments
Open

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

vincentcr opened this issue Feb 9, 2016 · 5 comments

Comments

@vincentcr
Copy link

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

@jkrems
Copy link
Contributor

jkrems commented Feb 9, 2016

@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
Copy link
Author

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
Copy link
Contributor

jkrems commented Feb 9, 2016

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. :(

@jkrems
Copy link
Contributor

jkrems commented Feb 9, 2016

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
Copy link
Author

yes, indeed, the same issue does happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants