Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80677 views
1
// Generated by CoffeeScript 1.9.3
2
(function() {
3
var LineMap, SourceMap;
4
5
LineMap = (function() {
6
function LineMap(line1) {
7
this.line = line1;
8
this.columns = [];
9
}
10
11
LineMap.prototype.add = function(column, arg, options) {
12
var sourceColumn, sourceLine;
13
sourceLine = arg[0], sourceColumn = arg[1];
14
if (options == null) {
15
options = {};
16
}
17
if (this.columns[column] && options.noReplace) {
18
return;
19
}
20
return this.columns[column] = {
21
line: this.line,
22
column: column,
23
sourceLine: sourceLine,
24
sourceColumn: sourceColumn
25
};
26
};
27
28
LineMap.prototype.sourceLocation = function(column) {
29
var mapping;
30
while (!((mapping = this.columns[column]) || (column <= 0))) {
31
column--;
32
}
33
return mapping && [mapping.sourceLine, mapping.sourceColumn];
34
};
35
36
return LineMap;
37
38
})();
39
40
SourceMap = (function() {
41
var BASE64_CHARS, VLQ_CONTINUATION_BIT, VLQ_SHIFT, VLQ_VALUE_MASK;
42
43
function SourceMap() {
44
this.lines = [];
45
}
46
47
SourceMap.prototype.add = function(sourceLocation, generatedLocation, options) {
48
var base, column, line, lineMap;
49
if (options == null) {
50
options = {};
51
}
52
line = generatedLocation[0], column = generatedLocation[1];
53
lineMap = ((base = this.lines)[line] || (base[line] = new LineMap(line)));
54
return lineMap.add(column, sourceLocation, options);
55
};
56
57
SourceMap.prototype.sourceLocation = function(arg) {
58
var column, line, lineMap;
59
line = arg[0], column = arg[1];
60
while (!((lineMap = this.lines[line]) || (line <= 0))) {
61
line--;
62
}
63
return lineMap && lineMap.sourceLocation(column);
64
};
65
66
SourceMap.prototype.generate = function(options, code) {
67
var buffer, i, j, lastColumn, lastSourceColumn, lastSourceLine, len, len1, lineMap, lineNumber, mapping, needComma, ref, ref1, v3, writingline;
68
if (options == null) {
69
options = {};
70
}
71
if (code == null) {
72
code = null;
73
}
74
writingline = 0;
75
lastColumn = 0;
76
lastSourceLine = 0;
77
lastSourceColumn = 0;
78
needComma = false;
79
buffer = "";
80
ref = this.lines;
81
for (lineNumber = i = 0, len = ref.length; i < len; lineNumber = ++i) {
82
lineMap = ref[lineNumber];
83
if (lineMap) {
84
ref1 = lineMap.columns;
85
for (j = 0, len1 = ref1.length; j < len1; j++) {
86
mapping = ref1[j];
87
if (!(mapping)) {
88
continue;
89
}
90
while (writingline < mapping.line) {
91
lastColumn = 0;
92
needComma = false;
93
buffer += ";";
94
writingline++;
95
}
96
if (needComma) {
97
buffer += ",";
98
needComma = false;
99
}
100
buffer += this.encodeVlq(mapping.column - lastColumn);
101
lastColumn = mapping.column;
102
buffer += this.encodeVlq(0);
103
buffer += this.encodeVlq(mapping.sourceLine - lastSourceLine);
104
lastSourceLine = mapping.sourceLine;
105
buffer += this.encodeVlq(mapping.sourceColumn - lastSourceColumn);
106
lastSourceColumn = mapping.sourceColumn;
107
needComma = true;
108
}
109
}
110
}
111
v3 = {
112
version: 3,
113
file: options.generatedFile || '',
114
sourceRoot: options.sourceRoot || '',
115
sources: options.sourceFiles || [''],
116
names: [],
117
mappings: buffer
118
};
119
if (options.inline) {
120
v3.sourcesContent = [code];
121
}
122
return JSON.stringify(v3, null, 2);
123
};
124
125
VLQ_SHIFT = 5;
126
127
VLQ_CONTINUATION_BIT = 1 << VLQ_SHIFT;
128
129
VLQ_VALUE_MASK = VLQ_CONTINUATION_BIT - 1;
130
131
SourceMap.prototype.encodeVlq = function(value) {
132
var answer, nextChunk, signBit, valueToEncode;
133
answer = '';
134
signBit = value < 0 ? 1 : 0;
135
valueToEncode = (Math.abs(value) << 1) + signBit;
136
while (valueToEncode || !answer) {
137
nextChunk = valueToEncode & VLQ_VALUE_MASK;
138
valueToEncode = valueToEncode >> VLQ_SHIFT;
139
if (valueToEncode) {
140
nextChunk |= VLQ_CONTINUATION_BIT;
141
}
142
answer += this.encodeBase64(nextChunk);
143
}
144
return answer;
145
};
146
147
BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
148
149
SourceMap.prototype.encodeBase64 = function(value) {
150
return BASE64_CHARS[value] || (function() {
151
throw new Error("Cannot Base64 encode value: " + value);
152
})();
153
};
154
155
return SourceMap;
156
157
})();
158
159
module.exports = SourceMap;
160
161
}).call(this);
162
163