ericmckean / traceur-compiler

Automatically exported from code.google.com/p/traceur-compiler
Apache License 2.0
0 stars 0 forks source link

Make use of source maps in Node stack traces (and maybe in the browser) #227

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This is one package implementing source maps: 
https://github.com/evanw/node-source-map-support

The method used there should work in Chrome/Chromium as well (and everything 
else using V8).
I don't know if SpiderMonkey lets you do this.

Original issue reported on code.google.com by edy.b...@gmail.com on 27 Mar 2013 at 2:13

GoogleCodeExporter commented 9 years ago
Since Chrome and Firefox already support sourcemaps natively, we only
really have to worry about node. Which makes things a lot easier.

So this could be a special option for node debug compilation.

#--cut--
npm install --local source-map-support
## Note: Obviously, there is some code here that should have been generated
## automatically.
cat > throw.js <<"END"
require('source-map-support').install();
require('./src/node/traceur.js');
var f = (i) => { throw new Error(`traceur test ${i + 40}`); };
f(2);
END
./traceur --out throw.out.js --sourcemap -- throw.js
## Neat. The error is in the original source file.
node throw.out.js
#--cut--

Thanks for bringing up this library. This is actually pretty cool.

Original comment by usrbi...@yahoo.com on 27 Mar 2013 at 5:57

GoogleCodeExporter commented 9 years ago
Sounds useful

Original comment by arv@chromium.org on 27 Mar 2013 at 6:04

GoogleCodeExporter commented 9 years ago
Oh, didn't know about Chrome and Firefox.

I think src/node/traceur.js should load source-map-support and call install().

It doesn't seem to allow monkey patching of any sort, so you can't have it work 
without saving the compiled file and the sourcemap, a proper patch is required 
for runtime dynamic sourcemap insertion.
Maybe replace the empty cache with Object.create(exports.overrides), that would 
allow traceur to do require('source-map-support').overrides[filename] = 
sourceMap;

Original comment by edy.b...@gmail.com on 27 Mar 2013 at 6:52