mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-01-14 09:17:55 -05:00
* Eliminate wrapper around “bound” (arrow) functions; output `=>` for such functions * Remove irrelevant (and breaking) tests * Minor cleanup * When a function parameter is a splat (i.e., it uses the ES2015 rest parameter syntax) output that parameter as ES2015 * Rearrange function parameters when one of the parameters is a splat and isn’t the last parameter (very WIP) * Handle params like `@param`, adding assignment expressions for them when they appear; ensure splat parameter is last * Add parameter names (not a text like `'\nValue IdentifierLiteral: a'`) to the scope, so that parameters can’t be deleted; move body-related lines together; more explanation of what’s going on * For parameters with a default value, correctly add the parameter name to the function scope * Handle expansions in function parameters: when an expansion is found, set the parameters to only be the original parameters left of the expansion, then an `...args` parameter; and in the function body define variables for the parameters to the right of the expansion, including setting default values * Handle splat parameters the same way we handle expansions: if a splat parameter is found, it becomes the last parameter in the function definition, and all following parameters get declared in the function body. Fix the splat/rest parameter values after the post-splat parameters have been extracted from it. Clean up `Code.compileNode` so that we loop through the parameters only once, and we create all expressions using calls like `new IdentifierLiteral` rather than `@makeCode`. * Fix parameter name when a parameter is a splat attached to `this` (e.g. `@param...`) * Rather than assigning post-splat parameters based on index, use slice; passes test “Functions with splats being called with too few arguments” * Dial back our w00t indentation * Better parsing of parameter names (WIP) * Refactor processing of splat/expansion parameters * Fix assignment of default parameters for parameters that come after a splat * Better check for whether a param is attached to `this` * More understandable variable names * For parameters after a splat or expansion, assign them similar to the 1.x destructuring method of using `arguments`, except only concern ourselves with the post-splat parameters instead of all parameters; and use the splat/expansion parameter name, since `arguments` in ES fat arrow functions refers to the parent function’s `arguments` rather than the fat arrow function’s arguments/parameters * Don’t add unnamed parameters (like `[]` as a parameter) to the function scope * Disallow multiple splat/expansion parameters in function definitions; disallow lone expansion parameters * Fix `this` params not getting assigned if the parameter is after a splat parameter * Allow names of function parameters attached to `this` to be reserved words * Always add a statement to the function body defining a variable with its default value, if it has one, if the variable `== null`; this covers the case when ES doesn’t apply the default value when `null` is passed in as a value, but CoffeeScript expects `null` and `undefined` to act interchangeably * Aftermath of having both `undefined` and `null` trigger the use of default values for parameters with default values * More careful parsing of destructured parameters * Fall back to processing destructured parameters in the function body, to account for `this` or default values within destructured objects * Clean up comments * Restore new bare function test, minus the arrow function part of it * Test that bound/arrow functions aren’t overwriting the `arguments` object, which should refer to the parent scope’s `arguments` (like `this`) * Follow ES2015 spec for parameter default values: `null` gets assigned as as `null`, not the default value * Mimic ES default parameters behavior for parameters after a splat or expansion parameter * Bound functions cannot be generators: remove no-longer-relevant test, add check to throw error if `yield` appears inside a bound (arrow) function * Error for bound generator functions should underline the `yield`
150 lines
4.3 KiB
JavaScript
150 lines
4.3 KiB
JavaScript
// Generated by CoffeeScript 2.0.0-alpha
|
|
(function() {
|
|
var LineMap, SourceMap;
|
|
|
|
LineMap = (function() {
|
|
function LineMap(line1) {
|
|
this.line = line1;
|
|
this.columns = [];
|
|
}
|
|
|
|
LineMap.prototype.add = function(column, arg, options = {}) {
|
|
var sourceColumn, sourceLine;
|
|
sourceLine = arg[0], sourceColumn = arg[1];
|
|
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 base, column, line, lineMap;
|
|
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 = null) {
|
|
var buffer, i, j, lastColumn, lastSourceColumn, lastSourceLine, len, len1, lineMap, lineNumber, mapping, needComma, ref, ref1, v3, writingline;
|
|
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.inlineMap) {
|
|
v3.sourcesContent = [code];
|
|
}
|
|
return v3;
|
|
};
|
|
|
|
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);
|