concept source map in category coffeescript

appears as: source maps, source map, The source map
CoffeeScript in Action

This is an excerpt from Manning's book CoffeeScript in Action.

In this chapter you’ll look at the evolving relationship between CoffeeScript and JavaScript and why your understanding of CoffeeScript applies not only to JavaScript today but also to the JavaScript of tomorrow. You’ll see how JavaScript versions relate to different editions of the ECMAScript specification that documents the evolving JavaScript standard. Lastly, this chapter discusses one of the most important tool-related aspects of the JavaScript ecosystem: how to debug CoffeeScript programs with source maps. Before looking at the future, though, where are you now?

13.4.2. Getting started with source maps

To try CoffeeScript with source maps, you’ll need both a runtime that supports them and a CoffeeScript compiler that can create a source map. Right now, that means a CoffeeScript compiler version greater than 1.6 and a recent version of your web browser that supports source maps.[1] Before long, source maps will be supported by more runtimes.

1 Consult the documentation for your browser to determine if it supports source maps and how you can enable them.

The source map won’t make much sense because it’s not intended to be human readable. It’s a JSON file containing information that the runtime can use to map from the compiled JavaScript program to your original CoffeeScript source:

{
  "version":3,
  "file":" sourcemaps.coffee",
  "sources":[
    "sourcemaps.coffee"
  ],
  "names":[],
  "mappings":"AAAC;;;EAAA,MAAA,GAAS,SAAA,CAAA,KAAA,CAAA;;;MAAW,2BAAqB,aAArB,
aAAA,CAAA,KAAA,CAAA;QAAa,OAAQ;oBAArB,IAAA,CAAA,CAAA,CAAO;;;;;EAC3B,OAAO,IAAP,CAAY,MAAA,CAAO,CAAA;AAAA,IAAC,CAAD;AAAA,IAAG,CAAH;AAAA,IAAK,CAAL;
AAAA,IAAO,CAAP;AAAA,EAAA,CAAP,CAAZ;EACA,KAAA,CAAM,GAAA,CAAI,KAAJ,CAAU,
mBAAV,CAAN"
}

To use the source map, the runtime needs to be told where to find it. To tell the runtime where to find the source map, either put a comment in the compiled JavaScript or set an X-SourceMap header if the file is served over HTTP. You add a comment to the file like this: