Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / ibrik / lib / instrumenter.js
1 // Generated by CoffeeScript 1.8.0
2 (function() {
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; };
6
7   coffee = require('coffee-script');
8
9   istanbul = require('istanbul');
10
11   estraverse = require('estraverse');
12
13   _ = require('lodash');
14
15   esprima = require('esprima');
16
17   path = require('path');
18
19   fs = require('fs');
20
21   globalEval = function(source) {
22     var geval;
23     geval = eval;
24     return geval(source);
25   };
26
27   Instrumenter = (function(_super) {
28     __extends(Instrumenter, _super);
29
30     function Instrumenter(opt) {
31       istanbul.Instrumenter.call(this, opt);
32     }
33
34     Instrumenter.prototype.instrumentSync = function(code, filename) {
35       var e, program;
36       filename = filename || ("" + (Date.now()) + ".js");
37       if (typeof code !== 'string') {
38         throw new Error('Code must be string');
39       }
40       try {
41         code = coffee.compile(code, {
42           sourceMap: true
43         });
44         program = esprima.parse(code.js, {
45           loc: true
46         });
47         this.fixupLoc(program, code.sourceMap);
48         return this.instrumentASTSync(program, filename, code);
49       } catch (_error) {
50         e = _error;
51         e.message = "Error compiling " + filename + ": " + e.message;
52         throw e;
53       }
54     };
55
56     Instrumenter.prototype.include = function(filename) {
57       var code;
58       filename = path.resolve(filename);
59       code = fs.readFileSync(filename, 'utf8');
60       this.instrumentSync(code, filename);
61       globalEval("" + (this.getPreamble(null)));
62     };
63
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]);
71             line = 0;
72             column = 0;
73             if (locArray) {
74               line = locArray[0] + 1;
75               column = locArray[1];
76             }
77             return {
78               line: line,
79               column: column
80             };
81           };
82           if ((_ref = node.loc) != null ? _ref.start : void 0) {
83             node.loc.start = mappedLocation(node.loc.start);
84           }
85           if ((_ref1 = node.loc) != null ? _ref1.end : void 0) {
86             node.loc.end = mappedLocation(node.loc.end);
87           }
88         }
89       });
90     };
91
92     return Instrumenter;
93
94   })(istanbul.Instrumenter);
95
96   module.exports = Instrumenter;
97
98 }).call(this);