mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 11:31:20 -05:00
Fixing for magic scoping issues. Small steps at a time.
This commit is contained in:
@@ -25,14 +25,22 @@
|
|||||||
return xhr.send(null);
|
return xhr.send(null);
|
||||||
};
|
};
|
||||||
runScripts = function() {
|
runScripts = function() {
|
||||||
var _i, _len, _ref;
|
var _i, _j, _len, _ref, script;
|
||||||
for (_i = 0, _len = (_ref = document.getElementsByTagName('script')).length; _i < _len; _i++) {
|
for (_i = 0, _len = (_ref = document.getElementsByTagName('script')).length; _i < _len; _i++) {
|
||||||
(function() {
|
(function() {
|
||||||
var script = _ref[_i];
|
var script = _ref[_i];
|
||||||
return script.type === 'text/coffeescript' ? (script.src ? CoffeeScript.load(script.src) : setTimeout(function() {
|
if (script.type === 'text/coffeescript') {
|
||||||
return CoffeeScript.run(script.innerHTML);
|
if (script.src) {
|
||||||
})) : undefined;
|
CoffeeScript.load(script.src);
|
||||||
|
} else {
|
||||||
|
setTimeout(function() {
|
||||||
|
return CoffeeScript.run(script.innerHTML);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (_j = script);
|
||||||
})();
|
})();
|
||||||
|
script = _j;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
});
|
});
|
||||||
exports.run = function() {
|
exports.run = function() {
|
||||||
return path.exists('Cakefile', function(exists) {
|
return path.exists('Cakefile', function(exists) {
|
||||||
var _i, _len, _ref, _result, arg, args;
|
var _i, _j, _len, _ref, _result, arg, args;
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
throw new Error("Cakefile not found in " + (process.cwd()));
|
throw new Error("Cakefile not found in " + (process.cwd()));
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
printTasks = function() {
|
printTasks = function() {
|
||||||
var _ref, desc, name, spaces, task;
|
var _i, _ref, desc, name, spaces, task;
|
||||||
puts('');
|
puts('');
|
||||||
for (name in _ref = tasks) {
|
for (name in _ref = tasks) {
|
||||||
task = _ref[name];
|
task = _ref[name];
|
||||||
|
|||||||
@@ -48,13 +48,13 @@
|
|||||||
return compileScripts();
|
return compileScripts();
|
||||||
};
|
};
|
||||||
compileScripts = function() {
|
compileScripts = function() {
|
||||||
var _i, _len, _ref2, _result;
|
var _i, _j, _len, _ref2, _result, source;
|
||||||
_result = [];
|
_result = [];
|
||||||
for (_i = 0, _len = (_ref2 = sources).length; _i < _len; _i++) {
|
for (_i = 0, _len = (_ref2 = sources).length; _i < _len; _i++) {
|
||||||
(function() {
|
(function() {
|
||||||
var base, compile;
|
var base, compile;
|
||||||
var source = _ref2[_i];
|
var source = _ref2[_i];
|
||||||
return _result.push((function() {
|
_result.push((function() {
|
||||||
base = source;
|
base = source;
|
||||||
compile = function(source, topLevel) {
|
compile = function(source, topLevel) {
|
||||||
return path.exists(source, function(exists) {
|
return path.exists(source, function(exists) {
|
||||||
@@ -64,10 +64,10 @@
|
|||||||
return fs.stat(source, function(err, stats) {
|
return fs.stat(source, function(err, stats) {
|
||||||
if (stats.isDirectory()) {
|
if (stats.isDirectory()) {
|
||||||
return fs.readdir(source, function(err, files) {
|
return fs.readdir(source, function(err, files) {
|
||||||
var _j, _len2, _result2, file;
|
var _k, _l, _len2, _result2, file;
|
||||||
_result2 = [];
|
_result2 = [];
|
||||||
for (_j = 0, _len2 = files.length; _j < _len2; _j++) {
|
for (_k = 0, _len2 = files.length; _k < _len2; _k++) {
|
||||||
file = files[_j];
|
file = files[_k];
|
||||||
_result2.push(compile(path.join(source, file)));
|
_result2.push(compile(path.join(source, file)));
|
||||||
}
|
}
|
||||||
return _result2;
|
return _result2;
|
||||||
@@ -83,12 +83,14 @@
|
|||||||
};
|
};
|
||||||
return compile(source, true);
|
return compile(source, true);
|
||||||
})());
|
})());
|
||||||
|
return (_j = source);
|
||||||
})();
|
})();
|
||||||
|
source = _j;
|
||||||
}
|
}
|
||||||
return _result;
|
return _result;
|
||||||
};
|
};
|
||||||
compileScript = function(file, input, base) {
|
compileScript = function(file, input, base) {
|
||||||
var _i, _len, _ref2, o, options, req, t, task;
|
var _i, _j, _len, _ref2, o, options, req, t, task;
|
||||||
o = opts;
|
o = opts;
|
||||||
options = compileOptions(file);
|
options = compileOptions(file);
|
||||||
if (o.require) {
|
if (o.require) {
|
||||||
@@ -186,7 +188,7 @@
|
|||||||
return jsl.stdin.end();
|
return jsl.stdin.end();
|
||||||
};
|
};
|
||||||
printTokens = function(tokens) {
|
printTokens = function(tokens) {
|
||||||
var _i, _len, _ref2, _result, strings, tag, token, value;
|
var _i, _j, _len, _ref2, _result, strings, tag, token, value;
|
||||||
strings = (function() {
|
strings = (function() {
|
||||||
_result = [];
|
_result = [];
|
||||||
for (_i = 0, _len = tokens.length; _i < _len; _i++) {
|
for (_i = 0, _len = tokens.length; _i < _len; _i++) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
(function() {
|
(function() {
|
||||||
var Parser, _i, _j, _len, _len2, _ref, _result, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap;
|
var Parser, _i, _j, _k, _l, _len, _len2, _m, _ref, _result, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap;
|
||||||
var __hasProp = Object.prototype.hasOwnProperty;
|
var __hasProp = Object.prototype.hasOwnProperty;
|
||||||
Parser = require('jison').Parser;
|
Parser = require('jison').Parser;
|
||||||
unwrap = /function\s*\(\)\s*\{\s*return\s*([\s\S]*);\s*\}/;
|
unwrap = /function\s*\(\)\s*\{\s*return\s*([\s\S]*);\s*\}/;
|
||||||
@@ -595,11 +595,11 @@
|
|||||||
alternatives = grammar[name];
|
alternatives = grammar[name];
|
||||||
grammar[name] = (function() {
|
grammar[name] = (function() {
|
||||||
_result = [];
|
_result = [];
|
||||||
for (_i = 0, _len = alternatives.length; _i < _len; _i++) {
|
for (_j = 0, _len = alternatives.length; _j < _len; _j++) {
|
||||||
alt = alternatives[_i];
|
alt = alternatives[_j];
|
||||||
_result.push((function() {
|
_result.push((function() {
|
||||||
for (_j = 0, _len2 = (_ref = alt[0].split(' ')).length; _j < _len2; _j++) {
|
for (_l = 0, _len2 = (_ref = alt[0].split(' ')).length; _l < _len2; _l++) {
|
||||||
token = _ref[_j];
|
token = _ref[_l];
|
||||||
if (!grammar[token]) {
|
if (!grammar[token]) {
|
||||||
tokens.push(token);
|
tokens.push(token);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
indexOf = (exports.indexOf = Array.indexOf || (Array.prototype.indexOf ? function(array, item, from) {
|
indexOf = (exports.indexOf = Array.indexOf || (Array.prototype.indexOf ? function(array, item, from) {
|
||||||
return array.indexOf(item, from);
|
return array.indexOf(item, from);
|
||||||
} : function(array, item, from) {
|
} : function(array, item, from) {
|
||||||
var _len, index, other;
|
var _i, _len, index, other;
|
||||||
for (index = 0, _len = array.length; index < _len; index++) {
|
for (index = 0, _len = array.length; index < _len; index++) {
|
||||||
other = array[index];
|
other = array[index];
|
||||||
if (other === item && (!from || (from <= index))) {
|
if (other === item && (!from || (from <= index))) {
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
return literal === string.substr(string.length - len - (back || 0), len);
|
return literal === string.substr(string.length - len - (back || 0), len);
|
||||||
};
|
};
|
||||||
exports.compact = function(array) {
|
exports.compact = function(array) {
|
||||||
var _i, _len, _result, item;
|
var _i, _j, _len, _result, item;
|
||||||
_result = [];
|
_result = [];
|
||||||
for (_i = 0, _len = array.length; _i < _len; _i++) {
|
for (_i = 0, _len = array.length; _i < _len; _i++) {
|
||||||
item = array[_i];
|
item = array[_i];
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
return extend(extend({}, options), overrides);
|
return extend(extend({}, options), overrides);
|
||||||
};
|
};
|
||||||
extend = (exports.extend = function(object, properties) {
|
extend = (exports.extend = function(object, properties) {
|
||||||
var key, val;
|
var _i, key, val;
|
||||||
for (key in properties) {
|
for (key in properties) {
|
||||||
val = properties[key];
|
val = properties[key];
|
||||||
object[key] = val;
|
object[key] = val;
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
return object;
|
return object;
|
||||||
});
|
});
|
||||||
exports.flatten = (flatten = function(array) {
|
exports.flatten = (flatten = function(array) {
|
||||||
var _i, _len, element, flattened;
|
var _i, _j, _len, element, flattened;
|
||||||
flattened = [];
|
flattened = [];
|
||||||
for (_i = 0, _len = array.length; _i < _len; _i++) {
|
for (_i = 0, _len = array.length; _i < _len; _i++) {
|
||||||
element = array[_i];
|
element = array[_i];
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
(function() {
|
(function() {
|
||||||
var _ref, key, val;
|
var _i, _ref, key, val;
|
||||||
var __hasProp = Object.prototype.hasOwnProperty;
|
var __hasProp = Object.prototype.hasOwnProperty;
|
||||||
for (key in _ref = require('./coffee-script')) {
|
for (key in _ref = require('./coffee-script')) {
|
||||||
if (!__hasProp.call(_ref, key)) continue;
|
if (!__hasProp.call(_ref, key)) continue;
|
||||||
|
|||||||
@@ -200,7 +200,7 @@
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
Lexer.prototype.heregexToken = function(match) {
|
Lexer.prototype.heregexToken = function(match) {
|
||||||
var _i, _len, _ref2, _ref3, _ref4, _this, body, flags, heregex, re, tag, tokens, value;
|
var _i, _j, _len, _ref2, _ref3, _ref4, _this, body, flags, heregex, re, tag, tokens, value;
|
||||||
heregex = match[0], body = match[1], flags = match[2];
|
heregex = match[0], body = match[1], flags = match[2];
|
||||||
this.i += heregex.length;
|
this.i += heregex.length;
|
||||||
if (0 > body.indexOf('#{')) {
|
if (0 > body.indexOf('#{')) {
|
||||||
@@ -454,7 +454,7 @@
|
|||||||
throw SyntaxError("Reserved word \"" + (this.value()) + "\" on line " + (this.line + 1) + " can't be assigned");
|
throw SyntaxError("Reserved word \"" + (this.value()) + "\" on line " + (this.line + 1) + " can't be assigned");
|
||||||
};
|
};
|
||||||
Lexer.prototype.balancedString = function(str, delimited, options) {
|
Lexer.prototype.balancedString = function(str, delimited, options) {
|
||||||
var _i, _len, close, i, levels, open, pair, slen;
|
var _i, _j, _len, close, i, levels, open, pair, slen;
|
||||||
options || (options = {});
|
options || (options = {});
|
||||||
levels = [];
|
levels = [];
|
||||||
i = 0;
|
i = 0;
|
||||||
@@ -492,7 +492,7 @@
|
|||||||
return !i ? false : str.slice(0, i);
|
return !i ? false : str.slice(0, i);
|
||||||
};
|
};
|
||||||
Lexer.prototype.interpolateString = function(str, options) {
|
Lexer.prototype.interpolateString = function(str, options) {
|
||||||
var _len, _ref2, _ref3, _this, expr, heredoc, i, inner, interpolated, letter, nested, pi, regex, tag, tokens, value;
|
var _i, _len, _ref2, _ref3, _this, expr, heredoc, i, inner, interpolated, letter, nested, pi, regex, tag, tokens, value;
|
||||||
_ref2 = options || (options = {}), heredoc = _ref2.heredoc, regex = _ref2.regex;
|
_ref2 = options || (options = {}), heredoc = _ref2.heredoc, regex = _ref2.regex;
|
||||||
tokens = [];
|
tokens = [];
|
||||||
pi = 0;
|
pi = 0;
|
||||||
|
|||||||
90
lib/nodes.js
90
lib/nodes.js
@@ -37,10 +37,13 @@
|
|||||||
};
|
};
|
||||||
Base.prototype.compileClosure = function(o) {
|
Base.prototype.compileClosure = function(o) {
|
||||||
o.sharedScope = o.scope;
|
o.sharedScope = o.scope;
|
||||||
return Closure.wrap(this, false, true).compile(o);
|
if (this.containsPureStatement()) {
|
||||||
|
throw new Error('cannot include a pure statement in an expression.');
|
||||||
|
}
|
||||||
|
return Closure.wrap(this).compile(o);
|
||||||
};
|
};
|
||||||
Base.prototype.compileReference = function(o, options) {
|
Base.prototype.compileReference = function(o, options) {
|
||||||
var _len, compiled, i, node, pair, reference;
|
var _i, _len, compiled, i, node, pair, reference;
|
||||||
pair = (function() {
|
pair = (function() {
|
||||||
if (!this.isComplex()) {
|
if (!this.isComplex()) {
|
||||||
return [this, this];
|
return [this, this];
|
||||||
@@ -95,7 +98,7 @@
|
|||||||
return this.traverseChildren(true, block);
|
return this.traverseChildren(true, block);
|
||||||
};
|
};
|
||||||
Base.prototype.toString = function(idt, override) {
|
Base.prototype.toString = function(idt, override) {
|
||||||
var _i, _len, _ref2, _result, child, children, klass;
|
var _i, _j, _len, _ref2, _result, child, children, klass;
|
||||||
idt || (idt = '');
|
idt || (idt = '');
|
||||||
children = (function() {
|
children = (function() {
|
||||||
_result = [];
|
_result = [];
|
||||||
@@ -109,7 +112,7 @@
|
|||||||
return '\n' + idt + klass + children;
|
return '\n' + idt + klass + children;
|
||||||
};
|
};
|
||||||
Base.prototype.eachChild = function(func) {
|
Base.prototype.eachChild = function(func) {
|
||||||
var _i, _j, _len, _len2, _ref2, _ref3, _result, attr, child;
|
var _i, _j, _k, _l, _len, _len2, _ref2, _ref3, _result, attr, child;
|
||||||
if (!this.children) {
|
if (!this.children) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -117,8 +120,8 @@
|
|||||||
for (_i = 0, _len = (_ref2 = this.children).length; _i < _len; _i++) {
|
for (_i = 0, _len = (_ref2 = this.children).length; _i < _len; _i++) {
|
||||||
attr = _ref2[_i];
|
attr = _ref2[_i];
|
||||||
if (this[attr]) {
|
if (this[attr]) {
|
||||||
for (_j = 0, _len2 = (_ref3 = flatten([this[attr]])).length; _j < _len2; _j++) {
|
for (_k = 0, _len2 = (_ref3 = flatten([this[attr]])).length; _k < _len2; _k++) {
|
||||||
child = _ref3[_j];
|
child = _ref3[_k];
|
||||||
if (func(child) === false) {
|
if (func(child) === false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -198,7 +201,7 @@
|
|||||||
return o.scope ? Expressions.__super__.compile.call(this, o) : this.compileRoot(o);
|
return o.scope ? Expressions.__super__.compile.call(this, o) : this.compileRoot(o);
|
||||||
};
|
};
|
||||||
Expressions.prototype.compileNode = function(o) {
|
Expressions.prototype.compileNode = function(o) {
|
||||||
var _i, _len, _ref2, _result, node;
|
var _i, _j, _len, _ref2, _result, node;
|
||||||
return (function() {
|
return (function() {
|
||||||
_result = [];
|
_result = [];
|
||||||
for (_i = 0, _len = (_ref2 = this.expressions).length; _i < _len; _i++) {
|
for (_i = 0, _len = (_ref2 = this.expressions).length; _i < _len; _i++) {
|
||||||
@@ -392,7 +395,7 @@
|
|||||||
return !o.top || this.properties.length ? Value.__super__.compile.call(this, o) : this.base.compile(o);
|
return !o.top || this.properties.length ? Value.__super__.compile.call(this, o) : this.base.compile(o);
|
||||||
};
|
};
|
||||||
Value.prototype.compileNode = function(o) {
|
Value.prototype.compileNode = function(o) {
|
||||||
var _i, _len, code, ifn, prop, props;
|
var _i, _j, _len, code, ifn, prop, props;
|
||||||
if (ifn = this.unfoldSoak(o)) {
|
if (ifn = this.unfoldSoak(o)) {
|
||||||
return ifn.compile(o);
|
return ifn.compile(o);
|
||||||
}
|
}
|
||||||
@@ -411,7 +414,7 @@
|
|||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
Value.prototype.unfoldSoak = function(o) {
|
Value.prototype.unfoldSoak = function(o) {
|
||||||
var _len, _ref2, fst, i, ifn, prop, ref, snd;
|
var _i, _len, _ref2, fst, i, ifn, prop, ref, snd;
|
||||||
if (ifn = this.base.unfoldSoak(o)) {
|
if (ifn = this.base.unfoldSoak(o)) {
|
||||||
Array.prototype.push.apply(ifn.body.properties, this.properties);
|
Array.prototype.push.apply(ifn.body.properties, this.properties);
|
||||||
return ifn;
|
return ifn;
|
||||||
@@ -493,7 +496,7 @@
|
|||||||
return method.klass ? ("" + (method.klass) + ".__super__." + name) : ("" + name + ".__super__.constructor");
|
return method.klass ? ("" + (method.klass) + ".__super__." + name) : ("" + name + ".__super__.constructor");
|
||||||
};
|
};
|
||||||
Call.prototype.unfoldSoak = function(o) {
|
Call.prototype.unfoldSoak = function(o) {
|
||||||
var _i, _len, _ref2, _ref3, call, ifn, left, list, rite, val;
|
var _i, _j, _len, _ref2, _ref3, call, ifn, left, list, rite, val;
|
||||||
if (this.soakNode) {
|
if (this.soakNode) {
|
||||||
if (val = this.variable) {
|
if (val = this.variable) {
|
||||||
if (!(val instanceof Value)) {
|
if (!(val instanceof Value)) {
|
||||||
@@ -542,7 +545,7 @@
|
|||||||
return ifn;
|
return ifn;
|
||||||
};
|
};
|
||||||
Call.prototype.compileNode = function(o) {
|
Call.prototype.compileNode = function(o) {
|
||||||
var _i, _j, _len, _len2, _ref2, _ref3, _ref4, _result, arg, args, ifn;
|
var _i, _j, _k, _l, _len, _len2, _ref2, _ref3, _ref4, _result, arg, args, ifn;
|
||||||
if (ifn = this.unfoldSoak(o)) {
|
if (ifn = this.unfoldSoak(o)) {
|
||||||
return ifn.compile(o);
|
return ifn.compile(o);
|
||||||
}
|
}
|
||||||
@@ -555,8 +558,8 @@
|
|||||||
}
|
}
|
||||||
args = (function() {
|
args = (function() {
|
||||||
_result = [];
|
_result = [];
|
||||||
for (_j = 0, _len2 = (_ref4 = this.args).length; _j < _len2; _j++) {
|
for (_k = 0, _len2 = (_ref4 = this.args).length; _k < _len2; _k++) {
|
||||||
arg = _ref4[_j];
|
arg = _ref4[_k];
|
||||||
_result.push((arg.parenthetical = true) && arg.compile(o));
|
_result.push((arg.parenthetical = true) && arg.compile(o));
|
||||||
}
|
}
|
||||||
return _result;
|
return _result;
|
||||||
@@ -778,7 +781,7 @@
|
|||||||
__extends(ObjectLiteral, Base);
|
__extends(ObjectLiteral, Base);
|
||||||
ObjectLiteral.prototype.children = ['properties'];
|
ObjectLiteral.prototype.children = ['properties'];
|
||||||
ObjectLiteral.prototype.compileNode = function(o) {
|
ObjectLiteral.prototype.compileNode = function(o) {
|
||||||
var _i, _len, _ref2, _result, i, indent, join, lastNoncom, nonComments, obj, prop, props, top;
|
var _i, _j, _len, _ref2, _result, i, indent, join, lastNoncom, nonComments, obj, prop, props, top;
|
||||||
top = del(o, 'top');
|
top = del(o, 'top');
|
||||||
o.indent = this.idt(1);
|
o.indent = this.idt(1);
|
||||||
nonComments = (function() {
|
nonComments = (function() {
|
||||||
@@ -814,7 +817,7 @@
|
|||||||
return this.tags.front ? ("(" + obj + ")") : obj;
|
return this.tags.front ? ("(" + obj + ")") : obj;
|
||||||
};
|
};
|
||||||
ObjectLiteral.prototype.assigns = function(name) {
|
ObjectLiteral.prototype.assigns = function(name) {
|
||||||
var _i, _len, _ref2, prop;
|
var _i, _j, _len, _ref2, prop;
|
||||||
for (_i = 0, _len = (_ref2 = this.properties).length; _i < _len; _i++) {
|
for (_i = 0, _len = (_ref2 = this.properties).length; _i < _len; _i++) {
|
||||||
prop = _ref2[_i];
|
prop = _ref2[_i];
|
||||||
if (prop.assigns(name)) {
|
if (prop.assigns(name)) {
|
||||||
@@ -841,7 +844,7 @@
|
|||||||
return Splat.compileSplattedArray(this.objects, o);
|
return Splat.compileSplattedArray(this.objects, o);
|
||||||
};
|
};
|
||||||
ArrayLiteral.prototype.compileNode = function(o) {
|
ArrayLiteral.prototype.compileNode = function(o) {
|
||||||
var _i, _len, _len2, _ref2, _ref3, code, i, obj, objects;
|
var _i, _j, _k, _len, _len2, _ref2, _ref3, code, i, obj, objects;
|
||||||
o.indent = this.idt(1);
|
o.indent = this.idt(1);
|
||||||
for (_i = 0, _len = (_ref2 = this.objects).length; _i < _len; _i++) {
|
for (_i = 0, _len = (_ref2 = this.objects).length; _i < _len; _i++) {
|
||||||
obj = _ref2[_i];
|
obj = _ref2[_i];
|
||||||
@@ -859,7 +862,7 @@
|
|||||||
return 0 < objects.indexOf('\n') ? ("[\n" + (o.indent) + objects + "\n" + (this.tab) + "]") : ("[" + objects + "]");
|
return 0 < objects.indexOf('\n') ? ("[\n" + (o.indent) + objects + "\n" + (this.tab) + "]") : ("[" + objects + "]");
|
||||||
};
|
};
|
||||||
ArrayLiteral.prototype.assigns = function(name) {
|
ArrayLiteral.prototype.assigns = function(name) {
|
||||||
var _i, _len, _ref2, obj;
|
var _i, _j, _len, _ref2, obj;
|
||||||
for (_i = 0, _len = (_ref2 = this.objects).length; _i < _len; _i++) {
|
for (_i = 0, _len = (_ref2 = this.objects).length; _i < _len; _i++) {
|
||||||
obj = _ref2[_i];
|
obj = _ref2[_i];
|
||||||
if (obj.assigns(name)) {
|
if (obj.assigns(name)) {
|
||||||
@@ -891,7 +894,7 @@
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
Class.prototype.compileNode = function(o) {
|
Class.prototype.compileNode = function(o) {
|
||||||
var _i, _len, _ref2, _ref3, _ref4, access, applied, apply, className, constScope, construct, constructor, extension, func, me, pname, prop, props, pvar, ref, returns, val, variable;
|
var _i, _j, _len, _ref2, _ref3, _ref4, access, applied, apply, className, constScope, construct, constructor, extension, func, me, pname, prop, props, pvar, ref, returns, val, variable;
|
||||||
variable = this.variable;
|
variable = this.variable;
|
||||||
if (variable.value === '__temp__') {
|
if (variable.value === '__temp__') {
|
||||||
variable = new Literal(o.scope.freeVariable('ctor'));
|
variable = new Literal(o.scope.freeVariable('ctor'));
|
||||||
@@ -1021,7 +1024,7 @@
|
|||||||
return top || this.parenthetical ? val : ("(" + val + ")");
|
return top || this.parenthetical ? val : ("(" + val + ")");
|
||||||
};
|
};
|
||||||
Assign.prototype.compilePatternMatch = function(o) {
|
Assign.prototype.compilePatternMatch = function(o) {
|
||||||
var _len, _ref2, _ref3, accessClass, assigns, code, i, idx, isObject, obj, objects, olength, otop, ref, splat, top, val, valVar, value;
|
var _i, _len, _ref2, _ref3, accessClass, assigns, code, i, idx, isObject, obj, objects, olength, otop, ref, splat, top, val, valVar, value;
|
||||||
if ((value = this.value).isStatement(o)) {
|
if ((value = this.value).isStatement(o)) {
|
||||||
value = Closure.wrap(value);
|
value = Closure.wrap(value);
|
||||||
}
|
}
|
||||||
@@ -1120,7 +1123,7 @@
|
|||||||
__extends(Code, Base);
|
__extends(Code, Base);
|
||||||
Code.prototype.children = ['params', 'body'];
|
Code.prototype.children = ['params', 'body'];
|
||||||
Code.prototype.compileNode = function(o) {
|
Code.prototype.compileNode = function(o) {
|
||||||
var _i, _len, _len2, _ref2, _ref3, _result, close, code, comm, empty, func, i, open, param, params, sharedScope, splat, top, value;
|
var _i, _j, _k, _len, _len2, _ref2, _ref3, _result, close, code, comm, empty, func, i, open, param, params, sharedScope, splat, top, value;
|
||||||
sharedScope = del(o, 'sharedScope');
|
sharedScope = del(o, 'sharedScope');
|
||||||
top = del(o, 'top');
|
top = del(o, 'top');
|
||||||
o.scope = sharedScope || new Scope(o.scope, this.body, this);
|
o.scope = sharedScope || new Scope(o.scope, this.body, this);
|
||||||
@@ -1159,8 +1162,8 @@
|
|||||||
o.scope.startLevel();
|
o.scope.startLevel();
|
||||||
params = (function() {
|
params = (function() {
|
||||||
_result = [];
|
_result = [];
|
||||||
for (_i = 0, _len2 = params.length; _i < _len2; _i++) {
|
for (_j = 0, _len2 = params.length; _j < _len2; _j++) {
|
||||||
param = params[_i];
|
param = params[_j];
|
||||||
_result.push(param.compile(o));
|
_result.push(param.compile(o));
|
||||||
}
|
}
|
||||||
return _result;
|
return _result;
|
||||||
@@ -1168,8 +1171,8 @@
|
|||||||
if (!empty) {
|
if (!empty) {
|
||||||
this.body.makeReturn();
|
this.body.makeReturn();
|
||||||
}
|
}
|
||||||
for (_i = 0, _len2 = params.length; _i < _len2; _i++) {
|
for (_j = 0, _len2 = params.length; _j < _len2; _j++) {
|
||||||
param = params[_i];
|
param = params[_j];
|
||||||
(o.scope.parameter(param));
|
(o.scope.parameter(param));
|
||||||
}
|
}
|
||||||
comm = this.comment ? this.comment.compile(o) + '\n' : '';
|
comm = this.comment ? this.comment.compile(o) + '\n' : '';
|
||||||
@@ -1239,7 +1242,7 @@
|
|||||||
return (this.index != null) ? this.compileParam(o) : this.name.compile(o);
|
return (this.index != null) ? this.compileParam(o) : this.name.compile(o);
|
||||||
};
|
};
|
||||||
Splat.prototype.compileParam = function(o) {
|
Splat.prototype.compileParam = function(o) {
|
||||||
var _len, _ref2, assign, end, idx, len, name, pos, trailing, variadic;
|
var _i, _len, _ref2, assign, end, idx, len, name, pos, trailing, variadic;
|
||||||
name = this.name.compile(o);
|
name = this.name.compile(o);
|
||||||
o.scope.find(name);
|
o.scope.find(name);
|
||||||
end = '';
|
end = '';
|
||||||
@@ -1268,7 +1271,7 @@
|
|||||||
return "" + (utility('slice')) + ".call(" + name + ", " + index + trail + ")";
|
return "" + (utility('slice')) + ".call(" + name + ", " + index + trail + ")";
|
||||||
};
|
};
|
||||||
Splat.compileSplattedArray = function(list, o) {
|
Splat.compileSplattedArray = function(list, o) {
|
||||||
var _len, arg, args, code, end, i, prev;
|
var _i, _len, arg, args, code, end, i, prev;
|
||||||
args = [];
|
args = [];
|
||||||
end = -1;
|
end = -1;
|
||||||
for (i = 0, _len = list.length; i < _len; i++) {
|
for (i = 0, _len = list.length; i < _len; i++) {
|
||||||
@@ -1482,7 +1485,7 @@
|
|||||||
return this.isArray() ? this.compileOrTest(o) : this.compileLoopTest(o);
|
return this.isArray() ? this.compileOrTest(o) : this.compileLoopTest(o);
|
||||||
};
|
};
|
||||||
In.prototype.compileOrTest = function(o) {
|
In.prototype.compileOrTest = function(o) {
|
||||||
var _len, _ref2, _result, i, item, tests;
|
var _i, _len, _ref2, _result, i, item, tests;
|
||||||
tests = (function() {
|
tests = (function() {
|
||||||
_result = [];
|
_result = [];
|
||||||
for (i = 0, _len = (_ref2 = this.array.base.objects).length; i < _len; i++) {
|
for (i = 0, _len = (_ref2 = this.array.base.objects).length; i < _len; i++) {
|
||||||
@@ -1654,7 +1657,7 @@
|
|||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
For.prototype.compileNode = function(o) {
|
For.prototype.compileNode = function(o) {
|
||||||
var body, codeInBody, forPart, guardPart, idt1, index, ivar, lvar, name, namePart, range, ref, resultPart, returnResult, rvar, scope, source, sourcePart, stepPart, svar, topLevel, varPart, vars;
|
var body, codeInBody, forPart, guardPart, idt1, index, ivar, lvar, name, namePart, nvar, range, ref, resultPart, returnResult, rvar, scope, source, sourcePart, stepPart, svar, topLevel, varPart, vars;
|
||||||
topLevel = del(o, 'top') && !this.returns;
|
topLevel = del(o, 'top') && !this.returns;
|
||||||
range = this.source instanceof Value && this.source.base instanceof Range && !this.source.properties.length;
|
range = this.source instanceof Value && this.source.base instanceof Range && !this.source.properties.length;
|
||||||
source = range ? this.source.base : this.source;
|
source = range ? this.source.base : this.source;
|
||||||
@@ -1681,6 +1684,9 @@
|
|||||||
if (!ivar || codeInBody) {
|
if (!ivar || codeInBody) {
|
||||||
ivar = scope.freeVariable('i');
|
ivar = scope.freeVariable('i');
|
||||||
}
|
}
|
||||||
|
if (name && !range) {
|
||||||
|
nvar = scope.freeVariable('i');
|
||||||
|
}
|
||||||
varPart = '';
|
varPart = '';
|
||||||
guardPart = '';
|
guardPart = '';
|
||||||
body = Expressions.wrap([this.body]);
|
body = Expressions.wrap([this.body]);
|
||||||
@@ -1728,7 +1734,19 @@
|
|||||||
if (index) {
|
if (index) {
|
||||||
body.unshift(new Literal("var " + index + " = " + ivar));
|
body.unshift(new Literal("var " + index + " = " + ivar));
|
||||||
}
|
}
|
||||||
|
if (index) {
|
||||||
|
body.push(new Assign(new Literal(ivar), new Literal(index)));
|
||||||
|
}
|
||||||
|
if (nvar) {
|
||||||
|
body.push(new Assign(new Literal(nvar), new Literal(name)));
|
||||||
|
}
|
||||||
body = Closure.wrap(body, true);
|
body = Closure.wrap(body, true);
|
||||||
|
if (index) {
|
||||||
|
body.push(new Assign(new Literal(index), new Literal(ivar)));
|
||||||
|
}
|
||||||
|
if (name) {
|
||||||
|
body.push(new Assign(new Literal(name), new Literal(nvar || ivar)));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (namePart) {
|
if (namePart) {
|
||||||
varPart = ("" + idt1 + namePart + ";\n");
|
varPart = ("" + idt1 + namePart + ";\n");
|
||||||
@@ -1766,7 +1784,7 @@
|
|||||||
Switch.prototype.children = ['subject', 'cases', 'otherwise'];
|
Switch.prototype.children = ['subject', 'cases', 'otherwise'];
|
||||||
Switch.prototype.isStatement = YES;
|
Switch.prototype.isStatement = YES;
|
||||||
Switch.prototype.makeReturn = function() {
|
Switch.prototype.makeReturn = function() {
|
||||||
var _i, _len, _ref2, pair;
|
var _i, _j, _len, _ref2, pair;
|
||||||
for (_i = 0, _len = (_ref2 = this.cases).length; _i < _len; _i++) {
|
for (_i = 0, _len = (_ref2 = this.cases).length; _i < _len; _i++) {
|
||||||
pair = _ref2[_i];
|
pair = _ref2[_i];
|
||||||
pair[1].makeReturn();
|
pair[1].makeReturn();
|
||||||
@@ -1777,7 +1795,7 @@
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
Switch.prototype.compileNode = function(o) {
|
Switch.prototype.compileNode = function(o) {
|
||||||
var _i, _j, _len, _len2, _ref2, _ref3, block, code, condition, conditions, exprs, idt, pair;
|
var _i, _j, _k, _l, _len, _len2, _ref2, _ref3, block, code, condition, conditions, exprs, idt, pair;
|
||||||
idt = (o.indent = this.idt(2));
|
idt = (o.indent = this.idt(2));
|
||||||
o.top = true;
|
o.top = true;
|
||||||
code = ("" + (this.tab) + "switch (" + (this.subject.compile(o)) + ") {");
|
code = ("" + (this.tab) + "switch (" + (this.subject.compile(o)) + ") {");
|
||||||
@@ -1785,8 +1803,8 @@
|
|||||||
pair = _ref2[_i];
|
pair = _ref2[_i];
|
||||||
conditions = pair[0], block = pair[1];
|
conditions = pair[0], block = pair[1];
|
||||||
exprs = block.expressions;
|
exprs = block.expressions;
|
||||||
for (_j = 0, _len2 = (_ref3 = flatten([conditions])).length; _j < _len2; _j++) {
|
for (_k = 0, _len2 = (_ref3 = flatten([conditions])).length; _k < _len2; _k++) {
|
||||||
condition = _ref3[_j];
|
condition = _ref3[_k];
|
||||||
if (this.tags.subjectless) {
|
if (this.tags.subjectless) {
|
||||||
condition = new Op('!!', new Parens(condition));
|
condition = new Op('!!', new Parens(condition));
|
||||||
}
|
}
|
||||||
@@ -1914,14 +1932,8 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Closure = {
|
Closure = {
|
||||||
wrap: function(expressions, statement, force) {
|
wrap: function(expressions, statement) {
|
||||||
var args, call, func, mentionsArgs, meth;
|
var args, call, func, mentionsArgs, meth;
|
||||||
if (expressions.containsPureStatement()) {
|
|
||||||
if (!force) {
|
|
||||||
return expressions;
|
|
||||||
}
|
|
||||||
throw new Error('cannot include a pure statement in an expression.');
|
|
||||||
}
|
|
||||||
if (expressions.containsPureStatement()) {
|
if (expressions.containsPureStatement()) {
|
||||||
return expressions;
|
return expressions;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
return OptionParser;
|
return OptionParser;
|
||||||
})();
|
})();
|
||||||
OptionParser.prototype.parse = function(args) {
|
OptionParser.prototype.parse = function(args) {
|
||||||
var _i, _len, _len2, _ref, arg, i, isOption, matchedRule, options, rule, value;
|
var _i, _j, _k, _len, _len2, _ref, arg, i, isOption, matchedRule, options, rule, value;
|
||||||
options = {
|
options = {
|
||||||
arguments: []
|
arguments: []
|
||||||
};
|
};
|
||||||
@@ -19,8 +19,8 @@
|
|||||||
arg = args[i];
|
arg = args[i];
|
||||||
isOption = !!(arg.match(LONG_FLAG) || arg.match(SHORT_FLAG));
|
isOption = !!(arg.match(LONG_FLAG) || arg.match(SHORT_FLAG));
|
||||||
matchedRule = false;
|
matchedRule = false;
|
||||||
for (_i = 0, _len2 = (_ref = this.rules).length; _i < _len2; _i++) {
|
for (_j = 0, _len2 = (_ref = this.rules).length; _j < _len2; _j++) {
|
||||||
rule = _ref[_i];
|
rule = _ref[_j];
|
||||||
if (rule.shortFlag === arg || rule.longFlag === arg) {
|
if (rule.shortFlag === arg || rule.longFlag === arg) {
|
||||||
value = rule.hasArgument ? args[i += 1] : true;
|
value = rule.hasArgument ? args[i += 1] : true;
|
||||||
options[rule.name] = rule.isList ? (options[rule.name] || []).concat(value) : value;
|
options[rule.name] = rule.isList ? (options[rule.name] || []).concat(value) : value;
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
return options;
|
return options;
|
||||||
};
|
};
|
||||||
OptionParser.prototype.help = function() {
|
OptionParser.prototype.help = function() {
|
||||||
var _i, _len, _ref, letPart, lines, rule, spaces;
|
var _i, _j, _len, _ref, letPart, lines, rule, spaces;
|
||||||
lines = ['Available options:'];
|
lines = ['Available options:'];
|
||||||
if (this.banner) {
|
if (this.banner) {
|
||||||
lines.unshift("" + (this.banner) + "\n");
|
lines.unshift("" + (this.banner) + "\n");
|
||||||
@@ -60,7 +60,7 @@
|
|||||||
MULTI_FLAG = /^-(\w{2,})/;
|
MULTI_FLAG = /^-(\w{2,})/;
|
||||||
OPTIONAL = /\[(\w+(\*?))\]/;
|
OPTIONAL = /\[(\w+(\*?))\]/;
|
||||||
buildRules = function(rules) {
|
buildRules = function(rules) {
|
||||||
var _i, _len, _result, tuple;
|
var _i, _j, _len, _result, tuple;
|
||||||
_result = [];
|
_result = [];
|
||||||
for (_i = 0, _len = rules.length; _i < _len; _i++) {
|
for (_i = 0, _len = rules.length; _i < _len; _i++) {
|
||||||
tuple = rules[_i];
|
tuple = rules[_i];
|
||||||
@@ -88,14 +88,14 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
normalizeArguments = function(args) {
|
normalizeArguments = function(args) {
|
||||||
var _i, _j, _len, _len2, _ref, arg, l, match, result;
|
var _i, _j, _k, _l, _len, _len2, _ref, arg, l, match, result;
|
||||||
args = args.slice(0);
|
args = args.slice(0);
|
||||||
result = [];
|
result = [];
|
||||||
for (_i = 0, _len = args.length; _i < _len; _i++) {
|
for (_i = 0, _len = args.length; _i < _len; _i++) {
|
||||||
arg = args[_i];
|
arg = args[_i];
|
||||||
if (match = arg.match(MULTI_FLAG)) {
|
if (match = arg.match(MULTI_FLAG)) {
|
||||||
for (_j = 0, _len2 = (_ref = match[1].split('')).length; _j < _len2; _j++) {
|
for (_k = 0, _len2 = (_ref = match[1].split('')).length; _k < _len2; _k++) {
|
||||||
l = _ref[_j];
|
l = _ref[_k];
|
||||||
result.push('-' + l);
|
result.push('-' + l);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
(function() {
|
(function() {
|
||||||
var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, INVERSES, LINEBREAKS, SINGLE_CLOSERS, SINGLE_LINERS, _i, _len, _ref, include, left, rite;
|
var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, INVERSES, LINEBREAKS, SINGLE_CLOSERS, SINGLE_LINERS, _i, _j, _len, _ref, include, left, rite;
|
||||||
include = require('./helpers').include;
|
include = require('./helpers').include;
|
||||||
exports.Rewriter = (function() {
|
exports.Rewriter = (function() {
|
||||||
function Rewriter() {
|
function Rewriter() {
|
||||||
@@ -83,7 +83,7 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
exports.Rewriter.prototype.removeLeadingNewlines = function() {
|
exports.Rewriter.prototype.removeLeadingNewlines = function() {
|
||||||
var _len, _ref, i, tag;
|
var _i, _len, _ref, i, tag;
|
||||||
for (i = 0, _len = (_ref = this.tokens).length; i < _len; i++) {
|
for (i = 0, _len = (_ref = this.tokens).length; i < _len; i++) {
|
||||||
tag = _ref[i][0];
|
tag = _ref[i][0];
|
||||||
if (tag !== 'TERMINATOR') {
|
if (tag !== 'TERMINATOR') {
|
||||||
@@ -275,11 +275,11 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
exports.Rewriter.prototype.ensureBalance = function(pairs) {
|
exports.Rewriter.prototype.ensureBalance = function(pairs) {
|
||||||
var _result, key, levels, open, openLine, unclosed, value;
|
var _i, _result, key, levels, open, openLine, unclosed, value;
|
||||||
levels = {};
|
levels = {};
|
||||||
openLine = {};
|
openLine = {};
|
||||||
this.scanTokens(function(token, i) {
|
this.scanTokens(function(token, i) {
|
||||||
var _i, _len, _ref, _ref2, close, open, tag;
|
var _i, _j, _len, _ref, _ref2, close, open, tag;
|
||||||
tag = token[0];
|
tag = token[0];
|
||||||
for (_i = 0, _len = (_ref = pairs).length; _i < _len; _i++) {
|
for (_i = 0, _len = (_ref = pairs).length; _i < _len; _i++) {
|
||||||
_ref2 = _ref[_i], open = _ref2[0], close = _ref2[1];
|
_ref2 = _ref[_i], open = _ref2[0], close = _ref2[1];
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
return this.garbage.push([]);
|
return this.garbage.push([]);
|
||||||
};
|
};
|
||||||
Scope.prototype.endLevel = function() {
|
Scope.prototype.endLevel = function() {
|
||||||
var _i, _len, _ref2, _result, name, vars;
|
var _i, _j, _len, _ref2, _result, name, vars;
|
||||||
vars = this.variables;
|
vars = this.variables;
|
||||||
_result = [];
|
_result = [];
|
||||||
for (_i = 0, _len = (_ref2 = this.garbage.pop()).length; _i < _len; _i++) {
|
for (_i = 0, _len = (_ref2 = this.garbage.pop()).length; _i < _len; _i++) {
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
Scope.prototype.any = function(fn) {
|
Scope.prototype.any = function(fn) {
|
||||||
var _ref2, k, v;
|
var _i, _ref2, k, v;
|
||||||
for (v in _ref2 = this.variables) {
|
for (v in _ref2 = this.variables) {
|
||||||
if (!__hasProp.call(_ref2, v)) continue;
|
if (!__hasProp.call(_ref2, v)) continue;
|
||||||
k = _ref2[v];
|
k = _ref2[v];
|
||||||
@@ -98,7 +98,7 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
Scope.prototype.declaredVariables = function() {
|
Scope.prototype.declaredVariables = function() {
|
||||||
var _ref2, _result, key, val;
|
var _i, _ref2, _result, key, val;
|
||||||
return (function() {
|
return (function() {
|
||||||
_result = [];
|
_result = [];
|
||||||
for (key in _ref2 = this.variables) {
|
for (key in _ref2 = this.variables) {
|
||||||
@@ -112,7 +112,7 @@
|
|||||||
}).call(this).sort();
|
}).call(this).sort();
|
||||||
};
|
};
|
||||||
Scope.prototype.assignedVariables = function() {
|
Scope.prototype.assignedVariables = function() {
|
||||||
var _ref2, _result, key, val;
|
var _i, _ref2, _result, key, val;
|
||||||
_result = [];
|
_result = [];
|
||||||
for (key in _ref2 = this.variables) {
|
for (key in _ref2 = this.variables) {
|
||||||
if (!__hasProp.call(_ref2, key)) continue;
|
if (!__hasProp.call(_ref2, key)) continue;
|
||||||
|
|||||||
@@ -52,7 +52,8 @@ exports.Base = class Base
|
|||||||
# object with their parent closure, to preserve the expected lexical scope.
|
# object with their parent closure, to preserve the expected lexical scope.
|
||||||
compileClosure: (o) ->
|
compileClosure: (o) ->
|
||||||
o.sharedScope = o.scope
|
o.sharedScope = o.scope
|
||||||
Closure.wrap(this, no, yes).compile o
|
throw new Error 'cannot include a pure statement in an expression.' if @containsPureStatement()
|
||||||
|
Closure.wrap(this).compile o
|
||||||
|
|
||||||
# If the code generation wishes to use the result of a complex expression
|
# If the code generation wishes to use the result of a complex expression
|
||||||
# in multiple places, ensure that the expression is only ever evaluated once,
|
# in multiple places, ensure that the expression is only ever evaluated once,
|
||||||
@@ -1424,6 +1425,7 @@ exports.For = class For extends Base
|
|||||||
rvar = scope.freeVariable 'result' unless topLevel
|
rvar = scope.freeVariable 'result' unless topLevel
|
||||||
ivar = if range then name else index
|
ivar = if range then name else index
|
||||||
ivar = scope.freeVariable 'i' if not ivar or codeInBody
|
ivar = scope.freeVariable 'i' if not ivar or codeInBody
|
||||||
|
nvar = scope.freeVariable 'i' if name and not range
|
||||||
varPart = ''
|
varPart = ''
|
||||||
guardPart = ''
|
guardPart = ''
|
||||||
body = Expressions.wrap([@body])
|
body = Expressions.wrap([@body])
|
||||||
@@ -1454,7 +1456,11 @@ exports.For = class For extends Base
|
|||||||
body.unshift new Literal "var #{name} = #{ivar}" if range
|
body.unshift new Literal "var #{name} = #{ivar}" if range
|
||||||
body.unshift new Literal "var #{namePart}" if namePart
|
body.unshift new Literal "var #{namePart}" if namePart
|
||||||
body.unshift new Literal "var #{index} = #{ivar}" if index
|
body.unshift new Literal "var #{index} = #{ivar}" if index
|
||||||
|
body.push new Assign new Literal(ivar), new Literal index if index
|
||||||
|
body.push new Assign new Literal(nvar), new Literal name if nvar
|
||||||
body = Closure.wrap(body, true)
|
body = Closure.wrap(body, true)
|
||||||
|
body.push new Assign new Literal(index), new Literal ivar if index
|
||||||
|
body.push new Assign new Literal(name), new Literal nvar or ivar if name
|
||||||
else
|
else
|
||||||
varPart = "#{idt1}#{namePart};\n" if namePart
|
varPart = "#{idt1}#{namePart};\n" if namePart
|
||||||
if @object
|
if @object
|
||||||
@@ -1618,10 +1624,7 @@ Closure =
|
|||||||
# Wrap the expressions body, unless it contains a pure statement,
|
# Wrap the expressions body, unless it contains a pure statement,
|
||||||
# in which case, no dice. If the body mentions `this` or `arguments`,
|
# in which case, no dice. If the body mentions `this` or `arguments`,
|
||||||
# then make sure that the closure wrapper preserves the original values.
|
# then make sure that the closure wrapper preserves the original values.
|
||||||
wrap: (expressions, statement, force) ->
|
wrap: (expressions, statement) ->
|
||||||
if expressions.containsPureStatement()
|
|
||||||
return expressions unless force
|
|
||||||
throw new Error 'cannot include a pure statement in an expression.'
|
|
||||||
return expressions if expressions.containsPureStatement()
|
return expressions if expressions.containsPureStatement()
|
||||||
func = new Parens new Code [], Expressions.wrap [expressions]
|
func = new Parens new Code [], Expressions.wrap [expressions]
|
||||||
args = []
|
args = []
|
||||||
|
|||||||
Reference in New Issue
Block a user