Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix off-by-one error

Lines should be stored 0-based according to the current version of the
spec:

https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit,
  • Loading branch information...
commit 539a0b8ce5993d615944942e821674fe477758f9 1 parent 3f6cbbd
@ConradIrwin authored
View
2  lib/source-map/source-map-consumer.js
@@ -119,6 +119,8 @@ define(function (require, exports, module) {
temp = base64VLQ.decode(str);
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))) {
throw new Error('Found a source and line, but no column');
View
5 lib/source-map/source-map-generator.js
@@ -148,9 +148,10 @@ define(function (require, exports, module) {
- previousSource);
previousSource = this._sources.indexOf(mapping.source);
- result += base64VLQ.encode(mapping.original.line
+ // lines are stored 0-based in SourceMap spec version 3
+ result += base64VLQ.encode(mapping.original.line - 1
- previousOriginalLine);
- previousOriginalLine = mapping.original.line;
+ previousOriginalLine = mapping.original.line - 1;
result += base64VLQ.encode(mapping.original.column
- previousOriginalColumn);
View
2  test/test-source-map-generator.js
@@ -197,7 +197,7 @@ define(function (require, exports, module) {
assert.deepEqual(map.names, ['bar', 'baz', 'n']);
assert.deepEqual(map.sources, ['one.js', 'two.js']);
assert.equal(map.sourceRoot, '/the/root');
- assert.equal(map.mappings, 'CACC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA');
+ assert.equal(map.mappings, 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA');
};
});
View
2  test/util.js
@@ -63,7 +63,7 @@ define(function (require, exports, module) {
names: ['bar', 'baz', 'n'],
sources: ['one.js', 'two.js'],
sourceRoot: '/the/root',
- mappings: 'CACC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA'
+ mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA'
};
function assertMapping(generatedLine, generatedColumn, originalSource,
Please sign in to comment.
Something went wrong with that request. Please try again.