1 // Generated by CoffeeScript 1.8.0
3 var Instrumenter, coffee, esprima, estraverse, fs, globalEval, istanbul, path, _,
4 __hasProp = {}.hasOwnProperty,
5 __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
7 coffee = require('coffee-script');
9 istanbul = require('istanbul');
11 estraverse = require('estraverse');
13 _ = require('lodash');
15 esprima = require('esprima');
17 path = require('path');
21 globalEval = function(source) {
27 Instrumenter = (function(_super) {
28 __extends(Instrumenter, _super);
30 function Instrumenter(opt) {
31 istanbul.Instrumenter.call(this, opt);
34 Instrumenter.prototype.instrumentSync = function(code, filename) {
36 filename = filename || ("" + (Date.now()) + ".js");
37 if (typeof code !== 'string') {
38 throw new Error('Code must be string');
41 code = coffee.compile(code, {
44 program = esprima.parse(code.js, {
47 this.fixupLoc(program, code.sourceMap);
48 return this.instrumentASTSync(program, filename, code);
51 e.message = "Error compiling " + filename + ": " + e.message;
56 Instrumenter.prototype.include = function(filename) {
58 filename = path.resolve(filename);
59 code = fs.readFileSync(filename, 'utf8');
60 this.instrumentSync(code, filename);
61 globalEval("" + (this.getPreamble(null)));
64 Instrumenter.prototype.fixupLoc = function(program, sourceMap) {
65 return estraverse.traverse(program, {
66 leave: function(node, parent) {
67 var mappedLocation, _ref, _ref1;
68 mappedLocation = function(location) {
69 var column, line, locArray;
70 locArray = sourceMap.sourceLocation([location.line - 1, location.column]);
74 line = locArray[0] + 1;
82 if ((_ref = node.loc) != null ? _ref.start : void 0) {
83 node.loc.start = mappedLocation(node.loc.start);
85 if ((_ref1 = node.loc) != null ? _ref1.end : void 0) {
86 node.loc.end = mappedLocation(node.loc.end);
94 })(istanbul.Instrumenter);
96 module.exports = Instrumenter;