Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I enable a source map for coffeescript?

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.

like image 655
Jerome WAGNER Avatar asked Jun 07 '12 23:06

Jerome WAGNER


3 Answers

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.

like image 193
mquandalle Avatar answered Oct 18 '22 03:10

mquandalle


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
like image 7
Ajay M Avatar answered Oct 18 '22 01:10

Ajay M


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

like image 5
Trevor Burnham Avatar answered Oct 18 '22 01:10

Trevor Burnham