Date:  12 Dec 2015 04:27:18 Hong Kong Time

Starting index of line numbers differs from the spec?



I'm trying to polish up the source map implementation for Sprockets 4 ( I was reading through the version 3 proposal and using the  mozilla library source-map when I found something slightly contradictory.

In it sounds like line numbers and column numbers should be zero indexed however in all the implementations i've been able to find such as `source-map` i'm seeing that lines are 1 indexed and columns are zero indexed.

For example:

$ cat foo.js
var foo = "foo";
var bar = "bar";

$ uglifyjs foo.js --source-map
var foo="foo";var bar="bar";

$ cat

I can parse this source map with mozilla's module using this code:

var sourceMap = require('source-map');
var fs        = require('fs');

fs.readFile('./', 'utf8', function (err, data) {
  if (err) {
    return console.log(err);
  var smc = new sourceMap.SourceMapConsumer(data);

  smc.eachMapping(function(m) {

For the `foo` variable I get this result:

{ source: 'foo.js',
  generatedLine: 1,
  generatedColumn: 3,
  originalLine: 1,
  originalColumn: 4,
  name: 'foo' }

I would have expected based on the google doc that `generatedLine` should be 0 and not 1, while the `generatedColumn` matches my expectations. From the doc

> If present, the zero-based starting line in the original source represented. This field is a base 64 VLQ relative to the previous occurrence of this field, unless this is the first occurrence of this field, in which case the whole value is represented. Always present if there is a source field.

All the implementations I've found start line numbers at 1. Am I reading the doc incorrectly or did I miss something?