UNPKG

1.62 kBJavaScriptView Raw
1// Generated by CoffeeScript 1.6.3
2(function() {
3 var langs, noop, process;
4
5 noop = "__noop__cc__";
6
7 process = function(_arg) {
8 var regexp, transform;
9 regexp = _arg.regexp, transform = _arg.transform;
10 return function(line) {
11 var exp, padding, x, _ref;
12 x = line.match(regexp);
13 if (!x) {
14 return {
15 line: line
16 };
17 }
18 _ref = x.slice(1), padding = _ref[0], exp = _ref[1];
19 return {
20 line: padding + transform(exp),
21 altered: true
22 };
23 };
24 };
25
26 langs = {
27 js: {
28 header: "var " + noop + " = function() {};",
29 processLine: process({
30 regexp: /^(\s*)\/\/\s*JSCOV:\s*(.*[^\s])(\s*)$/,
31 transform: function(exp) {
32 return "if (" + exp + ") { " + noop + "() } else { " + noop + "() };";
33 }
34 })
35 },
36 coffee: {
37 header: "" + noop + " = (->)",
38 processLine: process({
39 regexp: /^(\s*)#\s*JSCOV:\s*(.*[^\s])(\s*)$/,
40 transform: function(exp) {
41 return "if (" + exp + ") then " + noop + "() else " + noop + "()";
42 }
43 })
44 }
45 };
46
47 exports.expand = function(str, options) {
48 var altered, lang, result, _ref;
49 if (options == null) {
50 options = {};
51 }
52 lang = (_ref = options.lang) != null ? _ref : 'js';
53 result = str.split('\n').map(langs[lang].processLine);
54 altered = result.some(function(x) {
55 return x.altered;
56 });
57 if (altered) {
58 return langs[lang].header + "\n" + result.map(function(x) {
59 return x.line;
60 }).join('\n');
61 } else {
62 return str;
63 }
64 };
65
66}).call(this);