2016-10-22 18:48:54 +00:00
|
|
|
// Generated by CoffeeScript 2.0.0-alpha
|
2013-02-28 20:51:29 +00:00
|
|
|
(function() {
|
2013-03-18 11:46:19 +00:00
|
|
|
var LineMap, SourceMap;
|
2013-03-18 11:23:05 +00:00
|
|
|
|
|
|
|
LineMap = (function() {
|
2015-01-30 19:33:03 +00:00
|
|
|
function LineMap(line1) {
|
|
|
|
this.line = line1;
|
2013-03-18 11:23:05 +00:00
|
|
|
this.columns = [];
|
2013-02-28 20:51:29 +00:00
|
|
|
}
|
|
|
|
|
[CS2] Output ES2015 arrow functions, default parameters, rest parameters (#4311)
* 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`
2016-10-26 05:26:13 +00:00
|
|
|
LineMap.prototype.add = function(column, arg, options = {}) {
|
2013-02-28 20:51:29 +00:00
|
|
|
var sourceColumn, sourceLine;
|
2015-01-30 19:33:03 +00:00
|
|
|
sourceLine = arg[0], sourceColumn = arg[1];
|
2013-03-18 11:23:05 +00:00
|
|
|
if (this.columns[column] && options.noReplace) {
|
2013-02-28 20:51:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-03-18 11:23:05 +00:00
|
|
|
return this.columns[column] = {
|
|
|
|
line: this.line,
|
|
|
|
column: column,
|
2013-02-28 20:51:29 +00:00
|
|
|
sourceLine: sourceLine,
|
|
|
|
sourceColumn: sourceColumn
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-03-18 11:23:05 +00:00
|
|
|
LineMap.prototype.sourceLocation = function(column) {
|
|
|
|
var mapping;
|
|
|
|
while (!((mapping = this.columns[column]) || (column <= 0))) {
|
|
|
|
column--;
|
2013-02-28 20:51:29 +00:00
|
|
|
}
|
2013-03-18 11:23:05 +00:00
|
|
|
return mapping && [mapping.sourceLine, mapping.sourceColumn];
|
2013-02-28 20:51:29 +00:00
|
|
|
};
|
|
|
|
|
2013-03-18 11:23:05 +00:00
|
|
|
return LineMap;
|
2013-02-28 20:51:29 +00:00
|
|
|
|
|
|
|
})();
|
|
|
|
|
2013-03-18 11:23:05 +00:00
|
|
|
SourceMap = (function() {
|
|
|
|
var BASE64_CHARS, VLQ_CONTINUATION_BIT, VLQ_SHIFT, VLQ_VALUE_MASK;
|
|
|
|
|
2013-02-28 20:51:29 +00:00
|
|
|
function SourceMap() {
|
2013-03-18 11:23:05 +00:00
|
|
|
this.lines = [];
|
2013-02-28 20:51:29 +00:00
|
|
|
}
|
|
|
|
|
[CS2] Output ES2015 arrow functions, default parameters, rest parameters (#4311)
* 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`
2016-10-26 05:26:13 +00:00
|
|
|
SourceMap.prototype.add = function(sourceLocation, generatedLocation, options = {}) {
|
2015-01-30 19:33:03 +00:00
|
|
|
var base, column, line, lineMap;
|
2013-03-18 11:23:05 +00:00
|
|
|
line = generatedLocation[0], column = generatedLocation[1];
|
2015-01-30 19:33:03 +00:00
|
|
|
lineMap = ((base = this.lines)[line] || (base[line] = new LineMap(line)));
|
2013-03-18 11:23:05 +00:00
|
|
|
return lineMap.add(column, sourceLocation, options);
|
2013-02-28 20:51:29 +00:00
|
|
|
};
|
|
|
|
|
2015-01-30 19:33:03 +00:00
|
|
|
SourceMap.prototype.sourceLocation = function(arg) {
|
2013-03-18 11:23:05 +00:00
|
|
|
var column, line, lineMap;
|
2015-01-30 19:33:03 +00:00
|
|
|
line = arg[0], column = arg[1];
|
2013-03-18 11:23:05 +00:00
|
|
|
while (!((lineMap = this.lines[line]) || (line <= 0))) {
|
|
|
|
line--;
|
2013-02-28 20:51:29 +00:00
|
|
|
}
|
2013-03-18 11:23:05 +00:00
|
|
|
return lineMap && lineMap.sourceLocation(column);
|
2013-02-28 20:51:29 +00:00
|
|
|
};
|
|
|
|
|
[CS2] Output ES2015 arrow functions, default parameters, rest parameters (#4311)
* 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`
2016-10-26 05:26:13 +00:00
|
|
|
SourceMap.prototype.generate = function(options = {}, code = null) {
|
2015-01-30 19:33:03 +00:00
|
|
|
var buffer, i, j, lastColumn, lastSourceColumn, lastSourceLine, len, len1, lineMap, lineNumber, mapping, needComma, ref, ref1, v3, writingline;
|
2013-03-18 11:23:05 +00:00
|
|
|
writingline = 0;
|
|
|
|
lastColumn = 0;
|
|
|
|
lastSourceLine = 0;
|
|
|
|
lastSourceColumn = 0;
|
|
|
|
needComma = false;
|
|
|
|
buffer = "";
|
2015-01-30 19:33:03 +00:00
|
|
|
ref = this.lines;
|
|
|
|
for (lineNumber = i = 0, len = ref.length; i < len; lineNumber = ++i) {
|
|
|
|
lineMap = ref[lineNumber];
|
2013-03-18 11:36:34 +00:00
|
|
|
if (lineMap) {
|
2015-01-30 19:33:03 +00:00
|
|
|
ref1 = lineMap.columns;
|
|
|
|
for (j = 0, len1 = ref1.length; j < len1; j++) {
|
|
|
|
mapping = ref1[j];
|
2013-03-18 11:36:34 +00:00
|
|
|
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);
|
2013-03-18 13:50:40 +00:00
|
|
|
lastSourceLine = mapping.sourceLine;
|
2013-03-18 11:36:34 +00:00
|
|
|
buffer += this.encodeVlq(mapping.sourceColumn - lastSourceColumn);
|
|
|
|
lastSourceColumn = mapping.sourceColumn;
|
|
|
|
needComma = true;
|
|
|
|
}
|
2013-03-18 11:23:05 +00:00
|
|
|
}
|
2013-03-18 11:36:34 +00:00
|
|
|
}
|
2013-03-18 11:23:05 +00:00
|
|
|
v3 = {
|
|
|
|
version: 3,
|
|
|
|
file: options.generatedFile || '',
|
|
|
|
sourceRoot: options.sourceRoot || '',
|
|
|
|
sources: options.sourceFiles || [''],
|
|
|
|
names: [],
|
|
|
|
mappings: buffer
|
|
|
|
};
|
Improve inline source maps generation
- Inline source maps are now shorter by not using pretty-printed JSON.
- `.register()`ed files are now given more information in their inline source
maps: The name and contents of the source file.
- Some code cleanup.
If you decode the inline source map generated (when using `.register()`) for a
file test.coffee with the contents `console.log "it works!"`, here is the
output:
Before:
{
"version": 3,
"file": "",
"sourceRoot": "",
"sources": [
""
],
"names": [],
"mappings": "AAAA;EAAA,OAAO,CAAC,GAAR,CAAY,eAAZ;AAAA"
}
After:
{"version":3,"file":"","sourceRoot":"","sources":["test.coffee"],"names":[],"mappings":"AAAA;EAAA,OAAO,CAAC,GAAR,CAAY,WAAZ;AAAA","sourcesContent":["console.log \"it works!\"\n"]}
Related: #4214.
2016-03-06 13:30:47 +00:00
|
|
|
if (options.inlineMap) {
|
2013-03-18 11:23:05 +00:00
|
|
|
v3.sourcesContent = [code];
|
|
|
|
}
|
Improve inline source maps generation
- Inline source maps are now shorter by not using pretty-printed JSON.
- `.register()`ed files are now given more information in their inline source
maps: The name and contents of the source file.
- Some code cleanup.
If you decode the inline source map generated (when using `.register()`) for a
file test.coffee with the contents `console.log "it works!"`, here is the
output:
Before:
{
"version": 3,
"file": "",
"sourceRoot": "",
"sources": [
""
],
"names": [],
"mappings": "AAAA;EAAA,OAAO,CAAC,GAAR,CAAY,eAAZ;AAAA"
}
After:
{"version":3,"file":"","sourceRoot":"","sources":["test.coffee"],"names":[],"mappings":"AAAA;EAAA,OAAO,CAAC,GAAR,CAAY,WAAZ;AAAA","sourcesContent":["console.log \"it works!\"\n"]}
Related: #4214.
2016-03-06 13:30:47 +00:00
|
|
|
return v3;
|
2013-02-28 20:51:29 +00:00
|
|
|
};
|
|
|
|
|
2013-03-18 11:23:05 +00:00
|
|
|
VLQ_SHIFT = 5;
|
2013-02-28 20:51:29 +00:00
|
|
|
|
2013-03-18 11:23:05 +00:00
|
|
|
VLQ_CONTINUATION_BIT = 1 << VLQ_SHIFT;
|
2013-02-28 20:51:29 +00:00
|
|
|
|
2013-03-18 11:23:05 +00:00
|
|
|
VLQ_VALUE_MASK = VLQ_CONTINUATION_BIT - 1;
|
2013-02-28 20:51:29 +00:00
|
|
|
|
2013-03-18 11:23:05 +00:00
|
|
|
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;
|
|
|
|
};
|
2013-02-28 20:51:29 +00:00
|
|
|
|
2013-03-18 11:23:05 +00:00
|
|
|
BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
2013-02-28 20:51:29 +00:00
|
|
|
|
2013-03-18 11:23:05 +00:00
|
|
|
SourceMap.prototype.encodeBase64 = function(value) {
|
|
|
|
return BASE64_CHARS[value] || (function() {
|
2016-11-28 14:05:51 +00:00
|
|
|
throw new Error(`Cannot Base64 encode value: ${value}`);
|
2013-03-18 11:23:05 +00:00
|
|
|
})();
|
|
|
|
};
|
2013-02-28 20:51:29 +00:00
|
|
|
|
2013-03-18 11:23:05 +00:00
|
|
|
return SourceMap;
|
2013-02-28 20:51:29 +00:00
|
|
|
|
2013-03-18 11:23:05 +00:00
|
|
|
})();
|
2013-02-28 20:51:29 +00:00
|
|
|
|
2013-03-18 11:23:05 +00:00
|
|
|
module.exports = SourceMap;
|
2013-02-28 20:51:29 +00:00
|
|
|
|
|
|
|
}).call(this);
|