Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions lib/source-map/base64-vlq.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ define(function (require, exports, module) {

/**
* Decodes the next base 64 VLQ value from the given string and returns the
* value and the rest of the string.
* value and the rest of the string via the out parameter.
*/
exports.decode = function base64VLQ_decode(aStr) {
exports.decode = function base64VLQ_decode(aStr, aOutParam) {
var i = 0;
var strLen = aStr.length;
var result = 0;
Expand All @@ -135,10 +135,8 @@ define(function (require, exports, module) {
shift += VLQ_BASE_SHIFT;
} while (continuation);

return {
value: fromVLQSigned(result),
rest: aStr.slice(i)
};
aOutParam.value = fromVLQSigned(result);
aOutParam.rest = aStr.slice(i);
};

});
27 changes: 16 additions & 11 deletions lib/source-map/source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ define(function (require, exports, module) {
}
});

SourceMapConsumer.prototype._nextCharIsMappingSeparator =
function SourceMapConsumer_nextCharIsMappingSeparator(aStr) {
var c = aStr.charAt(0);
return c === ";" || c === ",";
};

/**
* Parse the mappings in a string in to a data structure which we can easily
* query (the ordered arrays in the `this.__generatedMappings` and
Expand All @@ -190,10 +196,9 @@ define(function (require, exports, module) {
var previousOriginalColumn = 0;
var previousSource = 0;
var previousName = 0;
var mappingSeparator = /^[,;]/;
var str = aStr;
var temp = {};
var mapping;
var temp;

while (str.length > 0) {
if (str.charAt(0) === ';') {
Expand All @@ -209,41 +214,41 @@ define(function (require, exports, module) {
mapping.generatedLine = generatedLine;

// Generated column.
temp = base64VLQ.decode(str);
base64VLQ.decode(str, temp);
mapping.generatedColumn = previousGeneratedColumn + temp.value;
previousGeneratedColumn = mapping.generatedColumn;
str = temp.rest;

if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
if (str.length > 0 && !this._nextCharIsMappingSeparator(str)) {
// Original source.
temp = base64VLQ.decode(str);
base64VLQ.decode(str, temp);
mapping.source = this._sources.at(previousSource + temp.value);
previousSource += temp.value;
str = temp.rest;
if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
if (str.length === 0 || this._nextCharIsMappingSeparator(str)) {
throw new Error('Found a source, but no line and column');
}

// Original line.
temp = base64VLQ.decode(str);
base64VLQ.decode(str, temp);
mapping.originalLine = previousOriginalLine + temp.value;
previousOriginalLine = mapping.originalLine;
// Lines are stored 0-based
mapping.originalLine += 1;
str = temp.rest;
if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
if (str.length === 0 || this._nextCharIsMappingSeparator(str)) {
throw new Error('Found a source and line, but no column');
}

// Original column.
temp = base64VLQ.decode(str);
base64VLQ.decode(str, temp);
mapping.originalColumn = previousOriginalColumn + temp.value;
previousOriginalColumn = mapping.originalColumn;
str = temp.rest;

if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
if (str.length > 0 && !this._nextCharIsMappingSeparator(str)) {
// Original name.
temp = base64VLQ.decode(str);
base64VLQ.decode(str, temp);
mapping.name = this._names.at(previousName + temp.value);
previousName += temp.value;
str = temp.rest;
Expand Down
5 changes: 2 additions & 3 deletions test/source-map/test-base64-vlq.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ define(function (require, exports, module) {
var base64VLQ = require('../../lib/source-map/base64-vlq');

exports['test normal encoding and decoding'] = function (assert, util) {
var result;
var result = {};
for (var i = -255; i < 256; i++) {
result = base64VLQ.decode(base64VLQ.encode(i));
assert.ok(result);
base64VLQ.decode(base64VLQ.encode(i), result);
assert.equal(result.value, i);
assert.equal(result.rest, "");
}
Expand Down