Skip to content

Commit 71dfd60

Browse files
authored
Merge pull request mozilla#277 from tromey/document-offsets
Update documentation to note basis of lines and columns
2 parents d730e6b + 0ef74c3 commit 71dfd60

13 files changed

+748
-188
lines changed

README.md

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,13 @@ Returns the original source, line, and column information for the generated
248248
source's line and column positions provided. The only argument is an object with
249249
the following properties:
250250

251-
* `line`: The line number in the generated source.
251+
* `line`: The line number in the generated source. Line numbers in
252+
this library are 1-based (note that the underlying source map
253+
specification uses 0-based line numbers -- this library handles the
254+
translation).
252255

253-
* `column`: The column number in the generated source.
256+
* `column`: The column number in the generated source. Column numbers
257+
in this library are 0-based.
254258

255259
* `bias`: Either `SourceMapConsumer.GREATEST_LOWER_BOUND` or
256260
`SourceMapConsumer.LEAST_UPPER_BOUND`. Specifies whether to return the closest
@@ -264,10 +268,10 @@ and an object is returned with the following properties:
264268
available.
265269

266270
* `line`: The line number in the original source, or null if this information is
267-
not available.
271+
not available. The line number is 1-based.
268272

269273
* `column`: The column number in the original source, or null if this
270-
information is not available.
274+
information is not available. The column number is 0-based.
271275

272276
* `name`: The original identifier, or null if this information is not available.
273277

@@ -293,15 +297,19 @@ the following properties:
293297

294298
* `source`: The filename of the original source.
295299

296-
* `line`: The line number in the original source.
300+
* `line`: The line number in the original source. The line number is
301+
1-based.
297302

298-
* `column`: The column number in the original source.
303+
* `column`: The column number in the original source. The column
304+
number is 0-based.
299305

300306
and an object is returned with the following properties:
301307

302-
* `line`: The line number in the generated source, or null.
308+
* `line`: The line number in the generated source, or null. The line
309+
number is 1-based.
303310

304-
* `column`: The column number in the generated source, or null.
311+
* `column`: The column number in the generated source, or null. The
312+
column number is 0-based.
305313

306314
```js
307315
consumer.generatedPositionFor({ source: "example.js", line: 2, column: 10 })
@@ -322,15 +330,19 @@ The only argument is an object with the following properties:
322330

323331
* `source`: The filename of the original source.
324332

325-
* `line`: The line number in the original source.
333+
* `line`: The line number in the original source. The line number is
334+
1-based.
326335

327-
* `column`: Optional. The column number in the original source.
336+
* `column`: Optional. The column number in the original source. The
337+
column number is 0-based.
328338

329339
and an array of objects is returned, each with the following properties:
330340

331-
* `line`: The line number in the generated source, or null.
341+
* `line`: The line number in the generated source, or null. The line
342+
number is 1-based.
332343

333-
* `column`: The column number in the generated source, or null.
344+
* `column`: The column number in the generated source, or null. The
345+
column number is 0-based.
334346

335347
```js
336348
consumer.allGeneratedpositionsfor({ line: 2, source: "foo.coffee" })
@@ -534,10 +546,11 @@ use before outputting the generated JS and source map.
534546
#### new SourceNode([line, column, source[, chunk[, name]]])
535547

536548
* `line`: The original line number associated with this source node, or null if
537-
it isn't associated with an original line.
549+
it isn't associated with an original line. The line number is 1-based.
538550

539551
* `column`: The original column number associated with this source node, or null
540-
if it isn't associated with an original column.
552+
if it isn't associated with an original column. The column number
553+
is 0-based.
541554

542555
* `source`: The original source's filename; null if no filename is provided.
543556

dist/source-map.debug.js

