A solution to the problem is in the use of Source Maps (SMAP) which relate each piece of generated code to the source code that produced it. Using a SMAP it is possible to report errors in the code that is running in the browser or on the server to the line in the source code that produced it so allowing the programmer a better chance of understanding the nature of the problem.
Currently only Google's Closure compiler generates SMAP files and the only tool that can make use of them is Closure Inspector a Firebug extension. Now we have news that both Mozilla and WebKit are working on projects that might result in something that supports SMAP more widely. Mozilla outlines the requirements for the project as:
- When a sourcemap is available, error messages in console will link to the original source, not the generated JS
- Likewise, console log output will link back to the original source
- Patches for CoffeeScript will be used to produce examples
- The Closure Compiler should generate compatible source maps
- A specification for generated scripts to refer to their mappings and a mapping format
- SpiderMonkey needs to output column in addition to source/line.
- code that is loaded via eval() should also support sourcemaps
Closure Tools - Google Code
Mozilla: SMAP and debugging functionality
Thanks to InfoQ for bringing this development to a wider audience.
If you would like to be informed about new articles on I Programmer you can either follow us on Twitter or Facebook or you can subscribe to our weekly newsletter.