mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-01-14 09:17:55 -05:00
Any variables generated by CoffeeScript are now made sure to be named to something not present in the source code being compiled. This way you can no longer interfere with them, either on purpose or by mistake. (#1500, #1574) For example, `({a}, _arg) ->` now compiles correctly. (#1574) As opposed to the somewhat complex implementations discussed in #1500, this commit takes a very simple approach by saving all used variables names using a single pass over the token stream. Any generated variables are then made sure not to exist in that list. `(@a) -> a` used to be equivalent to `(@a) -> @a`, but now throws a runtime `ReferenceError` instead (unless `a` exists in an upper scope of course). (#3318) `(@a) ->` used to compile to `(function(a) { this.a = a; })`. Now it compiles to `(function(_at_a) { this.a = _at_a; })`. (But you cannot access `_at_a` either, of course.) Because of the above, `(@a, a) ->` is now valid; `@a` and `a` are not duplicate parameters. Duplicate this-parameters with a reserved word, such as `(@case, @case) ->`, used to compile but now throws, just like regular duplicate parameters.
162 lines
4.6 KiB
JavaScript
162 lines
4.6 KiB
JavaScript
// Generated by CoffeeScript 1.8.0
|
|
(function() {
|
|
var LineMap, SourceMap;
|
|
|
|
LineMap = (function() {
|
|
function LineMap(_at_line) {
|
|
this.line = _at_line;
|
|
this.columns = [];
|
|
}
|
|
|
|
LineMap.prototype.add = function(column, _arg, options) {
|
|
var sourceColumn, sourceLine;
|
|
sourceLine = _arg[0], sourceColumn = _arg[1];
|
|
if (options == null) {
|
|
options = {};
|
|
}
|
|
if (this.columns[column] && options.noReplace) {
|
|
return;
|
|
}
|
|
return this.columns[column] = {
|
|
line: this.line,
|
|
column: column,
|
|
sourceLine: sourceLine,
|
|
sourceColumn: sourceColumn
|
|
};
|
|
};
|
|
|
|
LineMap.prototype.sourceLocation = function(column) {
|
|
var mapping;
|
|
while (!((mapping = this.columns[column]) || (column <= 0))) {
|
|
column--;
|
|
}
|
|
return mapping && [mapping.sourceLine, mapping.sourceColumn];
|
|
};
|
|
|
|
return LineMap;
|
|
|
|
})();
|
|
|
|
SourceMap = (function() {
|
|
var BASE64_CHARS, VLQ_CONTINUATION_BIT, VLQ_SHIFT, VLQ_VALUE_MASK;
|
|
|
|
function SourceMap() {
|
|
this.lines = [];
|
|
}
|
|
|
|
SourceMap.prototype.add = function(sourceLocation, generatedLocation, options) {
|
|
var column, line, lineMap, _base;
|
|
if (options == null) {
|
|
options = {};
|
|
}
|
|
line = generatedLocation[0], column = generatedLocation[1];
|
|
lineMap = ((_base = this.lines)[line] || (_base[line] = new LineMap(line)));
|
|
return lineMap.add(column, sourceLocation, options);
|
|
};
|
|
|
|
SourceMap.prototype.sourceLocation = function(_arg) {
|
|
var column, line, lineMap;
|
|
line = _arg[0], column = _arg[1];
|
|
while (!((lineMap = this.lines[line]) || (line <= 0))) {
|
|
line--;
|
|
}
|
|
return lineMap && lineMap.sourceLocation(column);
|
|
};
|
|
|
|
SourceMap.prototype.generate = function(options, code) {
|
|
var buffer, lastColumn, lastSourceColumn, lastSourceLine, lineMap, lineNumber, mapping, needComma, v3, writingline, _i, _j, _len, _len1, _ref, _ref1;
|
|
if (options == null) {
|
|
options = {};
|
|
}
|
|
if (code == null) {
|
|
code = null;
|
|
}
|
|
writingline = 0;
|
|
lastColumn = 0;
|
|
lastSourceLine = 0;
|
|
lastSourceColumn = 0;
|
|
needComma = false;
|
|
buffer = "";
|
|
_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);
|
|
lastSourceLine = mapping.sourceLine;
|
|
buffer += this.encodeVlq(mapping.sourceColumn - lastSourceColumn);
|
|
lastSourceColumn = mapping.sourceColumn;
|
|
needComma = true;
|
|
}
|
|
}
|
|
}
|
|
v3 = {
|
|
version: 3,
|
|
file: options.generatedFile || '',
|
|
sourceRoot: options.sourceRoot || '',
|
|
sources: options.sourceFiles || [''],
|
|
names: [],
|
|
mappings: buffer
|
|
};
|
|
if (options.inline) {
|
|
v3.sourcesContent = [code];
|
|
}
|
|
return JSON.stringify(v3, null, 2);
|
|
};
|
|
|
|
VLQ_SHIFT = 5;
|
|
|
|
VLQ_CONTINUATION_BIT = 1 << VLQ_SHIFT;
|
|
|
|
VLQ_VALUE_MASK = VLQ_CONTINUATION_BIT - 1;
|
|
|
|
SourceMap.prototype.encodeVlq = function(value) {
|
|
var answer, nextChunk, signBit, valueToEncode;
|
|
answer = '';
|
|
signBit = value < 0 ? 1 : 0;
|
|
valueToEncode = (Math.abs(value) << 1) + signBit;
|
|
while (valueToEncode || !answer) {
|
|
nextChunk = valueToEncode & VLQ_VALUE_MASK;
|
|
valueToEncode = valueToEncode >> VLQ_SHIFT;
|
|
if (valueToEncode) {
|
|
nextChunk |= VLQ_CONTINUATION_BIT;
|
|
}
|
|
answer += this.encodeBase64(nextChunk);
|
|
}
|
|
return answer;
|
|
};
|
|
|
|
BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
|
|
SourceMap.prototype.encodeBase64 = function(value) {
|
|
return BASE64_CHARS[value] || (function() {
|
|
throw new Error("Cannot Base64 encode value: " + value);
|
|
})();
|
|
};
|
|
|
|
return SourceMap;
|
|
|
|
})();
|
|
|
|
module.exports = SourceMap;
|
|
|
|
}).call(this);
|