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`
118 lines
3.4 KiB
JavaScript
118 lines
3.4 KiB
JavaScript
// Generated by CoffeeScript 2.0.0-alpha
|
|
(function() {
|
|
var CoffeeScript, compile, runScripts,
|
|
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
|
|
|
CoffeeScript = require('./coffee-script');
|
|
|
|
CoffeeScript.require = require;
|
|
|
|
compile = CoffeeScript.compile;
|
|
|
|
CoffeeScript["eval"] = function(code, options = {}) {
|
|
if (options.bare == null) {
|
|
options.bare = true;
|
|
}
|
|
return eval(compile(code, options));
|
|
};
|
|
|
|
CoffeeScript.run = function(code, options = {}) {
|
|
options.bare = true;
|
|
options.shiftLine = true;
|
|
return Function(compile(code, options))();
|
|
};
|
|
|
|
if (typeof window === "undefined" || window === null) {
|
|
return;
|
|
}
|
|
|
|
if ((typeof btoa !== "undefined" && btoa !== null) && (typeof JSON !== "undefined" && JSON !== null)) {
|
|
compile = function(code, options = {}) {
|
|
options.inlineMap = true;
|
|
return CoffeeScript.compile(code, options);
|
|
};
|
|
}
|
|
|
|
CoffeeScript.load = function(url, callback, options = {}, hold = false) {
|
|
var xhr;
|
|
options.sourceFiles = [url];
|
|
xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP') : new window.XMLHttpRequest();
|
|
xhr.open('GET', url, true);
|
|
if ('overrideMimeType' in xhr) {
|
|
xhr.overrideMimeType('text/plain');
|
|
}
|
|
xhr.onreadystatechange = function() {
|
|
var param, ref;
|
|
if (xhr.readyState === 4) {
|
|
if ((ref = xhr.status) === 0 || ref === 200) {
|
|
param = [xhr.responseText, options];
|
|
if (!hold) {
|
|
CoffeeScript.run.apply(CoffeeScript, param);
|
|
}
|
|
} else {
|
|
throw new Error("Could not load " + url);
|
|
}
|
|
if (callback) {
|
|
return callback(param);
|
|
}
|
|
}
|
|
};
|
|
return xhr.send(null);
|
|
};
|
|
|
|
runScripts = function() {
|
|
var coffees, coffeetypes, execute, fn, i, index, j, len, s, script, scripts;
|
|
scripts = window.document.getElementsByTagName('script');
|
|
coffeetypes = ['text/coffeescript', 'text/literate-coffeescript'];
|
|
coffees = (function() {
|
|
var j, len, ref, results;
|
|
results = [];
|
|
for (j = 0, len = scripts.length; j < len; j++) {
|
|
s = scripts[j];
|
|
if (ref = s.type, indexOf.call(coffeetypes, ref) >= 0) {
|
|
results.push(s);
|
|
}
|
|
}
|
|
return results;
|
|
})();
|
|
index = 0;
|
|
execute = function() {
|
|
var param;
|
|
param = coffees[index];
|
|
if (param instanceof Array) {
|
|
CoffeeScript.run.apply(CoffeeScript, param);
|
|
index++;
|
|
return execute();
|
|
}
|
|
};
|
|
fn = function(script, i) {
|
|
var options, source;
|
|
options = {
|
|
literate: script.type === coffeetypes[1]
|
|
};
|
|
source = script.src || script.getAttribute('data-src');
|
|
if (source) {
|
|
return CoffeeScript.load(source, function(param) {
|
|
coffees[i] = param;
|
|
return execute();
|
|
}, options, true);
|
|
} else {
|
|
options.sourceFiles = ['embedded'];
|
|
return coffees[i] = [script.innerHTML, options];
|
|
}
|
|
};
|
|
for (i = j = 0, len = coffees.length; j < len; i = ++j) {
|
|
script = coffees[i];
|
|
fn(script, i);
|
|
}
|
|
return execute();
|
|
};
|
|
|
|
if (window.addEventListener) {
|
|
window.addEventListener('DOMContentLoaded', runScripts, false);
|
|
} else {
|
|
window.attachEvent('onload', runScripts);
|
|
}
|
|
|
|
}).call(this);
|