Lines changed: 61 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/source-map.js

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@ return /******/ (function(modules) { // webpackBootstrap
142142
generator.addMapping(newMapping);
143143
});
144144
aSourceMapConsumer.sources.forEach(function (sourceFile) {
145+
var sourceRelative = sourceFile;
146+
if (sourceRoot !== null) {
147+
sourceRelative = util.relative(sourceRoot, sourceFile);
148+
}
149+
150+
if (!generator._sources.has(sourceRelative)) {
151+
generator._sources.add(sourceRelative);
152+
}
153+
145154
var content = aSourceMapConsumer.sourceContentFor(sourceFile);
146155
if (content != null) {
147156
generator.setSourceContent(sourceFile, content);
@@ -1013,7 +1022,7 @@ return /******/ (function(modules) { // webpackBootstrap
10131022
* stubbed out mapping.
10141023
*/
10151024
function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
1016-
var cmp = mappingA.source - mappingB.source;
1025+
var cmp = strcmp(mappingA.source, mappingB.source);
10171026
if (cmp !== 0) {
10181027
return cmp;
10191028
}
@@ -1038,7 +1047,7 @@ return /******/ (function(modules) { // webpackBootstrap
10381047
return cmp;
10391048
}
10401049

1041-
return mappingA.name - mappingB.name;
1050+
return strcmp(mappingA.name, mappingB.name);
10421051
}
10431052
exports.compareByOriginalPositions = compareByOriginalPositions;
10441053

@@ -1062,7 +1071,7 @@ return /******/ (function(modules) { // webpackBootstrap
10621071
return cmp;
10631072
}
10641073

1065-
cmp = mappingA.source - mappingB.source;
1074+
cmp = strcmp(mappingA.source, mappingB.source);
10661075
if (cmp !== 0) {
10671076
return cmp;
10681077
}
@@ -1077,7 +1086,7 @@ return /******/ (function(modules) { // webpackBootstrap
10771086
return cmp;
10781087
}
10791088

1080-
return mappingA.name - mappingB.name;
1089+
return strcmp(mappingA.name, mappingB.name);
10811090
}
10821091
exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
10831092

@@ -1086,6 +1095,14 @@ return /******/ (function(modules) { // webpackBootstrap
10861095
return 0;
10871096
}
10881097

1098+
if (aStr1 === null) {
1099+
return 1; // aStr2 !== null
1100+
}
1101+
1102+
if (aStr2 === null) {
1103+
return -1; // aStr1 !== null
1104+
}
1105+
10891106
if (aStr1 > aStr2) {
10901107
return 1;
10911108
}
@@ -1409,6 +1426,8 @@ return /******/ (function(modules) { // webpackBootstrap
14091426

14101427
SourceMapConsumer.prototype.__generatedMappings = null;
14111428
Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
1429+
configurable: true,
1430+
enumerable: true,
14121431
get: function () {
14131432
if (!this.__generatedMappings) {
14141433
this._parseMappings(this._mappings, this.sourceRoot);
@@ -1420,6 +1439,8 @@ return /******/ (function(modules) { // webpackBootstrap
14201439

14211440
SourceMapConsumer.prototype.__originalMappings = null;
14221441
Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
1442+
configurable: true,
1443+
enumerable: true,
14231444
get: function () {
14241445
if (!this.__originalMappings) {
14251446
this._parseMappings(this._mappings, this.sourceRoot);
@@ -1512,13 +1533,16 @@ return /******/ (function(modules) { // webpackBootstrap
15121533
* The only argument is an object with the following properties:
15131534
*
15141535
* - source: The filename of the original source.
1515-
* - line: The line number in the original source.
1536+
* - line: The line number in the original source. The line number is 1-based.
15161537
* - column: Optional. the column number in the original source.
1538+
* The column number is 0-based.
15171539
*
15181540
* and an array of objects is returned, each with the following properties:
15191541
*
1520-
* - line: The line number in the generated source, or null.
1542+
* - line: The line number in the generated source, or null. The
1543+
* line number is 1-based.
15211544
* - column: The column number in the generated source, or null.
1545+
* The column number is 0-based.
15221546
*/
15231547
SourceMapConsumer.prototype.allGeneratedPositionsFor =
15241548
function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {
@@ -1925,8 +1949,10 @@ return /******/ (function(modules) { // webpackBootstrap
19251949
* source's line and column positions provided. The only argument is an object
19261950
* with the following properties:
19271951
*
1928-
* - line: The line number in the generated source.
1929-
* - column: The column number in the generated source.
1952+
* - line: The line number in the generated source. The line number
1953+
* is 1-based.
1954+
* - column: The column number in the generated source. The column
1955+
* number is 0-based.
19301956
* - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
19311957
* 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
19321958
* closest element that is smaller than or greater than the one we are
@@ -1936,8 +1962,10 @@ return /******/ (function(modules) { // webpackBootstrap
19361962
* and an object is returned with the following properties:
19371963
*
19381964
* - source: The original source file, or null.
1939-
* - line: The line number in the original source, or null.
1940-
* - column: The column number in the original source, or null.
1965+
* - line: The line number in the original source, or null. The
1966+
* line number is 1-based.
1967+
* - column: The column number in the original source, or null. The
1968+
* column number is 0-based.
19411969
* - name: The original identifier, or null.
19421970
*/
19431971
BasicSourceMapConsumer.prototype.originalPositionFor =
@@ -2057,8 +2085,10 @@ return /******/ (function(modules) { // webpackBootstrap
20572085
* the following properties:
20582086
*
20592087
* - source: The filename of the original source.
2060-
* - line: The line number in the original source.
2061-
* - column: The column number in the original source.
2088+
* - line: The line number in the original source. The line number
2089+
* is 1-based.
2090+
* - column: The column number in the original source. The column
2091+
* number is 0-based.
20622092
* - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
20632093
* 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
20642094
* closest element that is smaller than or greater than the one we are
@@ -2067,8 +2097,10 @@ return /******/ (function(modules) { // webpackBootstrap
20672097
*
20682098
* and an object is returned with the following properties:
20692099
*
2070-
* - line: The line number in the generated source, or null.
2100+
* - line: The line number in the generated source, or null. The
2101+
* line number is 1-based.
20712102
* - column: The column number in the generated source, or null.
2103+
* The column number is 0-based.
20722104
*/
20732105
BasicSourceMapConsumer.prototype.generatedPositionFor =
20742106
function SourceMapConsumer_generatedPositionFor(aArgs) {
@@ -2242,14 +2274,18 @@ return /******/ (function(modules) { // webpackBootstrap
22422274
* source's line and column positions provided. The only argument is an object
22432275
* with the following properties:
22442276
*
2245-
* - line: The line number in the generated source.
2246-
* - column: The column number in the generated source.
2277+
* - line: The line number in the generated source. The line number
2278+
* is 1-based.
2279+
* - column: The column number in the generated source. The column
2280+
* number is 0-based.
22472281
*
22482282
* and an object is returned with the following properties:
22492283
*
22502284
* - source: The original source file, or null.
2251-
* - line: The line number in the original source, or null.
2252-
* - column: The column number in the original source, or null.
2285+
* - line: The line number in the original source, or null. The
2286+
* line number is 1-based.
2287+
* - column: The column number in the original source, or null. The
2288+
* column number is 0-based.
22532289
* - name: The original identifier, or null.
22542290
*/
22552291
IndexedSourceMapConsumer.prototype.originalPositionFor =
@@ -2333,13 +2369,17 @@ return /******/ (function(modules) { // webpackBootstrap
23332369
* the following properties:
23342370
*
23352371
* - source: The filename of the original source.
2336-
* - line: The line number in the original source.
2337-
* - column: The column number in the original source.
2372+
* - line: The line number in the original source. The line number
2373+
* is 1-based.
2374+
* - column: The column number in the original source. The column
2375+
* number is 0-based.
23382376
*
23392377
* and an object is returned with the following properties:
23402378
*
2341-
* - line: The line number in the generated source, or null.
2379+
* - line: The line number in the generated source, or null. The
2380+
* line number is 1-based.
23422381
* - column: The column number in the generated source, or null.
2382+
* The column number is 0-based.
23432383
*/
23442384
IndexedSourceMapConsumer.prototype.generatedPositionFor =
23452385
function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {

dist/source-map.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/source-map.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)