Debugging CoffeeScript line-by-line

前端 未结 6 1738
遥遥无期
遥遥无期 2021-01-30 10:20

Is there a way to debug CoffeeScript line-by-line?

I understand that it compiles into Javascript. But this sounds like it could make it a pain to debug.

相关标签:
6条回答
  • 2021-01-30 10:52

    if you are running coffeescript from the terminal you can debug it line-for-line using node-inspector, launching your script this way:

    coffee --nodejs --debug-brk yourscript.coffee
    
    0 讨论(0)
  • 2021-01-30 10:57

    Update: there's currently a redesign of coffeescript compiler that generates source maps, which should enable you to debug your coffeescript in most recent versions of Google Chrome (18 and upwards I think).

    I think it's not production-ready yet, but it's worth mentioning.

    0 讨论(0)
  • 2021-01-30 11:00

    Coffeescript now supports source maps: http://coffeescript.org/

    Jetbrains for example supports this feature: https://blog.jetbrains.com/ruby/2013/01/whats-mining-coffeescript-debugger/

    0 讨论(0)
  • 2021-01-30 11:11

    At the moment it is quite a pain to debug CoffeeScript. Most people use lots of unit tests.

    There is some work being done on debugging for CoffeeScript but it is probably a while away before we'll have a really good debugger. One example is http://www.infoq.com/news/2011/08/debug-languages-on-javascript-vm

    0 讨论(0)
  • 2021-01-30 11:16

    Yes, with node-inspector:

    npm install -g node-inspector
    

    By putting the statement debugger into the source code of your script, you will enable a breakpoint. Then type in a console:

    coffee -c -m myscript.coffee
    node-debug myscript.js
    

    Node Inspector supports source-maps out of the box, so no extra configuration is needed.

    For more information see this post.

    0 讨论(0)
  • 2021-01-30 11:17

    now is 2020, i find this question, and then i find vscode support sourcemap, so we can use vscode to debug coffee directly.

    btw, i think coffee need a great improve. just like static data. anyway here is my launch.json:

    {
        "version": "0.2.0",
        "configurations": [{
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${file}", //important, make sure debug current file
            "outFiles": [
                "${workspaceFolder}/dist/api/api.js" //important, where to find sourcemap js file
            ]
        }]
    }
    
    0 讨论(0)
提交回复
热议问题