21

I recently discovered the existence of source maps in chrome via source debugging in the haxe language. It allows to debug generated javascript inside the chrome browser while seeing the bug reason in the original source code.

Has anyone written a source map generator for coffeescript / Is coffeescript source mappable ?

It would help debug the javascript generated by coffeescript.

4 Answers 4

26

Coffeescript 1.6 has native support for source maps.

Use the "--map" or "-m" option to enable it. Or if you use the npm compiler, you will have to add the sourceMap: true option.

Sign up to request clarification or add additional context in comments.

Comments

7
npm install -g coffee-script

Should install coffee-script as a global module. Check version > 1.6 by typing

coffee -v

If you need help you can use. Use it to see meaning of options used below

coffee -h

For regular compilation use

coffee -mo script/ -cw src/

This should auto-generate maps files. I leave this running in terminal as I code, it compiles every time I save.

KNOWN BUG:

The current coffee-script compiler does not seem to handle different /src and /script directories. In map file you find that sources = {filename} rather than {relative file path}.

SOLUTION:

  1. Keep your .coffee files in same directory as .js
  2. Modify source directive manually in .map file. This will get overwritten again on next save

1 Comment

+1 for the known bug mention. That was my problem. Headache has subsided
5

This has long been an active issue on the CoffeeScript project (indeed, it predates the source map standard). However, no (complete) CoffeeScript source map generator exists yet. For discussion, see https://github.com/jashkenas/coffee-script/issues/558

Source map support is also one of the goals of the "CoffeeScript Redux" compiler that was recently funded on Kickstarter (see http://www.kickstarter.com/projects/michaelficarra/make-a-better-coffeescript-compiler). That project has just begun; you can watch it at https://github.com/michaelficarra/CoffeeScriptRedux

1 Comment

As of 1.6.0, CoffeeScript has native support for source maps. coffeescript.org/#source-maps
0

Ps, if you're on vim, use:

au BufWritePost *.coffee silent make -m

which compiles with source map on file save. I've found it extremely handy when I want some random buffer to start compiling coffee for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.