mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
139 lines
4.2 KiB
JavaScript
139 lines
4.2 KiB
JavaScript
// Generated by CoffeeScript 1.4.0
|
|
(function() {
|
|
var BASE64_CHARS, LineMapping, MAX_BASE64_VALUE, VLQ_CONTINUATION_BIT, VLQ_MASK, VLQ_SHIFT, encodeBase64Char;
|
|
|
|
LineMapping = (function() {
|
|
|
|
function LineMapping(generatedLine) {
|
|
this.generatedLine = generatedLine;
|
|
this.columnMap = {};
|
|
this.columnMappings = [];
|
|
}
|
|
|
|
LineMapping.prototype.addMapping = function(generatedColumn, sourceLine, sourceColumn) {
|
|
if (this.columnMap[generatedColumn]) {
|
|
return;
|
|
}
|
|
this.columnMap[generatedColumn] = {
|
|
generatedLine: this.generatedLine,
|
|
generatedColumn: generatedColumn,
|
|
sourceLine: sourceLine,
|
|
sourceColumn: sourceColumn
|
|
};
|
|
return this.columnMappings.push(this.columnMap[generatedColumn]);
|
|
};
|
|
|
|
return LineMapping;
|
|
|
|
})();
|
|
|
|
exports.SourceMap = (function() {
|
|
|
|
function SourceMap() {
|
|
this.generatedLines = [];
|
|
}
|
|
|
|
SourceMap.prototype.addMapping = function(generatedLine, generatedColumn, sourceLine, sourceColumn) {
|
|
var lineArray;
|
|
lineArray = this.generatedLines[generatedLine];
|
|
if (!lineArray) {
|
|
lineArray = this.generatedLines[generatedLine] = LineMapping(generatedLine);
|
|
}
|
|
return lineArray.addMapping(generatedColumn, sourceLine, sourceColumn);
|
|
};
|
|
|
|
SourceMap.prototype.forEachMapping = function(fn) {
|
|
var columnMapping, generatedLineNumber, lineMapping, _i, _len, _ref, _results;
|
|
_ref = this.generatedLines;
|
|
_results = [];
|
|
for (generatedLineNumber = _i = 0, _len = _ref.length; _i < _len; generatedLineNumber = ++_i) {
|
|
lineMapping = _ref[generatedLineNumber];
|
|
if (lineMapping) {
|
|
_results.push((function() {
|
|
var _j, _len1, _ref1, _results1;
|
|
_ref1 = lineMapping.columnMappings;
|
|
_results1 = [];
|
|
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
|
columnMapping = _ref1[_j];
|
|
_results1.push(fn(columnMapping));
|
|
}
|
|
return _results1;
|
|
})());
|
|
} else {
|
|
_results.push(void 0);
|
|
}
|
|
}
|
|
return _results;
|
|
};
|
|
|
|
return SourceMap;
|
|
|
|
})();
|
|
|
|
exports.generateV3SourceMap = function(sourceMap) {
|
|
var lastGeneratedColumnWritten, lastSourceColumnWritten, lastSourceLineWritten, mappings, needComma, writingGeneratedLine;
|
|
writingGeneratedLine = 0;
|
|
lastGeneratedColumnWritten = 0;
|
|
lastSourceLineWritten = 0;
|
|
lastSourceColumnWritten = 0;
|
|
needComma = false;
|
|
mappings = "";
|
|
return sourceMap.forEachMapping(function(mapping) {
|
|
while (writingGeneratedLine < mapping.generatedLine) {
|
|
lastGeneratedColumnWritten = 0;
|
|
needComma = false;
|
|
mappings += ";";
|
|
writingGeneratedLine++;
|
|
}
|
|
if (needComma) {
|
|
mappings += ",";
|
|
needComma = false;
|
|
}
|
|
exports.vlqEncodeValue(mapping.generatedColumn - lastGeneratedColumnWritten);
|
|
lastGeneratedColumnWritten = mapping.generatedColumn;
|
|
exports.vlqEncodeValue(0);
|
|
exports.vlqEncodeValue(mapping.sourceLine - lastSourceLineWritten);
|
|
lastSourceLineWritten = mapping.sourceLine;
|
|
exports.vlqEncodeValue(mapping.sourceColumn - lastSourceColumnWritten);
|
|
lastSourceColumnWritten = mapping.sourceColumn;
|
|
return needComma = true;
|
|
});
|
|
};
|
|
|
|
BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
|
|
MAX_BASE64_VALUE = BASE64_CHARS.length - 1;
|
|
|
|
VLQ_SHIFT = 5;
|
|
|
|
VLQ_MASK = 0x1F;
|
|
|
|
VLQ_CONTINUATION_BIT = 0x20;
|
|
|
|
encodeBase64Char = function(value) {
|
|
if (value > MAX_BASE64_VALUE) {
|
|
throw Error("Cannot encode value " + value + " > " + MAX_BASE64_VALUE);
|
|
} else if (value < 0) {
|
|
throw Error("Cannot encode value " + value + " < 0");
|
|
}
|
|
return BASE64_CHARS[value];
|
|
};
|
|
|
|
exports.vlqEncodeValue = function(value) {
|
|
var answer, nextVlqChunk, _results;
|
|
value = value < 0 ? 1 : 0;
|
|
value += Math.abs(value) << 1;
|
|
answer = "";
|
|
_results = [];
|
|
while (value) {
|
|
nextVlqChunk = value & VLQ_MASK;
|
|
value >> VLQ_SHIFT;
|
|
if (value) {
|
|
nextVlqChunk |= VLQ_CONTINUATION_BIT;
|
|
}
|
|
_results.push(answer += encodeBase64Char(nextVlqChunk));
|
|
}
|
|
return _results;
|
|
};
|
|
|
|
}).call(this);
|