each: (iterator) ->
- for lineMap, lineNumber in @lines when lineMap
- for mapping in lineMap.columns when mapping
- iterator mapping
diff --git a/documentation/docs/sourcemap.html b/documentation/docs/sourcemap.html index 98f826fe..97420185 100644 --- a/documentation/docs/sourcemap.html +++ b/documentation/docs/sourcemap.html @@ -247,33 +247,10 @@ code.
func
will be called once for every recorded mapping, in the order in
-which they occur in the generated source. fn
will be passed an object
-with four properties: sourceLine, sourceColumn, line, and
-column.
-
-
each: (iterator) ->
- for lineMap, lineNumber in @lines when lineMap
- for mapping in lineMap.columns when mapping
- iterator mapping
Builds up a V3 source map, returning the generated JSON as a string.
options.sourceRoot
may be used to specify the sourceRoot written to the source
@@ -305,12 +282,32 @@ set "sources" and "file", respectively.
needComma = no
buffer = ""
- @each (mapping) =>
- while writingline < mapping.line
- lastColumn = 0
- needComma = no
- buffer += ";"
- writingline++
Write a comma if we've already written a segment on this line. + +
+ + if needComma
+ buffer += ","
+ needComma = no
Write a comma if we've already written a segment on this line. - -
- - - - if needComma
- buffer += ","
- needComma = no
Write the next segment. Segments can be 1, 4, or 5 values. If just one, then it is a generated column which doesn't match anything in the source code. @@ -351,8 +329,25 @@ column for the current line:
buffer += @encodeVlq mapping.column - lastColumn
- lastColumn = mapping.column
buffer += @encodeVlq mapping.column - lastColumn
+ lastColumn = mapping.column
The index into the list of sources: + +
+ + buffer += @encodeVlq 0
The index into the list of sources: +
The starting line in the original source, relative to the previous source line.
- buffer += @encodeVlq 0
buffer += @encodeVlq mapping.sourceLine - lastSourceLine
+ if lastSourceLine isnt mapping.sourceLine
+ lastSourceLine = mapping.sourceLine
+ lastSourceColumn = 0
The starting line in the original source, relative to the previous source line. +
The starting column in the original source, relative to the previous column.
- buffer += @encodeVlq mapping.sourceLine - lastSourceLine
- if lastSourceLine isnt mapping.sourceLine
- lastSourceLine = mapping.sourceLine
- lastSourceColumn = 0
buffer += @encodeVlq mapping.sourceColumn - lastSourceColumn
+ lastSourceColumn = mapping.sourceColumn
+ needComma = yes
The starting column in the original source, relative to the previous column. - -
- - - - buffer += @encodeVlq mapping.sourceColumn - lastSourceColumn
- lastSourceColumn = mapping.sourceColumn
- needComma = yes
Produce the canonical JSON object format for a "v3" source map.
@@ -435,16 +413,16 @@ column for the current line: v3.sourcesContent = [code] if options.inline - return JSON.stringify v3, null, 2Note that SourceMap VLQ encoding is "backwards". MIDI-style VLQ encoding puts the most-significant-bit (MSB) from the original value into the MSB of the VLQ @@ -479,11 +457,11 @@ bits of the original value encoded into the first byte of the VLQ encoded value. -
Least significant bit represents the sign.
@@ -495,11 +473,11 @@ bits of the original value encoded into the first byte of the VLQ encoded value. -The next bits are the actual value.
@@ -511,11 +489,11 @@ bits of the original value encoded into the first byte of the VLQ encoded value. -Our API for source maps is just the SourceMap
class.
diff --git a/lib/coffee-script/sourcemap.js b/lib/coffee-script/sourcemap.js
index c2a0c72e..4775ce68 100644
--- a/lib/coffee-script/sourcemap.js
+++ b/lib/coffee-script/sourcemap.js
@@ -65,33 +65,8 @@
return lineMap && lineMap.sourceLocation(column);
};
- SourceMap.prototype.each = function(iterator) {
- var lineMap, lineNumber, mapping, _i, _len, _ref, _results;
- _ref = this.lines;
- _results = [];
- for (lineNumber = _i = 0, _len = _ref.length; _i < _len; lineNumber = ++_i) {
- lineMap = _ref[lineNumber];
- if (lineMap) {
- _results.push((function() {
- var _j, _len1, _ref1, _results1;
- _ref1 = lineMap.columns;
- _results1 = [];
- for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
- mapping = _ref1[_j];
- if (mapping) {
- _results1.push(iterator(mapping));
- }
- }
- return _results1;
- })());
- }
- }
- return _results;
- };
-
SourceMap.prototype.generate = function(options, code) {
- var buffer, lastColumn, lastSourceColumn, lastSourceLine, needComma, v3, writingline,
- _this = this;
+ var buffer, lastColumn, lastSourceColumn, lastSourceLine, lineMap, lineNumber, mapping, needComma, v3, writingline, _i, _j, _len, _len1, _ref, _ref1;
if (options == null) {
options = {};
}
@@ -104,29 +79,40 @@
lastSourceColumn = 0;
needComma = false;
buffer = "";
- this.each(function(mapping) {
- while (writingline < mapping.line) {
- lastColumn = 0;
- needComma = false;
- buffer += ";";
- writingline++;
+ _ref = this.lines;
+ for (lineNumber = _i = 0, _len = _ref.length; _i < _len; lineNumber = ++_i) {
+ lineMap = _ref[lineNumber];
+ if (lineMap) {
+ _ref1 = lineMap.columns;
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
+ mapping = _ref1[_j];
+ if (!(mapping)) {
+ continue;
+ }
+ while (writingline < mapping.line) {
+ lastColumn = 0;
+ needComma = false;
+ buffer += ";";
+ writingline++;
+ }
+ if (needComma) {
+ buffer += ",";
+ needComma = false;
+ }
+ buffer += this.encodeVlq(mapping.column - lastColumn);
+ lastColumn = mapping.column;
+ buffer += this.encodeVlq(0);
+ buffer += this.encodeVlq(mapping.sourceLine - lastSourceLine);
+ if (lastSourceLine !== mapping.sourceLine) {
+ lastSourceLine = mapping.sourceLine;
+ lastSourceColumn = 0;
+ }
+ buffer += this.encodeVlq(mapping.sourceColumn - lastSourceColumn);
+ lastSourceColumn = mapping.sourceColumn;
+ needComma = true;
+ }
}
- if (needComma) {
- buffer += ",";
- needComma = false;
- }
- buffer += _this.encodeVlq(mapping.column - lastColumn);
- lastColumn = mapping.column;
- buffer += _this.encodeVlq(0);
- buffer += _this.encodeVlq(mapping.sourceLine - lastSourceLine);
- if (lastSourceLine !== mapping.sourceLine) {
- lastSourceLine = mapping.sourceLine;
- lastSourceColumn = 0;
- }
- buffer += _this.encodeVlq(mapping.sourceColumn - lastSourceColumn);
- lastSourceColumn = mapping.sourceColumn;
- return needComma = true;
- });
+ }
v3 = {
version: 3,
file: options.generatedFile || '',
diff --git a/src/sourcemap.litcoffee b/src/sourcemap.litcoffee
index 26cb584f..3981f70e 100644
--- a/src/sourcemap.litcoffee
+++ b/src/sourcemap.litcoffee
@@ -58,16 +58,6 @@ code.
line-- until (lineMap = @lines[line]) or (line <= 0)
lineMap and lineMap.sourceLocation column
-`func` will be called once for every recorded mapping, in the order in
-which they occur in the generated source. `fn` will be passed an object
-with four properties: sourceLine, sourceColumn, line, and
-column.
-
- each: (iterator) ->
- for lineMap, lineNumber in @lines when lineMap
- for mapping in lineMap.columns when mapping
- iterator mapping
-
V3 SourceMap Generation
-----------------------
@@ -85,18 +75,19 @@ set "sources" and "file", respectively.
needComma = no
buffer = ""
- @each (mapping) =>
- while writingline < mapping.line
- lastColumn = 0
- needComma = no
- buffer += ";"
- writingline++
+ for lineMap, lineNumber in @lines when lineMap
+ for mapping in lineMap.columns when mapping
+ while writingline < mapping.line
+ lastColumn = 0
+ needComma = no
+ buffer += ";"
+ writingline++
Write a comma if we've already written a segment on this line.
- if needComma
- buffer += ","
- needComma = no
+ if needComma
+ buffer += ","
+ needComma = no
Write the next segment. Segments can be 1, 4, or 5 values. If just one, then it
is a generated column which doesn't match anything in the source code.
@@ -104,25 +95,25 @@ is a generated column which doesn't match anything in the source code.
The starting column in the generated source, relative to any previous recorded
column for the current line:
- buffer += @encodeVlq mapping.column - lastColumn
- lastColumn = mapping.column
+ buffer += @encodeVlq mapping.column - lastColumn
+ lastColumn = mapping.column
The index into the list of sources:
- buffer += @encodeVlq 0
+ buffer += @encodeVlq 0
The starting line in the original source, relative to the previous source line.
- buffer += @encodeVlq mapping.sourceLine - lastSourceLine
- if lastSourceLine isnt mapping.sourceLine
- lastSourceLine = mapping.sourceLine
- lastSourceColumn = 0
+ buffer += @encodeVlq mapping.sourceLine - lastSourceLine
+ if lastSourceLine isnt mapping.sourceLine
+ lastSourceLine = mapping.sourceLine
+ lastSourceColumn = 0
The starting column in the original source, relative to the previous column.
- buffer += @encodeVlq mapping.sourceColumn - lastSourceColumn
- lastSourceColumn = mapping.sourceColumn
- needComma = yes
+ buffer += @encodeVlq mapping.sourceColumn - lastSourceColumn
+ lastSourceColumn = mapping.sourceColumn
+ needComma = yes
Produce the canonical JSON object format for a "v3" source map.
@@ -136,7 +127,7 @@ Produce the canonical JSON object format for a "v3" source map.
v3.sourcesContent = [code] if options.inline
- return JSON.stringify v3, null, 2
+ JSON.stringify v3, null, 2
Base64 VLQ Encoding
@@ -168,7 +159,7 @@ bits of the original value encoded into the first byte of the VLQ encoded value.
nextChunk |= VLQ_CONTINUATION_BIT if valueToEncode
answer += @encodeBase64 nextChunk
- return answer
+ answer
Regular Base64 Encoding