multi-stage-sourcemap ![Build Status](https://camo.githubusercontent.com/f37ec987f5c21909dd75663cf3afbb6e13e3d6406620224aa3ff8fd65e00e5c6/68747470733a2f2f7472617669732d63692e6f72672f617a752f6d756c74692d73746167652d736f757263656d61702e7376673f6272616e63683d6d6173746572)
This library provide re-mapping function for multi-level sourcemap.
Installation
npm install multi-stage-sourcemap
Concept
Basic SourceMap
well-know basic sourcemap is no problem.
Multi-level SourceMap
Multi-level SourceMap has a problem.
Source Map Revision 3 Proposal doens't provide the way of mapping Minified Code
to Original Code
in the following figure.
Example:
A.js -> B.js -> C.js
B.js.map -> C.js.map
We can't see from C.js to A.js.
multi-stage-sourcemap <= THIS LIBRARY
multi-stage-sourcemap
can mapping C.js
to A.js
The easy but lossy way is to ignore the intermediate steps in the process for the purposes of debugging, the source location information from the translation is either ignored (the intermediate translation is considered the “Original Source”) or the source location information is carried through (the intermediate translation hidden). -- Source Map Revision 3 Proposal
multi-stage-sourcemap
does that!
C.js -> ... -> A.js
Code:
var transfer = require("multi-stage-sourcemap").transfer;
var cToAMap = transfer({fromSourceMap: cMap, toSourceMap: bMap});
Usage
transfer
Return the re-mapped rawSourceMap
string.
The only argument is an object with the following properties:
fromSourceMap
: Object - rawSourceMap or String - JSON.stringify(rawSourceMap)toSourceMap
: Object - rawSourceMap or String - JSON.stringify(rawSourceMap)
rawSourceMap
is like below object.
var rawSourceMap = {
version: 3,
file: 'min.js',
names: ['bar', 'baz', 'n'],
sources: ['one.js', 'two.js'],
sourceRoot: 'http://exammuple.com/www/js/',
mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA'
};
For details, please see mozilla/source-map.
Use Case
- AltJS -> JavaScript -> minify
- AltJS -> JavaScript -> power-assert
- power-assert supports multi-level sourcemaps using this module.
- twada/battlefield-sourcemaps
- power-assert 多段 SourceMap 対応の方針
etc...
AltJS is languages that compile to JS. (It's contain ES6 with Traceur. )
Related library
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
License
MIT