Code coverage report for 6to5/lib/6to5/generation/source-map.js

Statements: 96.67% (29 / 30)      Branches: 93.75% (15 / 16)      Functions: 100% (3 / 3)      Lines: 100% (26 / 26)      Ignored: none     

All files » 6to5/lib/6to5/generation/ » source-map.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 571   1 1   1 12210 12210   12210 13         13   12197       1 12210 12210 13   12197       1 1993626 1993626   1931164 1931164   4206   4180   4180         4180   4180   4180            
module.exports = SourceMap;
 
var sourceMap = require("source-map");
var t         = require("../types");
 
function SourceMap(position, opts, code) {
  this.position = position;
  this.opts     = opts;
 
  if (opts.sourceMap) {
    this.map = new sourceMap.SourceMapGenerator({
      file: opts.sourceMapName,
      sourceRoot: opts.sourceRoot
    });
 
    this.map.setSourceContent(opts.sourceFileName, code);
  } else {
    this.map = null;
  }
}
 
SourceMap.prototype.get = function () {
  var map = this.map;
  if (map) {
    return map.toJSON();
  } else {
    return map;
  }
};
 
SourceMap.prototype.mark = function (node, type) {
  var loc = node.loc;
  if (!loc) return; // no location info
 
  var map = this.map;
  if (!map) return; // no source map
 
  if (t.isProgram(node) || t.isFile(node)) return; // illegal mapping nodes
 
  var position = this.position;
 
  var generated = {
    line: position.line,
    column: position.column
  };
 
  var original = loc[type];
 
  Iif (generated.line === original.line && generated.column === original.column) return; // nothing to map
 
  map.addMapping({
    source: this.opts.sourceFileName,
    generated: generated,
    original: original
  });
};